![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
davefromnj
Joined: 03 May 2007 Posts: 42
|
Problem using Timer0 & Timer1 on PIC 16F610 |
Posted: Tue Jan 27, 2009 8:25 am |
|
|
Hello All,
A friend built a program around a PIC 16F887 / PICKIT2 demo board that worked properly.
He used Timer0 to flash an LED at 2kHz, and Timer1 to flash an LED at a slower 800Hz. Timer0 was setup with an interrupt and within the interrupt, the LED toggles states and Timer0 gets reloaded with the same value that translates into a 2kHz flashrate.
Timer1 was setup in the same way as Timer0, with an interrupt and within the interrupt the other LED gets toggled and Timer1 gets reloaded with a value that will translate into an 800kHz flashrate.
This worked great, but he only needed like 6 I/O pins for his project and the 16F887 has like 44pins.
I suggested he try it out on a PIC16F610 since it's the smallest packaged 16F PIC that advertises having a Timer0 and Timer1.
He built his project up again with the LEDs, however now Timer0 and Timer1 appear to be interacting with each other. When Timer 1 expires, it appears to turn off the LED that is normally controlled by Timer0.
he's using port C on the chip to control the LEDs, and has used the setup_comparator(NC_NC_NC_NC) function to turn off the comparators in his main routine.
What could be causing this?
There is nothing in the while loop, the toggling is only controlled in the interrupts.
When he emails me the code I'll paste it here. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Tue Jan 27, 2009 8:58 am |
|
|
The obvious 'danger', is in 'toggling' LED's. Don't. Toggle an internal bit in a variable, and output this to the LED's. The most likely problem is that the resistors in series with the LEDs, are not quite large enough.
You have to remember that with any 'toggle' operation, you are performing a RMW cycle on the port. So the voltages on the port pins are read (R), modified (toggling the bit - M), and then written back to the port (W). If a line driving an LED, doesn't have a big enough pull up resistor, it may 'read' as a low, and get written back as a low. Now haven't checked the data sheet, and you don't say which pins are involved, but (for example), if the older chip, had TTL input thresholds on the pins, and the new chip has Schotty thresholds on the pins you are now using, the voltage required to be seen as a 'high', could change from perhaps 2.4v, to 4v.
So avoid the 'toggle', and write the pins directly, from an internally held value.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
davefromnj
Joined: 03 May 2007 Posts: 42
|
|
Posted: Tue Jan 27, 2009 9:53 am |
|
|
Ttelmah wrote: | The obvious 'danger', is in 'toggling' LED's. Don't. Toggle an internal bit in a variable, and output this to the LED's. The most likely problem is that the resistors in series with the LEDs, are not quite large enough.
You have to remember that with any 'toggle' operation, you are performing a RMW cycle on the port. So the voltages on the port pins are read (R), modified (toggling the bit - M), and then written back to the port (W). If a line driving an LED, doesn't have a big enough pull up resistor, it may 'read' as a low, and get written back as a low. Now haven't checked the data sheet, and you don't say which pins are involved, but (for example), if the older chip, had TTL input thresholds on the pins, and the new chip has Schotty thresholds on the pins you are now using, the voltage required to be seen as a 'high', could change from perhaps 2.4v, to 4v.
So avoid the 'toggle', and write the pins directly, from an internally held value.
Best Wishes |
Thanks, I'll ask him what his series resistor values are.
He did use a variable to drive the outputs like this:
within the timer0 interrupt routine:
var1 = ~var1;
output_bit(PIN_C4, var1);
and
within the timer1 interrupt routine:
var2 = ~var2;
output_bit(PIN_C3, var2);
For some reason when timer 1 expires it turns off / on its LED and the one on the other pin.
One thing to note, if only one timer interrupt is used, either timer0 or timer1 the leds will flash at their appropriate rate, its only when they are both used simultaneously that the LEDs almost have what looks like jitter. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|