How do I get out of the WaituntilHigh macro?

For general Flowcode discussion that does not belong in the other sections.
mnfisher
Valued Contributor
Posts: 1628
http://meble-kuchenne.info.pl
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 142 times
Been thanked: 761 times

Re: How do I get out of the WaituntilHigh macro?

Post by mnfisher »

If it's a digital signal (with a short length) then shouldn't use the switch component (debounce isn't needed and it is probably too slow) - timing PWM pulses might be pushing it !

Use an input of a digital port (set the port as a property (say inp) then read = inp in a calculation block) Will need to shift >> 2.

Using the timer is also slightly more problematic as it uses floating point maths for GetTime - perhaps try with GetRaw instead of Getmilliseconds

Would have to experiment with PWM (using the timer component might cause a clash too)

Martin

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

Re: How do I get out of the WaituntilHigh macro?

Post by ChrisT66 »

Ok Martin, thank you!

Then I'm back to the original solution with the four Pulsin macros that you helped me with. Or do you think it's better to do this directly with an input instead of the button query?

mnfisher
Valued Contributor
Posts: 1628
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 142 times
Been thanked: 761 times

Re: How do I get out of the WaituntilHigh macro?

Post by mnfisher »

I'd try using an input rather than a button - the button component is going to be too slow to time 1-2ms pulses.
It's probably going to be tight on timing anyway - I would try using something similar to the GetTime macro in the last example - but read port c directly (inp = port) and rather than using a timer component count the number of loops required for the pin(s) to change.
I'd (wrongly) got the impression that the pins would be high at the start of the program and needed to timed until off - so you'll also need a way to wait for a pin (or pins) to go high or a timeout - which complicates things as well..

Something like

Loop
Inp = portc
Until inp or timeout

But unless all 4 pins go high at the same time then yes, would have to measure each pin separately - although you can do this with one macro and a bit mask.

Martin

mnfisher
Valued Contributor
Posts: 1628
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 142 times
Been thanked: 761 times

Re: How do I get out of the WaituntilHigh macro?

Post by mnfisher »

I did a very small test program - to time a 'pulse' on a pin.

Here I just count 'loops' - but the results seem very consistent - for example a 4.1ms pulse gives a result of 8288 to 8290 (loops) reliably. I didn't test with a 2ms pulse but would expect ~4000 counts (I did test various lengths though - and results seem sensible - setting the length of the pulse on the smartscope seems a little hit or miss - and I checked the timing using the scope!)

I've used a Arduino Uno and output results to UART - but this should work on a Mega2560 (though you might need some work to get the output)

It waits for a 'low' on a pin then for a high (or times out) if it received a 'high' then it counts loops until pin goes low again. The port to use is in properties ('port') - I used port D (and pin 3)

I used a square wave generator on my oscilloscope to generate pulses (5v with a common ground)

Sorry about the ' in the file name :-(

Martin
Attachments
TimeTest`1.fcfx
(14.72 KiB) Downloaded 121 times

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

Re: How do I get out of the WaituntilHigh macro?

Post by ChrisT66 »

Thank you for your efforts to help! Great as always.

I'll test it with my signals, it'll take a while...

mnfisher
Valued Contributor
Posts: 1628
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 142 times
Been thanked: 761 times

Re: How do I get out of the WaituntilHigh macro?

Post by mnfisher »

I tested with a proper function generator (GW Instek) - so about as accurate as I can generate at home...
500us pulse gives 998
1ms ------------ 2010
2ms ------------- 3988
3ms ------------- 6003
4ms ------------- 8018
5ms ------------- 10093

I also tested 50us -> 96, 25us -> 46

So - it's not quite linear, but not far off. Count will of course depend on the clock speed (so in my case 16MHz). One issue is that very short pulses - all give a count of 1...

Martin

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

Re: How do I get out of the WaituntilHigh macro?

Post by ChrisT66 »

Works very well. I have tested it with the 328P and 8MHz. A 1.5ms signal gives 1498, great.)
I will now try to read in all four signals one after the other.

Thanks again!

Post Reply