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?
Logic help - Ignoring short pulses
-
- Flowcode V4 User
- Posts: 288
- Joined: Wed Nov 02, 2011 11:15 pm
- Has thanked: 29 times
- Been thanked: 30 times
- Contact:
-
- Valued Contributor
- Posts: 1188
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 439 times
- Contact:
Re: Logic help - Ignoring short pulses
How about something like:
(in pseudocode)
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:
Give us some more details on what you are trying to achieve
Martin
(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
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
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Logic help - Ignoring short pulses
Have you thought about using the built in Timer
Maybe ideal for your application?
Maybe ideal for your application?
Martin
-
- Flowcode V4 User
- Posts: 288
- Joined: Wed Nov 02, 2011 11:15 pm
- Has thanked: 29 times
- Been thanked: 30 times
- Contact:
Re: Logic help - Ignoring short pulses
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
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
- Attachments
-
- Pulse Filter.fcfx
- (9.16 KiB) Downloaded 183 times
-
- Flowcode V4 User
- Posts: 288
- Joined: Wed Nov 02, 2011 11:15 pm
- Has thanked: 29 times
- Been thanked: 30 times
- Contact:
Re: Logic help - Ignoring short pulses
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
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
-
- Flowcode V4 User
- Posts: 288
- Joined: Wed Nov 02, 2011 11:15 pm
- Has thanked: 29 times
- Been thanked: 30 times
- Contact:
Re: Logic help - Ignoring short pulses
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
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