How immediately zero the PCNT using GPIO?

clarkster
Posts: 47
Joined: Sat Sep 23, 2017 12:36 pm

How immediately zero the PCNT using GPIO?

Postby clarkster » Mon Jan 22, 2018 7:08 pm

I have a application where I want to zero a PCNT when a GPIO goes low. It's a home flag on an absolute stepper. I was expecting that the control input to the PCNT could be used to reset the counter, but that does not seem to be the case. Have I missed anything?

As far as I can see, the only method to reset the counter from an external input is to create an ISR for the GPIO input and in that routine put the software commands to reset the PCNT. This method is simple enough but I'm afraid it will be somewhat slow.

Is there any possibility of adding reset to the PCNT control inputs in the future? I suspect there are many use cases where the PCNT needs to be immediately reset based on an external input.

Clark

clarkster
Posts: 47
Joined: Sat Sep 23, 2017 12:36 pm

Re: How immediately zero the PCNT using GPIO?

Postby clarkster » Tue Jan 23, 2018 10:43 pm

For my purposes, using a GPIO interrupt to clear a counter is going to work very well. I only need to count pulses up to around 150 Hz.

I just ran a simple test using two PCNT. The output from an LED_PWM controller was sent to both counters. One counter had a high limit set of 10000 and had no interrupts set. The other counter had a high limit of 800 and that high limit generated an interrupt.
The interrupt was used to reset the first counter.

I then began adjusting the frequency of the PWM. I started with it set to 1 hz and performed several tests while I increased the frequency to 30KHz. If the interrupt was able to immediately reset the first counter, the two counters would always have the same current count. If the interrupt took more than one PWM cycle, then the counts would diverge.

The counts of the two counters remained identical beyond 20 KHz. At 30 KHz the counters differed by only 1 count.

My tests show that using an interrupt to reset a counter works well (the count is reset within one clock cycle) to at least to 20 KHz.

Who is online

Users browsing this forum: No registered users and 104 guests