john green
Member
Greetings,
Having just started on the great PICAXE learning curve and for this purpose have obtained a PICAXE28X1 starter kit (16F886), I seek an explanation for a quandary and how best to approach overcoming this.
Purely for the purpose of learning, I have been trying to achieve an adjustable square wave form to create a PWM servo drive. The simple program written seems to work perfectly and observing the outputs in simulation, the values behave as expected and desired.
In reality however, the output (which is an impressively symmetrical and free of noise), never exceeds approximately a 50% duty due to the ‘off’ duty period being extended by the time required to read the ‘main’ part of the program. The effect is unchanged by altering the total duty period even in the micro second range.
The code presented is a much simplified version using a similar construction which displays exactly the same tendencies. The actual times (as comments on right hand side) are read from a sillyscope reading the output. Regardless of the low pause input demanded, the off period remains about 12mS.
I have explored the onboard pwm elements but can see no way of using these to simply achieve the same requirements.
It seems to me that I have either missed some vital step in the set up or perhaps, the 28X1 chip is not suitable for such uses. Whatever, I have exhausted my limited resources of understanding and would appreciate suggestions from those who know more!
Having just started on the great PICAXE learning curve and for this purpose have obtained a PICAXE28X1 starter kit (16F886), I seek an explanation for a quandary and how best to approach overcoming this.
Purely for the purpose of learning, I have been trying to achieve an adjustable square wave form to create a PWM servo drive. The simple program written seems to work perfectly and observing the outputs in simulation, the values behave as expected and desired.
In reality however, the output (which is an impressively symmetrical and free of noise), never exceeds approximately a 50% duty due to the ‘off’ duty period being extended by the time required to read the ‘main’ part of the program. The effect is unchanged by altering the total duty period even in the micro second range.
The code presented is a much simplified version using a similar construction which displays exactly the same tendencies. The actual times (as comments on right hand side) are read from a sillyscope reading the output. Regardless of the low pause input demanded, the off period remains about 12mS.
I have explored the onboard pwm elements but can see no way of using these to simply achieve the same requirements.
It seems to me that I have either missed some vital step in the set up or perhaps, the 28X1 chip is not suitable for such uses. Whatever, I have exhausted my limited resources of understanding and would appreciate suggestions from those who know more!
Code:
main:
low 6
readadc 0,b1 ;read pot input 0-255
if b1 <10 then low 7
endif
if b1 >10 and b1 <40 then goto out1:
if b1 >40 and b1 <80then goto out2:
if b1 >80 and b1 <120 then goto out3:
if b1 >120 and b1 <160 then goto out4:
if b1 >160 and b1 <200 then goto out5:
if b1 >200 and b1 <240 then goto out6:
if b1 >250 then goto out7:
goto main
out1:
high 7 ;1H,L9, high2,low 12,total 14
pause 1
low 7
pause 9
goto main
out2:
high 7 ;2H,L8, high3,low 12, total 15
pause 2
low 7
pause 8
goto main
out3:
high 7 ;3H,7L, high4,low 12, total 16
pause 3
low 7
pause 7
goto main
out4:
high 7 ;5H,5L, high5,low 12,total 17
pause 5
low 7
pause 5
goto main
out5:
high 7 ;7H,3L, high7,low 12,total 18
pause 7
low 7
pause 3
goto main
out6:
high 7 ;9H,1L, high9,low 10, total 19
pause 9
low 7
pause 1
goto main
out7:
high 7 ;10H, full wave
pause 10
goto main
Last edited: