Click counter

For general Flowcode discussion that does not belong in the other sections.
ChrisT66
Posts: 103
http://meble-kuchenne.info.pl
Joined: Mon Dec 07, 2020 12:47 pm
Been thanked: 1 time

Re: Click counter

Post by ChrisT66 »

Ok, found a mistake. Forgot to set onetime to 1 in the switch case.

but the double flashing at the beginning remains

ChrisT66
Posts: 103
Joined: Mon Dec 07, 2020 12:47 pm
Been thanked: 1 time

Re: Click counter

Post by ChrisT66 »

By the way, OUT1 and OUT2 are also LEDs, I think I forgot to mention that.
So here is the working version
Attachments
Testclick.fcfx
(36.2 KiB) Downloaded 89 times

chipfryer27
Valued Contributor
Posts: 1607
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 357 times
Been thanked: 565 times

Re: Click counter

Post by chipfryer27 »

Hi

If you run and get no input within your count of 20,000 you enter an endless loop. You may want to try and prevent that.

Looks like you would benefit from using timers rather than just counting up based on the run time it takes to complete a loop.

Button presses etc typically are counted in milliseconds (hundreds) so your chip can easily use timers to capture pulse lengths with accuracy, eliminating "bounce". For example lets say with bounce you get some pulses coming in for anything up to 10mS before settling, with a normal button press being between 20 and 40mS in length. Same for a Switch but this time the length is 80 to 120mS. These are just example values and in reality you would need to experiment.

You could (for example) set up Interrupt On Change. Interrupt on High will start a timer, Low will stop.

When interupt occurs (say Button 1 going high) you start timer (tick = tick +1, with time interval of say 1mS)

Enable IOC on High.
When Tick = 12 you test button. If low stop timer and go back to beginning.
If still high then carry on, and enable IOC on low
When button goes Low IOC then stops timer

Tick equals the number of mS that elapsed. If up to 40 then it's a button, if above 80 then its a switch so to speak.

Obviously the times above are not realistic but it's just to give an example of one way to measure pulse duration.

Regards

ChrisT66
Posts: 103
Joined: Mon Dec 07, 2020 12:47 pm
Been thanked: 1 time

Re: Click counter

Post by ChrisT66 »

Hi,
I would like to work with an IOC. The only problem here is that I don't have a button or switch on a port pin but a permanent PWM pulse and I have to react to the change in pulse width with a button/switch click.
But thanks for the suggestion.
Regards

chipfryer27
Valued Contributor
Posts: 1607
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 357 times
Been thanked: 565 times

Re: Click counter

Post by chipfryer27 »

Hi

I think IOC is the way to go using a timer.

You are receiving a signal of varying duration or duty-cycle. When the signal goes High you start a "tick" stopping when going low. The count is then your duration. By measuring this duration you should be able to establish what is causing the change, assuming of course whatever causes the change causes a repeatable duration change.

If you expect 100% duration though then you may need to adjust the approach.

regards

Post Reply