PWM, Pulsin and Servo 08M2

ol boy

Member
I need to receive an input pulse from an RC receiver, then set an output DAC 0 to 5 volts which will correspond to the 1000us to 2000us pulse in range. Then send a slightly different servo command to the servo. I'd use the DAC output on the 08M2 but I need better resolution than 32 steps. It might still be an option though.

I'm in the process of doing fuel injection on a large RC airplane 2 stroke motor. The ECU I'm using needs to see a 0 to 5 volt range for throttle position. Which is working well with pulsin and pwmout. Manual 2 states PWMOUT and servo command can not be used at the same time but nothing is mentioned about just plain old PWM command. Does PWM not use any of the interrupts or timers to function? Can I use PWM, pulsin and servo command together with out any timing/interrupt issues?

Thanks Ryan
 

hippy

Technical Support
Staff member
PWM is controlled by software rather than the PWMOUT which is controlled by hardware. So there should be no timer conflicts but it is not clear if PWM will give the desired results.

You could use two PICAXE reading the same RC pulse - one doing RC to PWMOUT throttle the other doing RC to SERVO - rather than try and do everything on one chip. The results should be exactly the same.
 

ol boy

Member
Man 2 states something about...
This pwm command is used to provide ‘bursts’ of PWM output to generate a
pseudo analogue output on the PICAXE pins.
I should beable to refresh the duty to give a new analog looking output based on the next pulsin results and drive a servo output.

I'll give it some testing and report back.
 

Goeytex

Senior Member
Hi Ryan,

I had never worked with "PWM" before and occasionally need a DAC output of some kind, so I wrote this little snippet and tested it on the bench. It works amazingly well. The idea is to charge a cap with PWM from 0 v to 5v with a 1ms to 2 ms servo signal. The voltage is then read with ADC with a value of 0 for 1ms and 255 for 2ms input. Attached is the code and the circuit.

Code:
[COLOR="#008000"]'This demo code assumes a servo pulse input signal from
'1 ms to 2 ms on Pin c.3. There are no provisions
'for a missing or out of range  signal.     
[/COLOR]
#picaxe 08m2
setfreq m16


Symbol Servo_In = W0
Symbol Scaled_In = W1
Symbol ADC_VAL = B4
Symbol Voltage = W3
 
do
       
   Pulsin c.3,1,Servo_In              [COLOR="#008000"]   '1ms to 2 ms [/COLOR]
   w1 = w0 - 400 * 16 / 25  max 255      [COLOR="#008000"]'Scale[/COLOR]
   
   pwm c.4,Scaled_In,5                   [COLOR="#008000"]'Generate voltage [/COLOR]
    
   readadc c.4,ADC_VAL                 [COLOR="#008000"] 'Switch to input & read voltage on same pin[/COLOR]
   
   low c.4                              [COLOR="#008000"] 'Discharge cap & take pin low[/COLOR]
       
 [COLOR="#008000"] ' ======  Convert to volts for debugging ======[/COLOR]
   voltage = ADC_VAL * 196 
   bintoascii voltage, b8,b9,b10,b11,b12
   
[COLOR="#008000"]'===== debugging  ========
'sertxd ("Pulsin = ",#Servo_In,cr,lf)
'sertxd ("Scaled = ",#Scaled_In,cr,lf) 
'sertxd ("ADC =",#ADC_VAL,cr,lf)[/COLOR]
sertxd ("Voltage = ",b8,".",b9,b10,cr,lf)
      
 [COLOR="#008000"]'Here is where you use the ADC_Value variable
 'to modify the servo out[/COLOR]
      
   pause 2000    [COLOR="#008000"]'Delete in working code[/COLOR]
loop
 

Attachments

ol boy

Member
I ended up using the DAC command to give an analog out put. The 31 steps of the DAC aren't too noticeable. I wounder if there is a way to switch between steps quickly enough to raise the step count to 63 steps. My code seems to do this when the rounding errors in the math bounce between to steps.

I'm also controlling a TIP35 to turn on and off the ignition for the motor.

Code:
'PICAXE 08M2 receive pulse width from RX channel, convert to Anolog output.  DAC

dacsetup %10100000
main:

do
pulsin c.3, 1, w0
 ' 0% throttle is a pulsin value of 100, = 1000us.  WOT 200, = 200 with a delta of 100 count, = 1000us,
 
b2 = w0-100
b3 = b2/3

if w0 <= 99 then 
b3=0
elseif w0 >= 195 then 
b3 = 31
endif
daclevel b3			'w1

if w0 < 100 then 
servo c.4, 100
elseif w0 > 200 then
servo c.4, 200
else
servo c.4, w0
endif 


if w0 > 98 then 			'b0,b1
high c.1
else
low c.1
endif

loop
 
Top