![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| Hi, I've just started to learn using a servo motor yesterday. I bought a second hand servo from my senior, which has been modified to 360. http://www.trossenrobotics.com/store...rvo-HS322.aspx I couldn't find the datasheet of it. After researching, I found that the pulse given to the servo is from 1 ms to 2 ms and it is being updated every 20 ms. So I come out with this program: Code: LIST P=16F88 #include <P16F88.inc> errorlevel -302 __config _CONFIG1, 0x3f50 __config _CONFIG2, 0x3fff cblock 0x20 count1 counta countb offcount endc org 0x0000 goto Initialize Initialize bsf STATUS, RP0 movlw 0x07 movwf CMCON clrf ANSEL movlw 0x6e ;4 MHz, 1 us instruction cycle. movwf OSCCON movlw b'00011100' movwf TRISA clrf TRISB bcf STATUS, RP0 clrf PORTA clrf PORTB Start btfsc PORTA, 2 call One25 btfsc PORTA, 3 call One50 btfsc PORTA, 4 call One75 call Delay50 goto Start One25 ; movlw .156 ;1.25ms movlw .150 movwf offcount bsf PORTB, 4 call DelayW call Off return One50 ; movlw .187 ;1.5ms movlw .176 ;1.408ms, servo not moving movwf offcount bsf PORTB, 4 call DelayW call Off return One75 ; movlw .219 ;1.75ms movlw .200 movwf offcount bsf PORTB, 4 call DelayW call Off return Off movf offcount, w ;2 ms - on time + 18 ms = total off time sublw .250 bcf PORTB, 4 call DelayW call Delay18 return ;W 8 instruction cycle routine from Pommie. DelayW ; will delay W*8 cycles including the call/return addlw 0xff; add -1 to W 1 btfsc STATUS,Z; =zero? 1/2 goto DoneDelay; yes, better get out of here 2 nop; delay a bit 1 goto $+1; delay a bit more 2 goto DelayW; go around again 2 DoneDelay return ; 2 Delay50 movlw .50 ;delay 50 ms (4 MHz clock) goto d0 Delay18 movlw .18 goto d0 d0 movwf count1 d1 movlw 0xC7 ;delay 1mS movwf counta movlw 0x01 movwf countb Delay_0 decfsz counta, f goto $+2 decfsz countb, f goto Delay_0 decfsz count1 ,f goto d1 return end 1. Sometimes 1.408 ms pulse width the motor stops, sometimes it moves with very very low resolution. 2. Somehow I still couldn't figure out how much the pulse width represent how much the resolution, in degree. But I found that the turning angle for 1 pulse given won't be increased even I reduce the pulse width somewhere less than 1 ms. But I couldn't manage to get the exact value by just looking at it. 3. Sometimes when the motor is rotating counter clockwise for example, if there is any shaking to the motor, it turns clockwise for a while (less than 1 second) then turn back to counter clockwise. I'm sure that there is no connection problem. Is that the faulty of the motor? 4. When I turn off and on the supply every time, the servo turns a bit, then turns back. But sometimes it never turn back. Thanks
__________________ Superman returns.. | |
| |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| | ||||
| Title | Starter | Forum | Replies | Latest |
| PIC Hardware PWM for servo control | 1krr | Micro Controllers | 9 | 2nd December 2006 01:47 PM |
| Servo Controll... In reverse? | savage | Micro Controllers | 9 | 1st December 2006 04:11 PM |
| Replacing RC Servo w/ Custom PCB (Open Servo) | dknguyen | Electronic Projects Design/Ideas/Reviews | 3 | 29th May 2006 03:48 AM |
| Help required with servo motor controller | mayhem | Robotics Chat | 3 | 26th May 2006 05:21 PM |
| Servo Motor Help Needed!!!! | potpotpotpot | Robotics Chat | 10 | 10th May 2006 08:54 PM |