In SX Microcontrollers, SX/B Compiler and SX-Key Tool, bean wrote: I while back Ken posted about counting magneto pulses and driving a servo. I had said at that time that the SX48 hardware timers could easily do both. Well, I spoke too soon... One little quirk of the SX48 counters is that you cannot read the counter. What the ... No, I'm serious. If the counter is used in timer mode, there is little need to read the counter value, it just does something when it reaches R1 or R2. In capture mode, we can read the timer in a round-about way. When you trigger the capture pin, the current count is copied into the capture register. But the capture pin doesn't do anything in "external counter" mode. So, being a crafty little programmer I thought. Well I'll just count, then switch to capture mode, toggle the capture pin, and volia I will have the count. And that works with one little problem. The counter is incrementing from the instant you put it into counter mode. So you end up with some extra counts until the code toggles the capture pin. Well, it's better than nothing... Then I was playing with the external counter mode and discovered something interesting. The prescaler does not affect the external counter mode. Hmmm, what if I set the prescaler to 1:128, then when I put the counter in capture mode, 128 cycles could go by without the counter getting incremented. So, I tried it...And it works like a charm. I have attached the program I was using to test it out. Simply connect the pulses to the RC.3 pin, and make sure nothing is connected to RC.0 (the capture pin). Comment welcome. Bean. ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=148780 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)