Page 1 of 1
Logic help - Ignoring short pulses
Posted: Mon Jan 14, 2019 5:30 pm
by Lord Grezington
Hello
I have spent far longer on this issue than I really should, it seems so simple but I cant seem to get it right and I seem to be going round in circles.
I have an IOC pin that I need to use to time the length of high and low puslses. I am increasing a variable in a timer between any changes on the IOC pin, and this works well...
But I now also need to ignore short pulses which is set with another variable, I cant add any delays so it needs to be done with increasing timer variables.
Anyone have any suggestions?
Re: Logic help - Ignoring short pulses
Posted: Mon Jan 14, 2019 10:13 pm
by mnf
How about something like:
(in pseudocode)
Code: Select all
loop for as long as needed
On PinChange // When pin changes start timer (timer method will depend on resolution needed) (This may be an interrupt handler or flag set by a interrupt....)
last_timer = current_timer // Size (byte, word or long) of last & current_timer must allow for sufficient counts
if last_timer > minimum_time -- do whatever
current_timer = 0
else
current_timer = current_timer + 1 // We're counting loops here - or use a timer interrupt to increment current_timer
This is assuming you just do something if a pulse is > minimum_time (is this s, ms, ns?) and only on the pulse finishing.
If you want to do something continuously if the pulse overruns minimum_time then:
Code: Select all
if current_timer > minimum_time then do_something
Give us some more details on what you are trying to achieve
Martin
Re: Logic help - Ignoring short pulses
Posted: Tue Jan 15, 2019 8:56 am
by medelec35
Have you thought about using the built in
Timer
Maybe ideal for your application?
Re: Logic help - Ignoring short pulses
Posted: Tue Jan 15, 2019 9:21 am
by Lord Grezington
Hello Martin & mnf
Below is a short depection of what I am looking to achieve. This is basically a signal coming of of a comparitor. I had the raw signal going through a low pass filter before entering the comparator but I was adding too much delay on the filtered signal. So I reduced the value of the cap on the filter and now I am seeing something like below which needs to be cleaned up.
I have also attached a short program with the parameters setup on how I get the pulse length.
Thanks

- Min Pulse.jpg (21.47 KiB) Viewed 4109 times
Re: Logic help - Ignoring short pulses
Posted: Tue Jan 15, 2019 1:58 pm
by Lord Grezington
Hello Everyone
I seem to be struggling with this... It does sound simple, and perhaps I am making it more complicated than it needs to be.
I have attached a program I have done this morning (I was hoping not to as I wanted you guys to look at it from a fresh perspective). It seems to work maybe 97% of the time, but now and then I get something going wrong.
Any help is appriciated...
Thanks
Re: Logic help - Ignoring short pulses
Posted: Tue Jan 15, 2019 5:24 pm
by Lord Grezington
Hello
I think I have got this done now - seems the problem I was having was some sort of debouce where the IOC pin now and then jumped through twice. Was very odd as this was not shown on the scope. This caused the IOC macro to run through twice incrementing the variable. This was resolved by saving the previous reading into variable and comparing it to the new one (if there was a change).
Thanks