Left for archival purposes.

User avatar
By pit
#7408 The SG90 servo is most inexpensive servo you can get these days. It operates at 50Hz (20ms pulse) with 1-2ms duty time going through the whole range from left to right. With a 1024 resolution however I'm limited only about 50 steps i.e.
1024 steps / 20ms * 1 ms = 51 (minimum value, servo is all the way to the left)
1024 steps / 20ms * 2 ms = 102 (maximum value, servo is all the way to the right)
So from the 1024 steps I can only use about 102max-51min = 51 steps which is about a 3.5 degree minimum turn per step at 180 degree freedom. 0.5 degree or less are desirable.
Can this be done?

Thanks!!
pit
User avatar
By milikiller
#7675 Better option, can be writing dedicated library for servo control. Because all PWM must have same period, is problematic driving servos at 50hz and cotroling RGB LED on same frequency... For led is higher frequency better.

I would like to use ESP8266 as micro RC telemetry Receiver and PWM period is big limit for me...

I must use 3 servos, and one DC motor (2 PWM) and have problem with 50Hz for small DC brushed motor. At 200Hz motor have much more precise regulation.


Solution is write library, independent on PWM, with fixed period 20ms and pulse lenght as parameter... This can simple be done with one timer at 20ms period and using sleep for specified amount of time for generating pulses... Problem is jitter, when module communicate over wifi. the precise delay, must be writen LOW Level, with precise timing.

Next week maybe I'll have time for testing it.
User avatar
By milikiller
#7837 Hi. I try to fix problem.

First problem is GPIO speed from LUA. Setting GPIO high and low from lua takes about 80us which is 16x longer then servo deadband. This is problem when I can try write code completely in LUA.

I can try add small function in timer module called "servo_pulse" that have 2 parameters (pin, time) this function disable interrupts, set GPIO to HIGH, delay specified amount of time in us and set GPIO back to LOW and enable interrupts... In C Its prety acurate. But if you have tmr.alarms or comunicate over wifi while servo pulse is running, communication can be broken or ESP8266 make reboot.

I update my servo function to work without interrupt disabling, its not precise as previous function, but causes less problems. I have lot of communication over wifi, every cca 8ms send packet and receive another one... and communication hangs in random interval, if servo_pulse is used.

I do not have a lot of other ideas how to solve it.

If program is in delay loop, wifi or other event is freeze and not work.