Faster detection on Port A0
Moderator: Benj
- JLeith
- Posts: 537
- Joined: Wed Nov 14, 2012 7:49 pm
- Location: British Columbia Canada
- Has thanked: 146 times
- Been thanked: 26 times
Faster detection on Port A0
Hello All
I have a Halloween interface to make my Ghosts and Goblets move when a Ghost comes Trick or Treat.
I have a sensor across my walk way that triggers PortA0 to logic 1
The problem I have is I loop 500 times with a 600ms delay to get about 5min with no Trick or Treats to activate a Fog Machine and other Ghosts.
I can't always trigger my main action from Port A0 if I miss the action while waiting the 600ms delay
I have a simple drawing. And the Flowcode. All the Action is under Macro 'Relay"
I have added several PortA0 looks during the loop but I think my flaw is in the 600ms delay.
Does anyone know how I can get around this. And have the Main action happen.
I tried the Wait for PortA but I couldn't trigger the Loop relay 4 to run.
The program runs about 4 ot of 5 times. I would like to see if I can get it to do 5 out 5.
John
I have a Halloween interface to make my Ghosts and Goblets move when a Ghost comes Trick or Treat.
I have a sensor across my walk way that triggers PortA0 to logic 1
The problem I have is I loop 500 times with a 600ms delay to get about 5min with no Trick or Treats to activate a Fog Machine and other Ghosts.
I can't always trigger my main action from Port A0 if I miss the action while waiting the 600ms delay
I have a simple drawing. And the Flowcode. All the Action is under Macro 'Relay"
I have added several PortA0 looks during the loop but I think my flaw is in the 600ms delay.
Does anyone know how I can get around this. And have the Main action happen.
I tried the Wait for PortA but I couldn't trigger the Loop relay 4 to run.
The program runs about 4 ot of 5 times. I would like to see if I can get it to do 5 out 5.
John
- Attachments
-
- Relay Driver Sept 30 2018.fcfx
- (42.01 KiB) Downloaded 209 times
-
- Ghost loop.png
- (9.97 KiB) Downloaded 3671 times
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Faster detection on Port A0
Hi John,
You can make this work really well if you use interrupts.
Are you able to use port B0 (Int) as a input for the triggering?
If so as soon as INT (port B0 interrupt) is triggered i.e a change from high to low or low to high depending on preference then it can set a flag to 1 which also you can get it to reset the timer for use whenever you want.
Also I would use a timer interrupt for timing instead of a delay within a loop.
Then the delay can be set from a milliseconds to loads of hours
All this should be nice an easy to implement.
You can make this work really well if you use interrupts.
Are you able to use port B0 (Int) as a input for the triggering?
If so as soon as INT (port B0 interrupt) is triggered i.e a change from high to low or low to high depending on preference then it can set a flag to 1 which also you can get it to reset the timer for use whenever you want.
Also I would use a timer interrupt for timing instead of a delay within a loop.
Then the delay can be set from a milliseconds to loads of hours
All this should be nice an easy to implement.
Martin
- JLeith
- Posts: 537
- Joined: Wed Nov 14, 2012 7:49 pm
- Location: British Columbia Canada
- Has thanked: 146 times
- Been thanked: 26 times
Re: Faster detection on Port A0
Hello Martin
Really nice to hear from you on my newest project
Yes I can use B0 it is open
I was looking at the Interrupt just not sure where to place it in the flow.
? Not sure how the timer interrupt for timing works. Yes the long loop is hard to manage.
I will give it a go and see how I make out.
Is this a picture of design. At lease I thing this is the design ?
Really nice to hear from you on my newest project
Yes I can use B0 it is open
I was looking at the Interrupt just not sure where to place it in the flow.
? Not sure how the timer interrupt for timing works. Yes the long loop is hard to manage.
I will give it a go and see how I make out.
Is this a picture of design. At lease I thing this is the design ?
- Attachments
-
- interrupt.png
- (8.8 KiB) Downloaded 3652 times
- JLeith
- Posts: 537
- Joined: Wed Nov 14, 2012 7:49 pm
- Location: British Columbia Canada
- Has thanked: 146 times
- Been thanked: 26 times
Re: Faster detection on Port A0
Hi again Martin
Looking at the Timer Interrupt and the Port B0
Would I not be in the same pickle with the timer ? . If I say set the timer to run for 5 min then how do I trigger a "Ghost" say arrives in 3 min after the Timer Interrupt is timing 1....5 Min ?
I will wait for you help on this before I dive in a redesign. I will look into the PorrtB0 trigger.
John
Looking at the Timer Interrupt and the Port B0
Would I not be in the same pickle with the timer ? . If I say set the timer to run for 5 min then how do I trigger a "Ghost" say arrives in 3 min after the Timer Interrupt is timing 1....5 Min ?
I will wait for you help on this before I dive in a redesign. I will look into the PorrtB0 trigger.
John
- JLeith
- Posts: 537
- Joined: Wed Nov 14, 2012 7:49 pm
- Location: British Columbia Canada
- Has thanked: 146 times
- Been thanked: 26 times
Re: Faster detection on Port A0
Hi Martin
I got the PortB0 to trigger and it works every time.
The issue I see know is Flowcode works every time but the hardware locks up after the Relay2 macro runs
Getting Load errors but I can't seam to find the faults.
Can you help locating the offending. It looks like a call to the LCD ?
I think I have the LCD settings working to clear the LCD to list the current steps.
John
Attached the new flowcode build
Building CASM file
Serious Warning: Possible sw stack corruption, function 'FCI_DELAYINT_MS' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Serious Warning: Possible sw stack corruption, function 'FCD_04071_LCD__Clear' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Serious Warning: Possible sw stack corruption, function 'FCD_04071_LCD__Cursor' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Serious Warning: Possible sw stack corruption, function 'FCD_04071_LCD__PrintString' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Serious Warning: Possible sw stack corruption, function 'FCD_04071_LCD__ClearLine' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Serious Warning: Possible sw stack corruption, function 'delay_ms' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Serious Warning: Possible sw stack corruption, function 'delay_s' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
I got the PortB0 to trigger and it works every time.
The issue I see know is Flowcode works every time but the hardware locks up after the Relay2 macro runs
Getting Load errors but I can't seam to find the faults.
Can you help locating the offending. It looks like a call to the LCD ?
I think I have the LCD settings working to clear the LCD to list the current steps.
John
Attached the new flowcode build
Building CASM file
Serious Warning: Possible sw stack corruption, function 'FCI_DELAYINT_MS' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Serious Warning: Possible sw stack corruption, function 'FCD_04071_LCD__Clear' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Serious Warning: Possible sw stack corruption, function 'FCD_04071_LCD__Cursor' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Serious Warning: Possible sw stack corruption, function 'FCD_04071_LCD__PrintString' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Serious Warning: Possible sw stack corruption, function 'FCD_04071_LCD__ClearLine' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Serious Warning: Possible sw stack corruption, function 'delay_ms' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Serious Warning: Possible sw stack corruption, function 'delay_s' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
- Attachments
-
- Relay Driver Oct 20 2018.fcfx
- (44.22 KiB) Downloaded 232 times
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Faster detection on Port A0
Thanks John, Happy to helpJLeith wrote:Really nice to hear from you on my newest project
I don't believe it would be the same pickle at all!JLeith wrote:Would I not be in the same pickle with the timer ?
Both interrupts are placed at the start so are only ever enabled once.
Add a timer2 interrupt and set the properties for the very lowest whole frequency = 125Hz
to do that set both pre and post scaler to 16 and Rollover to 250.
Select Create a new macro and call it something like Timer2ISR
How the interrupt works is precisely every second the interrupt call macro called Timer2ISR would have been accessed 125 times.
In other words once every 1/125 = 8 ms.
So if you have a byte TimerTick and a Int Seconds variable then you can have
Code: Select all
If TimerTick <125:
Code: Select all
Yes: TimerTick = TimerTick + 1:
Code: Select all
No: TimerTick = 0: If Seconds < 300:
Code: Select all
Yes: Seconds = Seconds + 1:
Now add another interrupt - interrupt on INT0 Pin
Select Create New Macro and name it something like
Code: Select all
INT0ISR
Code: Select all
GhostDetected = 1
Code: Select all
Seconds = 0
Then within main you can have two decision branches.
Code: Select all
If Seconds = 300 then: Seconds = 0: Do what ever is required when 5 minutes has elapsed e.g call macro
Code: Select all
If GhostDetected = 1 then: GhostDetected = 0: Do what ever is required when ghost has been detected e.g call macro
Martin
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Faster detection on Port A0
Hi John,
Not seen your latest post prior to my latest post.
If you follow my suggestion on where and what to place within the interrupts then you won't have any corruption issues causing lock-ups.
To prevent corruption, keep interrupts as short as possible,
Don't place any delays or components that are used anywhere else within flowchart.
As you can see within INT0 interrupt macro there is only one calculation box with
Keep it short = no issues.
Not seen your latest post prior to my latest post.
If you follow my suggestion on where and what to place within the interrupts then you won't have any corruption issues causing lock-ups.
To prevent corruption, keep interrupts as short as possible,
Don't place any delays or components that are used anywhere else within flowchart.
As you can see within INT0 interrupt macro there is only one calculation box with
Code: Select all
GhostDetected = 1
Martin
- JLeith
- Posts: 537
- Joined: Wed Nov 14, 2012 7:49 pm
- Location: British Columbia Canada
- Has thanked: 146 times
- Been thanked: 26 times
Re: Faster detection on Port A0
Hi Martin
Crash & Burn
Note: Seconds is used in the timer_int Macro. I used the term sec but not much luck
I added the Interrupt
1. Timer 2
And Added the Macro
Timer2ISR
And added the 2 decisions
Now the Flowcode just runs then stops
Crash & Burn
Note: Seconds is used in the timer_int Macro. I used the term sec but not much luck
I added the Interrupt
1. Timer 2
And Added the Macro
Timer2ISR
And added the 2 decisions
Now the Flowcode just runs then stops
- Attachments
-
- Timer2 Oct 20 2018.fcfx
- (48.36 KiB) Downloaded 221 times
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Faster detection on Port A0
Hi John,
Made some corrections for you.
See how you get on with flowchart now.
You need to make sure your other call macros are correct.
Made some corrections for you.
See how you get on with flowchart now.
You need to make sure your other call macros are correct.
- Attachments
-
- Timer3 Oct 20 2018.fcfx
- (43.93 KiB) Downloaded 232 times
Martin
- JLeith
- Posts: 537
- Joined: Wed Nov 14, 2012 7:49 pm
- Location: British Columbia Canada
- Has thanked: 146 times
- Been thanked: 26 times
Re: Faster detection on Port A0
Hi Martin
Endless Loop once B0 is detected in Flowcode. And nothing happens in the Chip
i have loaded into Chip... BO doesn't trigger when activated
The Seconds timer works in chip. Watching to see what the chip does at 300
Nothing happened when the Chip went to 300 just went back to zero
I added the LCD messages so I could follow the code.
version to is Timer3A
The Compiler Errors are gone.
Martin do you know why when I load to chip I get a long line of ...............................................
Then the file saves. It works just curious.
Endless Loop once B0 is detected in Flowcode. And nothing happens in the Chip
i have loaded into Chip... BO doesn't trigger when activated
The Seconds timer works in chip. Watching to see what the chip does at 300
Nothing happened when the Chip went to 300 just went back to zero
I added the LCD messages so I could follow the code.
version to is Timer3A
The Compiler Errors are gone.
Martin do you know why when I load to chip I get a long line of ...............................................
Then the file saves. It works just curious.
- Attachments
-
- Timer3A Oct 20 2018.fcfx
- (47.6 KiB) Downloaded 235 times
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Faster detection on Port A0
Lets concentrate on the triggering side first.
You have the the triggering circuit connected to port b0?
What is the voltage when not triggered and when triggered?
What do you want to happen as soon as trigger detected?
You have the the triggering circuit connected to port b0?
What is the voltage when not triggered and when triggered?
What do you want to happen as soon as trigger detected?
Martin
- JLeith
- Posts: 537
- Joined: Wed Nov 14, 2012 7:49 pm
- Location: British Columbia Canada
- Has thanked: 146 times
- Been thanked: 26 times
Re: Faster detection on Port A0
Good News Martin
With your help with the timer made it possible
I added in the PortB0 Interrupt
Add resets to the sec timing after No Ghost and also when Ghost detected.
I adjusted the timers for testing. I'm not sure if I can post the Sec on the LCD it updates to fast. Not sure if I can post LCD during the 1 sec timer.
Version Timer AAA is working in the Chip not so much in Flowcode the LCD update doesn't follow the Chip Action.
I just need to clean up the "No Ghost" relay action in "Relay" and "Relay2" Just to clean the Code.
Do you see anything I have errors on ?
John
With your help with the timer made it possible
I added in the PortB0 Interrupt
Add resets to the sec timing after No Ghost and also when Ghost detected.
I adjusted the timers for testing. I'm not sure if I can post the Sec on the LCD it updates to fast. Not sure if I can post LCD during the 1 sec timer.
Version Timer AAA is working in the Chip not so much in Flowcode the LCD update doesn't follow the Chip Action.
I just need to clean up the "No Ghost" relay action in "Relay" and "Relay2" Just to clean the Code.
Do you see anything I have errors on ?
John
- Attachments
-
- Timer3AAA Oct 20 2018.fcfx
- (48.58 KiB) Downloaded 175 times
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Faster detection on Port A0
As the seconds continuously count up (or you could have it to count down) in the background, you can have the seconds displayed live.
Just within the main loop place a LCD print number macro for the seconds.
best to place a 100ms delay also within the main loop so LCD is not being updated too fast.
Just within the main loop place a LCD print number macro for the seconds.
best to place a 100ms delay also within the main loop so LCD is not being updated too fast.
Martin
- JLeith
- Posts: 537
- Joined: Wed Nov 14, 2012 7:49 pm
- Location: British Columbia Canada
- Has thanked: 146 times
- Been thanked: 26 times
Re: Faster detection on Port A0
Morning Martin
I was able to get the B0 to trigger every time.
The Green or is it Blue of no return happen. I placed a Count down as you indicted and I was not getting the numbers correctly.
Example - 4 - 3 - 1 - 3 - 2 - 1
Could not see why I could not see a clean 4 -3 - 2 -1....Relay
What I don't follow is after a Non Ghost the relays activate but the 5 min loop doesn't loop back to timing. I think also the Ghost Detected doesn't always loop back
I know how how a program completed will fall back to the called Macro just can't follow how the Timer gets called back to restart.
I made it easier to code by Ghost = Trick & Treat Kids
Events: On startup ----5 min timer--------At (0) --- Activate Macro Relays with Ghost =4----Then return to count down from 5 min
The PortB0 trigger ------------------------------------- At any time a Ghost is Detected the Macro Relay 2 triggers ----This should reset the 5 Min timer Also
I added the Flowcode with the count down.
I was able to get the B0 to trigger every time.
The Green or is it Blue of no return happen. I placed a Count down as you indicted and I was not getting the numbers correctly.
Example - 4 - 3 - 1 - 3 - 2 - 1
Could not see why I could not see a clean 4 -3 - 2 -1....Relay
What I don't follow is after a Non Ghost the relays activate but the 5 min loop doesn't loop back to timing. I think also the Ghost Detected doesn't always loop back
I know how how a program completed will fall back to the called Macro just can't follow how the Timer gets called back to restart.
I made it easier to code by Ghost = Trick & Treat Kids
Events: On startup ----5 min timer--------At (0) --- Activate Macro Relays with Ghost =4----Then return to count down from 5 min
The PortB0 trigger ------------------------------------- At any time a Ghost is Detected the Macro Relay 2 triggers ----This should reset the 5 Min timer Also
I added the Flowcode with the count down.
- Attachments
-
- Timer3AAA Oct 20 2018.fcfx
- (47.85 KiB) Downloaded 152 times
-
- Relay Flow.png
- (8.15 KiB) Downloaded 3601 times
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Faster detection on Port A0
I have made a fair few changes.
You definitely don't require 2 timer interrupts.
I only had timer2 in mind as the timing is much more accurate than timer0
Should work on hardware better than simulation.
At all times you should see on the display exactly how many seconds are left including the 10 & 20 second delays.
I never use a delay component that is for 10 seconds or greater as the hardware has to effectively pause.
During that time, display can't be updated.
You definitely don't require 2 timer interrupts.
I only had timer2 in mind as the timing is much more accurate than timer0
Should work on hardware better than simulation.
At all times you should see on the display exactly how many seconds are left including the 10 & 20 second delays.
I never use a delay component that is for 10 seconds or greater as the hardware has to effectively pause.
During that time, display can't be updated.
- Attachments
-
- Timer3AAA Oct 21 2018.fcfx
- (42.87 KiB) Downloaded 188 times
Martin
- JLeith
- Posts: 537
- Joined: Wed Nov 14, 2012 7:49 pm
- Location: British Columbia Canada
- Has thanked: 146 times
- Been thanked: 26 times
Re: Faster detection on Port A0
Works like a charm
I see you did a cleanup of the Time_tmr and the Variables.
In my Main at the start is there a cleaner way to reset the PortC and Port A. I have relay banks on the outputs and they need to be at Logic 1 state.
They use Logic 0 to active. Opto Couplers
I was trying the Masking but not getting the action I was hoping.
I see you also put the count down on the 10sec time for the Relays and the 20sec when a Ghost is detected.
Great work.
John
I see you did a cleanup of the Time_tmr and the Variables.
In my Main at the start is there a cleaner way to reset the PortC and Port A. I have relay banks on the outputs and they need to be at Logic 1 state.
They use Logic 0 to active. Opto Couplers
I was trying the Masking but not getting the action I was hoping.
I see you also put the count down on the 10sec time for the Relays and the 20sec when a Ghost is detected.
Great work.
John
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Faster detection on Port A0
Glad it works like a charm.
rather than 1 to a .
Just select each bit that has to be at 5V.
Make sure any other bits that you don't want to be at 5V are not selected.
I thought you may like that touch.
Are you now more familiar how interrupts work?
Yes just output 255 to theJLeith wrote:In my Main at the start is there a cleaner way to reset the PortC and Port A
Code: Select all
Entire port
Code: Select all
Single Bit
Just select each bit that has to be at 5V.
Make sure any other bits that you don't want to be at 5V are not selected.
Thanks John,JLeith wrote:
I see you also put the count down on the 10sec time for the Relays and the 20sec when a Ghost is detected.
Great work.
I thought you may like that touch.
Are you now more familiar how interrupts work?
Martin
- JLeith
- Posts: 537
- Joined: Wed Nov 14, 2012 7:49 pm
- Location: British Columbia Canada
- Has thanked: 146 times
- Been thanked: 26 times
Re: Faster detection on Port A0
Hi Martin
Yes on the interrupts are clear.
I will look at clean up of the individual port settings
The 10sec is for Non Ghosts so the Monsters are not on to long. The 20sec is when a Ghost is Detected so the Fog Machine have time to cool down.
Thank you so much with the Timer help.
John
Yes on the interrupts are clear.
I will look at clean up of the individual port settings
The 10sec is for Non Ghosts so the Monsters are not on to long. The 20sec is when a Ghost is Detected so the Fog Machine have time to cool down.
Thank you so much with the Timer help.
John