SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By drmikeg
#185695
Hi - i'm pretty new to all this so please be gentle.

I have just received a pair of sx 1509 (v1) boards.

I want to use PWM to control some 9g model servos.

I have had success doing this when the servo is directly connected to my arduino.
I've also had (some) success doing this using a 4019 decade counter to control multiple servos (the pwm timing part works ok - there are other issues to do with my managing the power usage)

I've started out using the very helpful SparkFun SX1509 Arduino Library.
The approach i'm using for the PVM is:
Code: Select all
io.digitalWrite(SX1509_SERVO_PIN, HIGH);
delaymicroseconds(n);
io.digitalWrite(SX1509_SERVO_PIN, LOW); // Set the I/O low
I've found I need to vary n from 0 to 1000. There is some lag, which results in producing pwm signals in the range ~1200-2200 microseconds (I've not measured this exactly, I'm basing this assumption on how far the servo is moving and the pwm timing I've used without the SX1509 in play)

I need figure out how long io.digitalWrite() takes:
a) for the output pin to switch high/low
b) for the function to return
so I can factor that into my pwm timings.

From a quick experiment last night, I couldn't get a full range of movement from the servo - and my early suspicion is that the culprit is that I can't produce a PWM cycle short enough for the minimum end of the servo's movement range (high for just 500 microseconds*)

(*I know this is way shorter than the datasheet for 9g servos, but empirically this seems correct and is the default in the arduino servo library too)

I can get about 100 degrees of movement - (which I could probably live with) but it would be nice to understand where those other 70 degrees are hiding...

I had a look at the pwm / digital write code in the library - but I'm not really understanding the low level chip controls for the sx 1509.
I had a look at the pwm example for LEDs, but I need very specific timings - I don't think the 256 value duty cycle is in the range I need.

(Yes, I'm using external power for the servos. I'm also monitoring the current and only letting one servo move at once).

Questions:

1) Does anyone have an experience of driving servos from these boards?

2) Is there too much lag in the i2c for me to get fine enough control

3) Do I need to use an external clock signal?

4) Does anyone have an generally useful suggestions for me?

Many thanks for taking the time to read this. Best wishes.
By kill
#194288
Hi
don't have anny experience with servos, but you can probably ( i say probably, haven’t really tested this) controll the clock of the PWM either by an external clock to the SX1509 (regClock) or by fiddling with the clkX divisor (regMisc)