Hardware Reference
In-Depth Information
to explore this code a bit more, replace the r-2r ladder with an array of ten leDs, hook up a potentiometer
to analog 0, and then set manipVar equal to analogRead(0) and lower the delay to 100 ms. power up and watch the
conversion from the potentiometer to binary.
Note
Digital Sensors
When working with sensors, it often feels like there are as many different ways to digitally work with them as there are
sensor types. This section covers a common cross-section of communication styles. To simulate these sensors, it is
important to match the specifications of the various protocols. Data can be sent or received, sent in any order, sent to
multiple devices, or requested at any time, making some of these devices very difficult to implement. Both the devices
and the Atmel data sheets are valuable resources for determining the best method needed to simulate a sensor.
PWM
PWM sensors are not as common as other types, but still deserve an honorable mention. PWM is commonly used
to control servos; in a sense, PWM sensors replace the R/C receiver, which is arguably a type of sensor. Although the
microcontrollers used in Arduino lack some elements to precisely match the specifications of a majority of the sensors
that use PWM as a data mechanism, they are capable of reading them. The pulseIn() function can read the output
PWM signal of another pin with enough consistency that a data correlation can be formed. The code that can be used
to simulate a sensor of this type is similar to the code in Listing 6-2; couple that with a lack of sensors that implement
PWM within the timing tolerances of the Arduino, and there is no need for an example in this section. The use of this
style of passing digital information can be useful in the creation of other sensor packages.
Gray Code
Gray code is a digital method that uses two or more pins to produce a square wave that is out of phase from one sensor
output pin to another. The method of phasing multiple signals allows the direction and position changes to be read
at any time. The way in which the square waves are out of phase determines whether the bit shift is left or right. Gray
code is also known as reflected binary , and is commonly used to make sensors that convert either linear or angular
movement into countable pulses to determine position, direction, and speed. This is how scroll wheels on computer
mice work. Gray code is also commonly used in robotics for rotary encoders. If one output is read as a reference
signal on either a falling or rising logic, then the other outputs read at that time will denote the direction. If the second
output is LOW before the first pin is read, it is moving one direction, and if HIGH , it is going the other direction.
The minimum amount of pins needed for this sensor is two for data and one for ground/voltage supply. The
more logic pins a sensor has, the more accurate it can be, by providing the ability to error-check for missing pulses.
Figure 6-4 shows the pulses of a dual-output encoder with one output read as rising and falling; the state of the second
output depends on the shift direction of the first output at read time.
 
 
Search WWH ::




Custom Search