serout in parallel tasks


New Member

I have a program that uses parallel task processing feature of M2 and would like to send UART data with 9600 Bd with serout command.
As far as I understand, programs with parallel task processing automatically use 16 MHz clock frequency, but using N9600_16 results in a baudrate of 2400 Bd. Unfortunately, N9600_4 is not available.
Is there any trick to configure 9600 Bd?

#picaxe 08m2 
symbol P_SEROUT = C.0 
symbol P_LED = C.2 
#define LED_OFF high P_LED 
#define LED_ON low P_LED 
   serout P_SEROUT,N9600_16,("Test",cr,lf) ; N9600_16 results in only 2400 Bd 
   pause 1000 
goto task0_loop 
   pause 500 
   pause 500 
goto task1_loop


Senior Member
In general, you can use hserout as a direct replacement for serout on the M2 (as - with the exception of the 18M2 - they use the same default pin).

This example generates inverted serial for use with the AXE027:-
Rich (BB code):
symbol BAUD=B9600_16                                        ;hserout (multi-tasking means freq. is x4)

hsersetup BAUD,%10                                          ;inverted o/p
hserout 0,(cr,lf,#TIME," Some text")


Senior Member

You're asking a lot of a little 08M2 . ;)

But actually you should be able to use the "Alternate Pin Function Register" to swap the "HSEROUT" function onto Pin C.4 (Leg 3) of an 08M2. Untested, but I believe the following should execute the "Swap" (and then back again) between C.0 and C.4.
symbol APFCON = $5D
peeksfr APFCON, b1
b1 = b1 XOR 4      ; Toggle bit 2 to swap TX between C.0 and C.4
pokesfr APFCON,b1
The swap should be "transparent" to the program, but you will need to ensure that the levels on the two Port pins are correct (e.g. Idle Low) when the serial Hardware releases the pin that it has taken-over.

Cheers, Alan.


New Member

it does not have to be a 08M2, it could also be a 20M2, but that also does not work with serout at 9600 Bd. ;)

Thanks for your suggestion concerning pin swapping.

I see the following side effects:
- Task0 writes UART data to C.0
- Task1 also wants to write UART data to C.4
=> To achieve atomic accesses, one task would have to suspend the other task.

I would be very happy if I could just use serout in both tasks.
But unfortunately 9600 baud is not supported when using parallel task processing.
Although frequency is 16 MHz which should in theory be enough to generate 9600 Bd, because N9600_16 can be used in programs without parallel tasks. But it seems there is no way to configure 9600 Bd with serout in parallel tasks.


Senior Member

Personally, I've never found the multitasking feature "useful" in practice, it always seems to have too many restrictions, like this one. But IMHO, a "normal" program (particularly at 16 MHz) should be able to do almost anything that the multitasking facility can do, for example by using an interrupt, or simply with a more sophisticated single polling loop.

The M2 PICaxes are not well endowed with "timing events", but it's usually possible to find some workaround such as using PWM or Servo pulses (to generate an interrupt) or polling the "time" variable, etc..

Cheers, Alan.


Senior Member
Like Alan, I have never bothered using PICAXE's multitasking mode. To me, it complicates how various computing 'tasks' are prioritised. As you have discovered, it reduces your control of what happens within the chip.

I would use a single foreground loop that addresses all of your needs. PICAXEs are not multiple core devices, so only one command is executed at a time. SerOut is a blocking command: nothing else will happen in the PICAXE while the serial data is being transmitted. If two serial data outputs are required to different pins, one will follow the other.