Figure 3
PWM settings, which means that the PWM counts down to
the match number (OCR1A or OCR1B) and then clears the
output. When the count rolls back over to 255, it sets the
output again and starts over. The Phase Correct method
that you can choose ramps down to the match number
and clears, then when it reaches zero it does the opposite,
ramping back up. I’ve not noticed any performance
difference between these two modes.
The frequency you should use for your motors depends
entirely upon the motor quality and the ability of your
H-bridge. The motors used in automobile window drives,
toys, and such work best at 500 Hz to 1 kHz. An expensive
Escap motor will PWM very smoothly at 20 kHz. Check your
datasheets for your H-bridge, as well. A 754410 and L293D
dual H-bridge specifies their tests at 5 kHz. I’ve blown the
top off of the chip at 20 kHz, so I’d respect that number.
Q. I have a battery that is being used to power a
very high powered set of motors in my robot and it
can get very hot. This bothers me and I want to
measure the temperature of the pack while I’m running it
and shut down the motors if it overheats. How can I do this
with a TC77 temperature sensor?
— Tom Bartlett
A. A lot of people just don’t pay attention to that little
detail. Heat is a killer for all battery packs and it can
be REALLY bad if you are using lithium polymer packs.
The TC77 gives its temperature in straight Celsius or
Fahrenheit, depending upon the part. It uses an SPI-ish
synchronous serial protocol that is easy to use. If you let it
run in the default mode, you can simply read it and the
most recent value will be sent back.
This is handy because the TC77 has a single data
input/output line that is kind-of weird to use, so we’ll
simply read from it and save time and confusion. Because
this part is synchronous serial, you can bit-bang the
communication even if you have interrupts in your system
disturbing your code; it will tolerate the clock bit stretch.
Figure 4
16 SERVO 05.2008
My example for this part is using Microchip’s C18 C
compiler for a PIC18F252 microcontroller to handle this
bit banging. You can easily convert to any other compiler;
the code is very simple. I chose to only get the integer
part of the temperature and ignored the fractional value.
I suspect that this is adequate for your use.
My code waits the minimum amount of time for each
bit clock. The part is quite fast and I’m running my
PIC18F252 at the full 40 MHz.
PIC C18
unsigned char GetTemp(void)
{
unsigned char temp;
unsigned char i;
TC77_SCK = 0;
TC77_CS = 0;
temp = 0;
//Set all lines to a known state
for (i=0;i<9;i++)
{
//Yes, 9 bits, discard the first one
TC77_SCK = 0;
temp <<=1; //Get ready for the next bit
TC77_SCK = 1; //clock in on the rising edge
temp |= TC77_SIO; //Get the next bit
}
TC77_CS = 1;
//disable communications
return (temp);
//This is the integer temperature
}
The three TC77 defines are assigned to their respective
I/O pins going to the TC77 sensor. Make sure that you put
the sensor directly on the pack, preferably right in the middle.
Q. How do I scale down a voltage to read it using
an ADC pin on my microcontroller if it is too high
to read?
Rowen Cowley
A. The simple answer to the first part of your question
is to use a resistor divider to scale down the input
voltage. Most microcontrollers require that you keep
the impedance of the analog circuit under some value. With
a PIC thats value is 10K ohms; the Atmel AVR parts also
recommend 10K ohms as a maximum impedance.
Other microcontrollers may require a different maximum
impedance. Figure 3 shows the resistor network circuit that
you would use.
You will need to choose resistors that will step the
voltage down to what you need. Choose the resistor set
that will keep the maximum voltage that you will
experience in the range that your micro can handle. The
formula for determining this voltage is:
Vout = Vin(Rb/(Ra + Rb))
This answer just begs to be enhanced with a way to
scale a voltage up to get better resolution. If you have an
ADC of eight bits (maximum of 255) and you have a
voltage coming in that is only 1.2V maximum and your