SERVO command

Colin0704
Posts: 3
Joined: Fri Jan 24, 2014 5:04 am

SERVO command

Unread post by Colin0704 »

Apologies if this subject has already been covered but I can't see it in any previous post.

I've tried to use the SERVO command, but get a syntax error as soon as the programme starts.

I've noticed it in listed in the manual.pdf but not online in the list of commands. Is it still a valid command?

The exact code I'm using is - SERVO(9,1500) to centre a servo connected to pin 9. I wondered whether the pin needed to be initialized as a PWM output, so used PINMODE 9,PWMPIN. This doesn't work either.

Any suggestions would be most welcome.
Daniel
Posts: 133
Joined: Tue Nov 13, 2012 2:10 pm

Re: SERVO command

Unread post by Daniel »

Hi Colin
The command you gave is correct and SERVO is a supported keyword. So there are a few possibilities; You found a bug, the manual is wrong or something else is going on. If the syntax error is something other than "Not a valid PWM pin" or possibly "Not a valid IO pin" then it is likely that I broke something during a bug fix.

Please try the command on pin 21, if you get the same result then I broke the code during another bug fix. I will get a module set up to test this afternoon and let you know what I see.

More info soon
Daniel
Colin0704
Posts: 3
Joined: Fri Jan 24, 2014 5:04 am

Re: SERVO command

Unread post by Colin0704 »

Hi Daniel

I've tried pin 21 and the same result.

If the command doesn't work, is it possible to use the PWM command to get the same affect with a 50hz base frequency?
Daniel
Posts: 133
Joined: Tue Nov 13, 2012 2:10 pm

Re: SERVO command

Unread post by Daniel »

Yes, it is possible to use the PWM command. Try the code below:

Code: Select all

' PWM Demo 50Hz at 32%, 40% and 60% duty cycle
' The four pins available FOR PWM is 9, 21, 36 AND 37
scale= 30000000/50
pinmode 21,PWMPIN
pinmode 36,PWMPIN
pinmode 9, PWMPIN
PWM 21, scale, 0.32*scale
WAIT 1000
PWM 36, scale, 0.4*scale
WAIT 1000
PWM 9, scale, 0.6*scale
END
and make the duty cycle 7.5% for mid scale
Daniel
Posts: 133
Joined: Tue Nov 13, 2012 2:10 pm

Re: SERVO command

Unread post by Daniel »

SERVO and PWM commands do not block the program flow. The output to the pin is done in hardware and works in the background.

I finally figured out what was wrong with your servo command. You added brackets where none are needed.
The command SERVO(9,1500) causes a syntax error SERVO 9,1500 does not. However, the manual is wrong. It indicates that the brackets are required. I will fix the manual.

In general, the idea is that commands that return a value requires brackets and commands which do not return a value do not need brackets. If anyone is aware of inconsistencies in this behavior please inform me so it can be made consistent.
Colin0704
Posts: 3
Joined: Fri Jan 24, 2014 5:04 am

Re: SERVO command

Unread post by Colin0704 »

Thank you Daniel.

Works fine now.
Post Reply