Miskatonic Institute of Technology

Miskatonic Institute of Technology
(click on emblem to learn more)

20.10.09

PIC servo controller

Finally i managed to drive my SG5010 digital servo using a PIC (pic16f887)




Here is my code in Mikrobasic:
program MyPWM_numca
' * Description
' PWM library was unable to drive the SG5010 digital servo, so i am writing
' my own program. It will read Analog from PORTA.0 and it will create pulse
' of apropriate width every 20ms in PORTC.2
'
' * Test configuration
'     MCU:            P16F887
'     Dev.Board:      44pin demo board
'     Oscillator:     internal 4Mhz
dim temp as word

sub procedure WAIT(dim temp10 as word)
dim i as word
i = 0
for i = 0 to temp10
delay_us(1)
next i
end sub

main:
ANSEL = 000001          ' Configure AN0 pin as analog
TRISA = 000001          ' PORTA is input
TRISC = 000000          ' PORTC is output for pulses
TRISD = 000000          ' PORTD is output for temp

while true
temp = ADC_READ(0)
PORTD = temp
PORTC = 000100
delay_us(400)
WAIT(temp div %1000)
PORTC = 000000
WAIT(1000-temp)
delay_us(18600)
wend
end.

Here are the files of this project.

Ελληνικό post: http://www.hlektronika.gr/forum/showthread.php?p=328745#post328745

No comments:

Post a Comment