Servo PWM using 8 Bit timer

icemanfiveoh:
at this point i need to figure out how to invert the incoming signal. I am planning on using the pulsein() to grab the control pulse from the receiver, store that value, but from here i need some help. The way i am accomplishing this in my other circuit is i am generating a 3ms reference pulse with one 555 and then subtracting the incoming pulse from the receiver. this gives me exactly what i need. 3mS reference - 1ms = 2mS and 3mS - 2 mS = 1mS.

I’m one of the 4 people left who don’t use Arduinos so I hesitate to respond but …

Does the Arduino have an “interrupt on change” input pin ? If so why not have the servo signal routed to the IOC pin to trigger a service routine the starts a counter. Then the ISR sets a flag = “counting” and returns. When the pulse trailing edge happens the ISR runs and checks the flag and if “counting” is true, it stops and reads the counter. You’ve now measured the incoming pulsewidth. Then the Tiny can do the math and figure out the desired output pulsewidth. Setup the PWM output to run one cycle* with the duty cycle set to yield the desired PW and output that to the servo (perhaps needing an appropriate driver). Not sure if Arduino Sketch speak allows all this low level stuff but that’s how I’d do it.

Wash, rinse, repeat for each pulse from the controller. Now this scheme puts a variable transport lag into the pulsetrain but that could be fixed to a constant transport lag (~3 ms) if needed.

  • I guess you could set the PWM frequency to be 50 Hz (or whatever) and then just change the duty cyle (PW) to be whatever was last measured (and subsequently “inverted”) on the fly but you’d be back to having some variable transport lag in the system for that servo given the incoming and outgoing pulsetrains won’t be exactly the same frequency (or exactly 50 Hz). Perhaps that’s not an issue.