POSEDGE detection code.
StephenMoore
Posts: 188
I am trying to measure the number of pulses coming into pina between the toggling of pinb.
I want to continuously read out the pulse total in a separate cog. Here is the scenario:
I am passing the address of my display variable in countAddr when I call Start(countAddr, pulsePin, disablePin). However, the code fails and I can not figure out why.
Any suggestions would be welcome.
Sincerely,
sm
I want to continuously read out the pulse total in a separate cog. Here is the scenario:
''Counter used as a pulse counter CON POSEDGE = 0100000 PUB Start(countAddr, pulsePin, disablePin) pina := pulsePin pinb := disablePin cognew(@entry, countAddr) DAT org entry mov frqa, #1 'increment for each edge seen movs ctra, pina 'setup encoder pin movi ctra, ctra_ 'establish mode and start counter :loop test ina, pinb wz 'check state of stepper drive enable pin if_z jmp #:loop mov phsa, #0 'zero out pulse counter :count test ina, pinb wz wrlong phsa, par 'send the current value back if_nz jmp #:count jmp #:loop ctra_ long POSEDGE<< 26 'mode pina long 1 pinb long 1 addr res 1
I am passing the address of my display variable in countAddr when I call Start(countAddr, pulsePin, disablePin). However, the code fails and I can not figure out why.
Any suggestions would be welcome.
Sincerely,
sm
Comments
-Phil
Here is a corrected (but untested) version. For sure you need to pass some values to the Start methode to try it.
Andy
The code still doesn't update the phsa value with the pulse inputs from pina so I added some debug features.
Other than that the logic seems ok. That is pinb On/Off starts the led blinking but the posedge counter does not count the led pusles.
The wrlong works fine as I can read and display from the calling cog values I force into the phsa register.
I appreciate your help and am a little concerned why after all the effort I put into learning PASM very little of it sticks with me.
Sincerely,
sm
pina, in this case, evaluates to 512, which is not a valid pin number.
-Phil
The program is supposed to pulse pin 8 (led) which is used to provide input to pin 9 (pina), which it does. The counter is supposed to simply count the pulse leading edges and write the number out continuously, which it does not.
I hope that your Memorial Day is a good one.
The following code works on my Quickstart board. It has a testcode which calls the Start methode and generates some test patterns at the pins:
Andy
That's it. I can not express to you how many times I have gone over this code and failed to make it work right. This business of shadow registers is covered only vaguely in the manual.
I thank you sir for your help. And thanks to Mr. Pilgrim for looking at too.
I wish there were a way to payback but I always seem to be on the receiving end.
Regards,
sm