My project needed some small steps. [?More to come in a future 'Project"!?]
'
This utilizes Coridium's HWPWM11.bas file - as I used a Prostart board.
It also includes a 'Bit Bang' routine using a manually controlled (OUTPUT) designated pin.
'
Tried to 'pretty' up the code !!!!
Code: Select all
#include "LPC11xx.bas"
'tiankongrc SG90 servo - - 180 degrees .5ms to 2.5ms 1.5=center
CONST Cycletime = 20000
main:
dim ms20, ms_var, k, highTime, bigstep
'ms20 = 1
'ms_var = 500 '.5 ms for this servo - low volume
print "starting"
wait(2000)
output(9)
pwming:
'HWPWM ( channel, cycleTime, highTime ) '/microsecs
'HWPWM ( 2, 20000, highTime )
'// grz so I need to clear the old hightime and put in the new one
'// else I get 'chatter'
highTime = 500 '.5 ms for this servo - low volume
for k = 1 to 100
HWPWM ( 2, Cycletime, highTime ) ' chan 2 utilizes pin 9
wait(18)
next k
//
while bigstep < 9
print "input a value of 0 to 7 "
debugin bigstep
//
hightime = bigstep * 200 +500
T2_MR1 = 20000 - highTime + 1
wait(12)
// wait times could effect the chatter, had to experiment
'wait(1000)
loop
' highTime += 20
' if (ms20 mod 10) = 0
' print ms20, highTime
' endif
' if highTime > 1922 then stop
'next ms20
HWPWM ( 2, Cycletime, 700 )
print "done with PWM"
stop
//--------------------------------------------------
// Manual testing, using 'bit banging' a port pin
//--------------------------------------------------
zeroing:
ms_var = 500 '.5 ms for this servo - low volume
for k = 1 to 20
out(9) = 1
waitmicro(ms_var)
out(9) = 0
wait(18) 'just less than the max 20ms repetition rate
next k
stop
//
little_steps:
// searching for a 'little_step' value
for ms20 = 1 to 180 ' adjust upper limit to match the RC servo specification
for k = 1 to 10 'lets the servo settle
out(9) = 1
waitmicro(ms_var)
out(9) = 0
wait(18) 'just less than the max 20ms repetition rate
next k
ms_var += 11 // adjust as desired for 'little_step'
if (ms20 mod 10) = 0
print ms20, ms_var
endif
next ms20
print "done"
[u]// use the Basic Tool - <STOP> button as needed[/u]
goto zeroing
end