Quantcast
Viewing latest article 5
Browse Latest Browse All 4818

MicroPython • Re: Accurate Edge Counter with RP2040 PIO — Pulse Counting on Demand

PS. In your pseudo-code I think there is a misunderstanding of the increment algorithm. There is no "second increment". the following operation: bitwise invert y, followed by decrementing y and finished by inverting y again, effectively increments y, in these 3 steps. The "jmp" instruction here is basically a dummy jump just to proceed, because it allows to simply decrement a scratch variable y with y_dec Image may be NSFW.
Clik here to view.
:)
There are a few other mistakes in this pseudo-code as well. In this fragment at the beginning:

Code:

Initial_Pin_State = Read state of the configured input pin (associated with 'in_base' - btn0)Interrupt_Status_Register = Initial_Pin_State
The assignments should be the other way around:

Code:

Input_Shift_Register = Read state of the configured input pin (associated with 'in_base' - btn0)Initial_Pin_State = Input_Shift_Register
because the read pin state is written to the ISR with the in_(pins,1) instruction, an donly then written to X from the ISR. (I also point out the nomenclature: ISR is input shift register, not interrupt status register)
Similarly, in the further part of the code after a successful pull-request check:

Code:

    // A pull request was made, output the counter value    Interrupt_Status_Register (temporary) = Previous_Pin_State
The assignment should be the other way around, because it is the ISR which is storing temporarily the pin state which is to be restored at that point. Maybe I don't understand the distinction you made in the pseudo-code to "Interrupt_Status_Register" and "Interrupt_Status_Register (temporary)" - the latter doesn't exist in practice, so the pseudo-code doesn't really correspond to my logic. But this is besides the point of counting both types of edges anyway, I'm being pedantic I guess Image may be NSFW.
Clik here to view.
:geek:

[/quote]


You are correct, there was an interpretation error in my peusudo code. Good job.

Statistics: Posted by Henderson Hood — Mon Apr 07, 2025 5:16 pm



Viewing latest article 5
Browse Latest Browse All 4818

Trending Articles