Implementing a non blocking delay
-
mvictor
- Posts: 24
- http://meble-kuchenne.info.pl
- Joined: Thu Aug 25, 2022 7:46 am
- Has thanked: 3 times
- Been thanked: 1 time
Re: Implementing a non blocking delay
I have v9. Lemme try that out tomorrow and I shall get back to you. Thanks for this help for now.
-
chipfryer27
- Valued Contributor
- Posts: 1861
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 407 times
- Been thanked: 632 times
Re: Implementing a non blocking delay
Hi
I should have a bit more time tomorrow so could possibly assist further. Is your trigger a one-shot or can it go high numerous times during the time-frame?
Could you perhaps use PortB for trigger and Port A for delayed output? I ask as PortB has IOC which would make things a lot easier.
Regards
I should have a bit more time tomorrow so could possibly assist further. Is your trigger a one-shot or can it go high numerous times during the time-frame?
Could you perhaps use PortB for trigger and Port A for delayed output? I ask as PortB has IOC which would make things a lot easier.
Regards
Re: Implementing a non blocking delay
As it detects signal from my PLC, the trigger will go high. It will go high only when there is a signal from my input end (the PLC). So it is a one shot.
To use port B as trigger would be a little challenging as my pcb tracks are designed as Port A for inputs and port B is output.
To use port B as trigger would be a little challenging as my pcb tracks are designed as Port A for inputs and port B is output.
-
chipfryer27
- Valued Contributor
- Posts: 1861
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 407 times
- Been thanked: 632 times
Re: Implementing a non blocking delay
Hi
OK, it was just a thought but as you have one-shot then implementing a timed period based on your trigger is quite straight forward.
Regards
OK, it was just a thought but as you have one-shot then implementing a timed period based on your trigger is quite straight forward.
Regards
Re: Implementing a non blocking delay
Hello again,
I have attempted putting a timer interrupt in my main to increment count1. But in my case it is not calling my required macro. Perhaps I might be missing something out. Uploading my program to get further assistance.
I have attempted putting a timer interrupt in my main to increment count1. But in my case it is not calling my required macro. Perhaps I might be missing something out. Uploading my program to get further assistance.
-
chipfryer27
- Valued Contributor
- Posts: 1861
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 407 times
- Been thanked: 632 times
Re: Implementing a non blocking delay
Hi
You only need to initialse the Timer Interrupt once, before the Main loop. No need to keep initialising/disabling it.
I'll reply more later (assuming nobody else jumps in) as I'm pushed for time just now.
Regards
You only need to initialse the Timer Interrupt once, before the Main loop. No need to keep initialising/disabling it.
I'll reply more later (assuming nobody else jumps in) as I'm pushed for time just now.
Regards
-
mnfisher
- Valued Contributor
- Posts: 1812
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 152 times
- Been thanked: 853 times
Re: Implementing a non blocking delay
I've done a simple example - with a single LED and button to activate the timer - this will allow you to run in simulation (in v9) and hopefully follow the logic.
When the button is pressed - a countdown for the LED is set (I've used arbitary values) - and the ISR counts down - and either lights the LED - and sets a timer until off or turns the LED off.
As set here - the button is ignored until the LED is off.
Depending on the ISR timing (which will depend on clock etc) - I've allowed up to 65535 pulses before lighting and turning off - and you can adjust the counts to suit.
To extend to 3 LEDs - add extra LED / Button pairs - and duplicate the code with new time and state variables...
Martin
When the button is pressed - a countdown for the LED is set (I've used arbitary values) - and the ISR counts down - and either lights the LED - and sets a timer until off or turns the LED off.
As set here - the button is ignored until the LED is off.
Depending on the ISR timing (which will depend on clock etc) - I've allowed up to 65535 pulses before lighting and turning off - and you can adjust the counts to suit.
To extend to 3 LEDs - add extra LED / Button pairs - and duplicate the code with new time and state variables...
Martin
- Attachments
-
- non_blocking.fcfx
- (14.8 KiB) Downloaded 36 times
-
mnfisher
- Valued Contributor
- Posts: 1812
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 152 times
- Been thanked: 853 times
Re: Implementing a non blocking delay
As an aside - I've done a little work in the ISR - and in general ISRs should be as short and fast as possible. I've set it to as slow as possible interrupt rate (1:256) (I used timer 0) - but if it runs at 75Hz (maybe using a different timer?) - then the small amount of code here would be fine.
Also - as I used v11 - Flowcode will complain that it was created using a newer version - click YES.
A very good feature of FC - create a property and set to 'single digital pin' - then you can assign input / output pins in properties.
In a calculation you can do pin = 1 (output) or (.input = pin) - which is neater than using input output blocks (especially if you ever want to change pins!)
Martin
Also - as I used v11 - Flowcode will complain that it was created using a newer version - click YES.
A very good feature of FC - create a property and set to 'single digital pin' - then you can assign input / output pins in properties.
In a calculation you can do pin = 1 (output) or (.input = pin) - which is neater than using input output blocks (especially if you ever want to change pins!)
Martin
Re: Implementing a non blocking delay
I downloaded the program, but it is throwing two error of missing component which is LEDMono1::Setstate and Switchpushbutton. Are these components unavailable in V9 ?
-
mnfisher
- Valued Contributor
- Posts: 1812
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 152 times
- Been thanked: 853 times
Re: Implementing a non blocking delay
Possibly - sorry, i don't have v9 on my pc at the moment..
You could swap to another led component and a momentary push button - or just use input and output - and then view->digital pins.
You could swap to another led component and a momentary push button - or just use input and output - and then view->digital pins.