Have code running in background in Pbasic?
Brock
Posts: 2
I'm relatively new to Basic(1 week) and all programming I've ever done has been in c++ so i'm still learning some things. What I need is a section of code to be run in the "background" while the rest of the code
is running.
To give you a better idea, the processor is monitoring a pressure and battery voltage. When that voltage goes below a certain specified level, I want to have this LED blink(LED is on pin 13 of mcu). How do I incorporate that loop to run while the rest of the code runs? I see there is a POLLIN/POLLOUT commands that poll a pin after every line, but I am not polling the status of the pin, I would need to check the value of a variable then have a loop like
high 13
pause 1000
low 13
Thanks,
is running.
To give you a better idea, the processor is monitoring a pressure and battery voltage. When that voltage goes below a certain specified level, I want to have this LED blink(LED is on pin 13 of mcu). How do I incorporate that loop to run while the rest of the code runs? I see there is a POLLIN/POLLOUT commands that poll a pin after every line, but I am not polling the status of the pin, I would need to check the value of a variable then have a loop like
high 13
pause 1000
low 13
Thanks,
Comments
What you can do is to set up your main monitoring loop so that it takes roughly the same time to execute no matter what control path is taken and you use that as your "blink" timer instead of the PAUSE. Say that your main loop takes 100ms. You'd have a counter stored in a byte. If the byte is 255, you'd leave it alone otherwise you'd increment it with a wraparound at 20 back to zero. If the counter is less than 10, you'd turn the LED on. If the counter is 10 or higher, you'd turn the LED off.
To start the LED blinking, you'd set the counter to zero. To turn off the LED, you'd set the counter to 255.
One question is why would I wraparound at 20?
Another question I have is can I set a PollIN command to monitor an output that isn't being used(constant 0 value) and tell the pollin to look for 0 value and if it is the case
if(bat voltage < x)
hi 13
pause 500
lo 13
etc, and itll execute this set of code after every instruction
POLLIN doesn't work the way you want. It's not really an interrupt. Although POLLIN can cause code to be executed, there's no way to return to the "interrupted" code.
POLLIN and POLLOUT could help in a minor way. In one scenario, the POLLIN pin would be set up with a voltage divider to detect the battery voltage threshold. It would be coupled to the POLLOUT pin in such a way as to enable the flasher when the battery is low. No further program intervention would be necessary.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com