can picaxe support background work?

Hi. I am trying to use one I/O pin to give pulse my decode counter IC from background while my main program is running. Is that possible? Actually i dont really know how microcontroller works. This is my first project. I am using 4017 decode counter ic to flash led's. My project is picaxe will send pulse one after another all the time at the input pin of the ic and othet sensor's, servos will work at the same time on picaxe defferent pins. If it is possible then how can i do it. I am using picaxe 28x2. 8khz. I think. Please help.
 

westaust55

Moderator
A couple of clarifications first –
- the 4017 is a 5 stage decade counter not a decode counter.
- the X2 parts operate at 8 MHz by default, not 4 kHz

The PICAXE chips only have a single core and therefore generally only perform one task at a time. There are a few exceptions such as Servo output pulses and PWM and X1/X2 parts background i2c comms receiving. Even these can be blocked by some other time critical commands such as SEROUT.

To make several tasks appear to happen in parallel, If you have an overall program loop then you can include within that loop using a timer as a test, a pulse output to advance the 4017 decade counter drive LED’s, then adjust the servo position (using a formula, test or table for determining the next position), finally read the input signals from other sensors. All this can also be done in any order.
 
Last edited:

inglewoodpete

Senior Member
It sure can. Here is a link to a demonstration routine I wrote for a 28X1. To help get your head around the code, you can connect 2 LEDs with limiting resistors to 2 of the pins of your 28X2.

As the code was originally written for a 28X1, you will need to update the references to pins to suit the 28X2. Eg "Toggle 4" becomes "Toggle B.4" etc.
 

g6ejd

Senior Member
Yes, but the PicAxe is a von Neumann architecture and so the closest you'll get is a pseudo parallel process and depending on the foreground (or background) task you have, there will be variations in pulse frequency as each code segment is executed.
 
@ wastus.

I got your point. What if i give pwm off comms when serout comms run? Can you give me an example of pwm command at 500ms pulse please?
 

westaust55

Moderator
In the Programming Editor under (from memory) the Tools tab there are Wizards including (via sub-menu) one for the PWM control where you set the pin, frequency and duty cycle and the Wizard provides a line of code you can cut and paste into your program.

You do not need to specifically turn off the PWM, when a blocking type command (eg SEROUT) occurs , that command will automatically stop/slow the PWM while the timing critical function occurs.
Some of this is covered in PICAXE manual 2 appendix 4 - Possible conflicting commands
 
Last edited:
Top