Hello,
Flowcode version v4, PIC16F88.
I am trying to implement a non blocking delay to power ports B5, B6 and B7 with the required delay in seconds on receiving a hi signal from input ports A4, A0 and A1. I was able to use TMR0 interrupt to create a delay for the first B5 output but whilst using TMR1 as interrupt for B6 output it is just not calling my macro.
The thing behind this is that the port B outputs must turn hi after respective seconds on receiving respective hi inputs from port A. Non blocking delay is needed because i need the program to run continously to record the inputs. Attaching my macros, the Main is only calling my REJECT macro in a while loop.
Could use some help please?
Implementing a non blocking delay
-
mvictor
- Posts: 27
- http://meble-kuchenne.info.pl
- Joined: Thu Aug 25, 2022 7:46 am
- Has thanked: 3 times
- Been thanked: 1 time
-
mnfisher
- Valued Contributor
- Posts: 1812
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 152 times
- Been thanked: 855 times
Re: Implementing a non blocking delay
Flowcode v4 is now no longer supported - can I suggest you try v11 - you will find a lot has changed for the better...
If you need a non blocking delay you will need to get rid of the delays in your code... A timer interrupt could handle things (and must not contain delays)
Martin
If you need a non blocking delay you will need to get rid of the delays in your code... A timer interrupt could handle things (and must not contain delays)
Martin
Re: Implementing a non blocking delay
I did try using timer interrupt. I am able to work TMR0 and it calls my macro TIMERSERVICE, but in case of TMR1 it does not call my macro TIMERSERVICE2 which is linked to TMR1.
-
mnfisher
- Valued Contributor
- Posts: 1812
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 152 times
- Been thanked: 855 times
Re: Implementing a non blocking delay
It might be missing the interrupt - you have a 300ms delay in the first macro shown (which i assume is the ISR) - this would likely cause your program to fail.
It is very hard to tell from screen shots (no macro names etc) - so please upload your code - however, as version 4 is now no longer supported I would suggest upgrading to v11 (it is free for personal use) then it will be easier to help...
Martin
It is very hard to tell from screen shots (no macro names etc) - so please upload your code - however, as version 4 is now no longer supported I would suggest upgrading to v11 (it is free for personal use) then it will be easier to help...
Martin
-
chipfryer27
- Valued Contributor
- Posts: 1864
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 407 times
- Been thanked: 632 times
Re: Implementing a non blocking delay
Hi
Have to strongly agree with Martin above that you should seriously consider v11 as it is "free" for hobbyist use. Few on this forum will even remember or have v4. I still have a copy on a machine somewhere, but where....?
V11 won't open your program. It would need to be converted into something modern versions can use by using v7. I definitely have v7 so could try for you.
Without seeing your program it is difficult to assist, but could you perhaps just have one timer? Enable it once and leave it running. In the ISR Macro it increments one (or two counters) every second.
In your main loop when you want to start a time period, reset the appropriate counter then in your main loop test for it's desired value. You can either leave it running to proviode second value or start / test a seperate counter. Keep your ISRs as short as possible and avoid delays in them. Have your Main loop do any tests etc.
Regards
Have to strongly agree with Martin above that you should seriously consider v11 as it is "free" for hobbyist use. Few on this forum will even remember or have v4. I still have a copy on a machine somewhere, but where....?
V11 won't open your program. It would need to be converted into something modern versions can use by using v7. I definitely have v7 so could try for you.
Without seeing your program it is difficult to assist, but could you perhaps just have one timer? Enable it once and leave it running. In the ISR Macro it increments one (or two counters) every second.
In your main loop when you want to start a time period, reset the appropriate counter then in your main loop test for it's desired value. You can either leave it running to proviode second value or start / test a seperate counter. Keep your ISRs as short as possible and avoid delays in them. Have your Main loop do any tests etc.
Regards
Re: Implementing a non blocking delay
Sorry for the late reply, was occupied elsewhere.
So what I am trying to do with the program is:
A4, A0 and A1 are three inputs which is a high trigger signal. On receiving the signal at the appropriate ports I am trying to activate the respective port B5, B6 and B7 after a certain second delay, like say when a high is given to A4 then B5 will activate after 2s and when a high is given to A0 then B6 would get activated after 3s. But in this case, I need the delays to be non blocking since the microcontroller needs to be active to receive the input signals.
I have posted my program, any help or guidance would be highly appreciated. And yes, although not done here, I am trying to remove the delay component in the ISR but I need to know how to implement this non blocking delay?
So what I am trying to do with the program is:
A4, A0 and A1 are three inputs which is a high trigger signal. On receiving the signal at the appropriate ports I am trying to activate the respective port B5, B6 and B7 after a certain second delay, like say when a high is given to A4 then B5 will activate after 2s and when a high is given to A0 then B6 would get activated after 3s. But in this case, I need the delays to be non blocking since the microcontroller needs to be active to receive the input signals.
I have posted my program, any help or guidance would be highly appreciated. And yes, although not done here, I am trying to remove the delay component in the ISR but I need to know how to implement this non blocking delay?
-
Steve-Matrix
- Matrix Staff
- Posts: 1722
- Joined: Sat Dec 05, 2020 10:32 am
- Has thanked: 247 times
- Been thanked: 407 times
Re: Implementing a non blocking delay
One way to solve this is to have a timer interrupt constantly running which simply increments a global "tick" integer variable. In your main macro, have something like:
Remember to use the logical-AND operator (&&) instead of "AND" or "&" in your actual code.
Hopefully this will give you a start.
Code: Select all
//initialise some vars
Set tick to zero
Set check1 to false
Set delay1 to an appropriate value
...etc...
Enable Timer Interrupt
Loop Forever
//read the inputs
IF input1 becomes high, Set var1 to tick and set check1 to true
IF input2 becomes high, Set var2 to tick and set check2 to true
...etc...
//set the outputs
IF check1 is true AND tick > var1 + delay1, Set output1 high
IF check2 is true AND tick > var2 + delay2, Set output2 high
...etc...
End LoopHopefully this will give you a start.
-
mnfisher
- Valued Contributor
- Posts: 1812
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 152 times
- Been thanked: 855 times
Re: Implementing a non blocking delay
I was thinking along similar lines as Steve....
Sorry - I don't have Flowcode 4
Martin
Sorry - I don't have Flowcode 4
Code: Select all
ISR (Runs every Nms)
if L1 > 0:
L1 = L1 - 1
IF L1 = 0 - Light led 1
if L2 > 0
etc
In program:
If B1 pressed set L1 = time until L1 lit
If B2 ....
-
chipfryer27
- Valued Contributor
- Posts: 1864
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 407 times
- Been thanked: 632 times
Re: Implementing a non blocking delay
Hi
I am a bit rushed just now but have converted your v4 to a file that can be opened in v9/10/11. I don't really have time to look for a machine with v4 but strongly recommend upgrading to latest. It has far more features and is more user friendly.
Without access to v4 I can't show you any examples as you won't be able to open unless you upgrade
As both Steve and I mention, enable a single timer that increments a counter(s) before you enter your main loop and take all timings from that.
Timer2 can interrupt as low as 75Hz, so each second is a multiple of a count of 75.
When Pin1 triggers perhaps clear "counter1". In main loop test for counter1 = 150 and you know two seconds have elapsed. Pin2 triggering could do similar or just take note of current count and look for counter+x (where x is the period in seconds x 75).
Regards
Edit
Martin beat me to reply
I am a bit rushed just now but have converted your v4 to a file that can be opened in v9/10/11. I don't really have time to look for a machine with v4 but strongly recommend upgrading to latest. It has far more features and is more user friendly.
Without access to v4 I can't show you any examples as you won't be able to open unless you upgrade
As both Steve and I mention, enable a single timer that increments a counter(s) before you enter your main loop and take all timings from that.
Timer2 can interrupt as low as 75Hz, so each second is a multiple of a count of 75.
When Pin1 triggers perhaps clear "counter1". In main loop test for counter1 = 150 and you know two seconds have elapsed. Pin2 triggering could do similar or just take note of current count and look for counter+x (where x is the period in seconds x 75).
Regards
Edit
Martin beat me to reply
- Attachments
-
- Thermaltimingjan26_v11.fcfx
- (23.07 KiB) Downloaded 41 times