Query regarding paralle tasks and kbin

hnorwood

New Member
Hello,
I'm on my second project using these devices. I have a circuit that takes ps/2 keyboard input and drives a small two-arm semaphore. Currently, it has to wait until one character has been displayed before it will accept another keypress, as the manual says that processing stops while the picAXE waits for a keyboard press. It would be nice to have a keyboard buffer.

So... my question is - can I put the keyboard input routine in one parallel task and the arm-waving routine in a second parallel task, connecting the two with a circular buffer - or will the kbin [timeout], variable command stop both processes?

Many thanks in advance

Hugh Norwood

PS here is a video of the prototype in action:

http://youtu.be/RZwXq13EMoA
 
Last edited:

Paix

Senior Member
I can't answer your question with any authority I'm afraid. Welcome to the forum,

The video is good; A mechanical bunting tosser! I have to ask the question why the orientation of the shoulders is not horizontal? I know that Matelots can sometimes not appear to be human, but horizontal shoulders are necessary to do a lot of sailor things!

An educated colleague a few years ago enquired, what is a Matelot. Said colleague had no bunting, but he almost qualified . . . !

Bunting tosser at work
In the picture, the message was, "Radio operator reports flat battery!" Mein Radio ist kaputt!
 

westaust55

Moderator
Welcome to the PICAXE forum

From the PICAXE manual 2:
KBIN – Wait until a new keyboard press is received

The KBIN command is a blocking command just like SERIN and others. You can use the [TIMEOUT] parameter to limit the time the command waits before proceeding to the next/indicated command.

The PICAXE is a single core CPU so it can give the illusion of doing multiple things at once by rapidly alternating between commands in different tasks but for 'blocking commands' the PICAXE has to concentrate on executing the command and won't switch tasks until completed.
 

hnorwood

New Member
Thank you for the replies:
I had reached more or less the same conclusion about kbin by running a simulation in the programming editor. Oh, well, that's not to be then.

As regards the mechanical prototype, it is a model of one of the Admiralty's Popham semaphore towers where there were two arms 8 ft long, one above the other! They had a couple of semaphore lines linking the Admiralty in London to the coast during the Napoleonic wars.
 

hippy

Technical Support
Staff member
One option for non-blocking input on a PICAXE is the hardware serial input. It would be possible to create a keyboard to serial converter with another PICAXE and have the servo controlling PICAXE take serial input from that.

Or have the keyboard handler buffer characters and supply those on demand when asked. That would probably be easiest for an M2 which has a very small background serial buffer.
 

Roman505

Member
I faced essentially the same problem while designing a device using IR input, also a blocking command, using older Picaxe chips which lacked the TIMEOUT command. My solution was as hippy says, use two! One picaxe is dedicated to the blocking input. When it receives data and thus comes alive to the circuit world, as it were, it sends an interrupt to a second picaxe which controls external operations. That second picaxe receives the data item when it handles the interrupt and manages the output accordingly, while the first picaxe goes back to waiting for more.

As an extra layer for reliable communication, I have picaxe 2 raise a flag when it is ready to receive data after being interrupted, to cater for any other activity in which it may be indulging. Thus, picaxe 1 does not send data after it sends an interrupt until it is signalled to do so. There is a minor risk of losing next key input here. You could solve that with a third little picaxe interposed, dedicated to buffering data-in to data-out.

Old programmer saying: you can always add a layer of indirection.

:)
 

hippy

Technical Support
Staff member
Old programmer saying: you can always add a layer of indirection.
Or two.

There's always a problem with anything blocking as noted; you can't block on a KBIN ( or IRIN ) and handle polling from or interrupting another without having to give in some way. You may either miss requests for data while executing KBIN or not be able to re-enter KBIN until the data is taken and miss a character typed, but by having an intermediary which never blocks it should be able to handle both sides quickly enough that data is passed along without anything being missed.

An 08M2 has enough I/O to be able to poll or respond to a PICAXE on either side of itself that, although it is extra hardware, it's not an overly expensive nor complicated solution if one desires it.
 

hnorwood

New Member
It might be possible to rewrite the program so that it looks at kbin in passing while doing everything else....
 

hnorwood

New Member
Just a little update on the semaphore tower: The arms are now installed, Here is a short video clip. Once again, please ignore the date/time stamp

 
Top