Up - Down Counter
pogertt
Posts: 33
Is there a counter mode that will:
Count up on a low to high transition of A, When B is high,
Count down on a low to high transition of A, When B is low?
Count up on a low to high transition of A, When B is high,
Count down on a low to high transition of A, When B is low?
Comments
The counter modes all count up only. Read the application note on the counters (AN001) for details. It's on the Propeller downloads webpage.
If you have a spare cog, it's easy to write a short routine either in Spin or assembly (depending on the timing needed) to do what you want.
You could use two counters and an external quad NAND gate to provide A & B and A & !B, then use the NEGEDGE mode so that one counter counts low to high transitions when B is high and the other counts low to high transitions when B is low and you subtract the 2nd count from the 1st count to get your result.
Note that B can only change when A is low or you'll get false counts.
I am watching a quadrature encoder. There are several objects that I have found and are usable, the fastest determines if movment has ocured in 48 clock pulses. While 48 / 80 000 000 (1,666,666.666 samples a second) is way faster than required, the can I figure a way to do it faster bug has bitten me.
I think you have 3 too many 6's. 1.6 million times per second is very different than 1.6 billion. I definitely think you can do it in less than 48 cycles. I just put together a mock program that should be able to count cycles and add or subtract based on a pin in 26 cycles (~3.1MHz).
This is untested...but maybe code this this?
I'm guessing you'd need a DJNZ to every certain number of cycles you can WRLONG the value to a usable location. Or you add a WRLONG in the loop (make the whole think considerably lower resolution, but then instant updating). I guess that would make the whole thing 48 cycles (worst case). That might be where that is coming from.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
April, 2008: when I discovered the answers to all my micro-computational-botherations!
Some of my objects:
MCP3X08/4 ADC Driver - Programmable Schmitt inputs, frequency reading, and more!
Simple Propeller-based Database - Making life easier and more readable for all your EEPROM storage needs.
String Manipulation Library - Don't make strings the bane of the Propeller, bend them to your will!
I will have time over the weekend to set up my demo board and try this.