??? 07/19/09 00:41 Read: times |
#167533 - RC servos and 8051 |
Hello, I want to make a project, I want to drive 2 RC servos and 3 leds by PWM.
I'm actually using an AT89S52 with a 24mhz crystal The servo is the cheap Towerpro SG90 I had made some tests with this servo and discovered its minimum range is at 800uS, its maximum range is at 2390uS and its minimum "post PWM" time (output low) is around 12ms. I would like to drive both servos and led with 8bit PWM for 256 values. For servos, I will have 1590uS to do an 8bit PWM, by my calculation, a timer set to 12 cycles per overflow will give 1536uS total. I thinking 12 cycles for doing the PWM is critical. I will also need to handle incoming serial bytes at constant stream at every 44uS. But thinking just about the servos (by now) This is the partial untested code I made, but I already past 12 cycles :( PWMPos EQU R7 PrePWM EQU R5 PosPWM EQU R6 PanPWM EQU 76H ORG 0000H ;RESET VECTOR SJMP CONFIG ORG 000BH ;TIMER ZERO OVERFLOW CJNE PrePWM,#0,T0IEndDecPre ;if not zero do 800 before pwm CJNE PosPWM,#0,T0IEndDecPos ;if not zero do 20ms after pwm ;if both zero time to PWM positioning DEC PWMPos MOV A,PWMPos CJNE A,PanPWM,$+3 MOV P2.0,C ;Set output to servo CJNE PWMPos,#0,T0IEnd ;check for PWM end, prepare for post PWM MOV PosPWM,#?? ;here should set to wait the post 20ms T0IEndDecPre: DEC PrePWM JMP T0IEnd T0IEndDecPos: DEC PosPWM T0IEnd: CLR T0 RETI CONFIG: MOV TMOD,#00000010B ;T0 autoreload MOV TH0,#12 ;Reload Value MOV TL0,#12 SETB EA SETB ET0 Please somebody can give me some help to solve this? An Ideia? Maybe a more efficient routine for timer. Maybe I could use one timer to each motor, every overflow it changes its next overflow time to just change the output state in the right time. But dont know what to do with the leds. I got a bit lost now :( Thanks in advance. |
Topic | Author | Date |
RC servos and 8051 | 01/01/70 00:00 | |
Intended serial speed 22727 bytes/s? | 01/01/70 00:00 | |
Continuing on this one? | 01/01/70 00:00 | |
And no answer to this one either...![]() | 01/01/70 00:00 |