Can you control PWMOUT on a slave picaxe

Adiman

Member
I know you can use serout to control pins on a slaved picaxe, connected by an output pin on the master, to a input pin of the slaved picaxe.

If I had say have a master 18x that I wanted to control a 08m as the slave. In this instance I dont simply want to control pins on the 08m, i want to use the 08m's pwmout feature and vary duty cycle etc by commands sent from the 18x. Basically I want to use the 08m as a slave PWM handler to run a seperate circuit and it needs high frequency switching and constantly adjustable duty cycle

Is this possible?

Any help would be appreciated!

Adrian
 

hippy

Ex-Staff (retired)
I can't see why it wouldn't work unless PWM stops during SERIN, which I don't think is the case. Instead of setting output bits in respsonse to received serial data, it would just mean setting PWMOUT instead, eg ...

- MainLoop:
- SERIN RX_PIN,RX_BAUD,b1,b0,b3,b2 ' w0=b1:b0 w1=b3:b2
- PWMOUT PWM_PIN,w0,w1
- GOTO MainLoop
 

Adiman

Member
Hippy or anyone else who seems to know a lot about this, I have another question -

How many commands from the 18x could I send by serout per second before problems occur if both are operating in n2400(4800 actual speed as 8mhz operation is used on both 18x and 08m via the setfreq m8 command)

The 18x would be sending the four(b0,b1,b2,b3) variables and the 08m would have the same receiving program as above posted by Hippy with setfreq m8 added of course.

Its kind of mission critical that i can make many changes in the duty cyle per second for my application!

Again, any help would be appreciated from anyone!

Edited by - Adiman on 9/10/2005 7:51:37 AM
 

hippy

Ex-Staff (retired)
The problems arise when data is received using consecutive SERIN commands. When a single SERIN is used to receive multiple bytes there is no problem, but the time between the end of one SERIN and another can cause data to be missed.

This is also a problem when the PICAXE receives its data by SERIN, processes it, and then waits for the next SERIN data. Any data sent before the PICAXE is ready for it will be lost.

The easiest way to ensure the transmitter doesn't send before the receiver is ready for data is to have the receiver set a line immediately before SERIN and clear it immediately after. The transmitter polls the line ( or uses interrupts ) and when it is set it sends its data, determines the data it needs to send next, then waits again.

The maximum data throughput depends upon three things; the time to transfer the data serially, the ime it takes to process the data and how quickly the transmitter sends its data after the 'clear to send' line gets asserted.

The largest overhead is the serial transmission time; at 2400, each byte takes about 4.17mS, four bytes would take about 17mS. That would give around 60 data transfers per second.

Using faster baud rates and overclocking will improve things. On the 08M, that's 4800 baud @ 8MHz, which would double thoughput to about 120 transfers per second.

- ' Transmitter
-
- WaitForClearToSend:
- IF CTS_PIN = 0 THEN WaitForClearToSend
-
- SEROUT TX_PIN,TX_BAUD,(b1,b0,b3,b2)
- GOSUB <i>CalculateNewValues </i>
- GOTO WaitForClearToSend

- ' Receiver
-
- MainLoop:
- HIGH CTS_PIN
- SERIN RX_PIN,RX_BAUD,b1,b0,b3,b2
- LOW CTS_PIN
- PWMOUT PWM_PIN,w0,w1
- GOTO MainLoop
 

Adiman

Member
Do they pay you on these forums hippy?

If I made sure there was at least a 50ms gap between each serout command would it still require the pin handshaking? or am I just asking for trouble aka eratic behavour?
 

hippy

Ex-Staff (retired)
If the receiver is actually only doing very simple ( ie quick ) processing, it will be back waiting for SERIN before the transmitter has calculated the next values to send, so there's often no need for handshaking or even a delay. If you do need a delay, it probably only needs to be a short one.

It's really only when the receiver takes near or longer to do its stuff than the transmitter that there's any real issues with timing.

[ PS : I wish :) ]
 

Adiman

Member
Thanks a lot for the info Hippy... i've even realised the 08m code can be even shorter, because the PWMout period is only a standard 8bit variable:

looper:
serin 1, n2400, (b2,b0,b1) REM B0,B1 = w0
pwmout 2,b2,w0
goto looper

That's all I have to have the 08m do when slaved, bit of a waste of processing power really using it just for PWMout, but it sure as hell makes things easy and they are cheap anyway!

Now I just have to wait for the 08m cpu's to come from Oatley to actually try it in practice
 
Top