SX48 Timers
I was reviewing the thread 'Reading the SX48 Timers" from Feb 2006 (http://forums.parallax.com/showthread.php?p=570291). I was curious about the concept of triggering one timer with the output of the other timer. In the thread, it says I could pulse the second timer during the interrupt handler of the first timer.
I was wondering if I could have the timers do this pulsing themselves by connecting one's Compare Output to the other's External Event Clock Source. What I was unsure about was what actually happens to the Compare Output. The documentation says it "toggles" the Compare Output. Is this a low-high-low transition?
Thanks,
Joe
I was wondering if I could have the timers do this pulsing themselves by connecting one's Compare Output to the other's External Event Clock Source. What I was unsure about was what actually happens to the Compare Output. The documentation says it "toggles" the Compare Output. Is this a low-high-low transition?
Thanks,
Joe
Comments
What I was referring to in that post was just using an regular output pin to trigger the counter.
What are you wanting to do ?
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
"You're braver than you believe, stronger than you seem, and smarter than you think" Christopher Robin to Pooh
·
I was thinking that I could set up both timers in Capture/Compare. I want to connect Timer 1's Compare Output to Timer 2's External Event Clock Source. Both of these are output pins (RB.6 and RC.3, respectively). When Timer 1 reaches my compare value, it should "toggle" RB.6, and Timer 2 should see that as a transition and increment its count. In this manner, I wouldn't have to have a counter in RAM that I maintain - I could set a compare value on Timer 2 and receive the interrupt when there is a match (but I digress).
I wasn't sure if the transition on RB.6 is low to high, or low to high to low again. I wasn't sure what the documentation meant by "toggle".
Joe
1 Aug 2006
Some corrections:
RC.3 would have to be an input and Timer 2 would have to be set up in External Event Mode.
Post Edited (JDOhio) : 8/1/2006 9:47:27 AM GMT
I set Timer 1 up in Capture/Compare mode. The Compare register is set to $ffff. When Timer 1 reaches $ffff, it toggles RB.6 (i.e., low-high-low). This pulse should happen approximately every 1.3 ms (20nS/pulse * 65536 pulses = 1.3 ms).
I set Timer 2 up in External Event Mode. In this mode, Timer 2 counts pulses on RC.3. I physically connect RB.6 (from Timer 1) to RC.3 (the external input for Timer 2) and Timer 2 counts the number of times Timer 1 reaches $ffff. I set Timer 2's Compare register to $0bf0 (2288 decimal) and set up for an interrupt when the Compare register and Timer 2 match. The interrupt should occur approximately every three seconds (2288 * 1.3 ms=2.99 s).
After the SX48 is programmed, there is a two minute time period in which nothing happens. I set a break point as indicated in the code and there is no interrupt. After two minutes, the interrupt begins to occur regularly but not at the designed time of three seconds. It happens about every six seconds.
1. Why might there be a two minute delay before the code begins to operate as expected?
2. Why does the interrupt occur every six seconds rather than every three seconds?
Thanks,
Joe
I'm away for the weekend. I'll try your code when I get back.
I would just use Timer1 in PWM mode, and you'll need to clear Timer2 (I think that is why the long initial delay). You can use the new TIMER commands too.
OUTPUT RB.6
TIMER1 PWM, 32768, 65535
T2CNTA = %00000100 ' Enable compare interrupts for Timer2
TIMER2 EXTERNAL
TIMER2 R1, $08F0
TIMER2 CLEAR
And all your should have to do in the interrupt is maybe "TIMER2 CLEAR". You don't need to reset R1.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
"You're braver than you believe, stronger than you seem, and smarter than you think" Christopher Robin to Pooh
·
· Here is a program that does what you were trying...
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
"You're braver than you believe, stronger than you seem, and smarter than you think" Christopher Robin to Pooh
·
Resetting R1 is my misunderstanding. The documentation gave me the impression that when writing ANY of the timer registers, the timer is cleared. I tried this code and performs as you say. Wicked cool.
How might I have cleared a timer in SX/B using SX-Key v3.10?
Joe
There were "CLEART1" and "CLEART2" commands. These have been superceeded (sp?) by the "TIMER1 CLEAR" and "TIMER2 CLEAR" commands.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
"You're braver than you believe, stronger than you seem, and smarter than you think" Christopher Robin to Pooh
·