Guys,
Thanks for the suggestions. I'll follow your tips and see where they lead. It the meantime, here is a sample of the code that causes the servo to twitch.
I've observed that the jumps occur about 2 times per second, and are in a direction that a longer pulse width would cause. This supports Jerson's idea that the interrupt service is periodically adding to the pulse width. Maybe it would help if the ISR were written is assembly and therefore be faster?
Code:
'****************************************************************
'* Name : servo_demo.pbp *
'* Author : Dick Ivers *
'* Date : Nov 30, 2010 *
'* Notes : This is a simplistic demo of servo w/Elapsed Timer *
'****************************************************************
'435 program words
'device is PIC 16F690
'****************************************************************
'set device configuration
@ __config _HS_OSC & _WDT_ON & _MCLRE_ON & _CP_OFF
'set registers
CM1CON0.7 = 0 'comparator1 off
CM2CON0.7 = 0 'comparator2 off
ANSEL = 0 'porta pins all digital
ANSELH = 0 'all porta pins digital
DEFINE OSC 16 '16 Mhz oscillator
'declare variables
led var portc.5 'led output on portc.5
servopos var word
runtime var word 'motor runtime in tenths of seconds
start:
low led 'flash red LED for 0.5 sec to show circuit is functioning
pause 500
high led 'turn off led
INCLUDE "DT_INTS-14.bas" 'Base interrupt system
INCLUDE "ReEnterPBP.bas" 'Using PBP interrupts
INCLUDE "Elapsed_INT_RI2.bas" 'Elasped timer counting seconds and tenths seconds
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _ClockCount, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
@ INT_ENABLE TMR1_INT ; Enable Timer 1 Interrupts
runtime = 100 ' run servo for 10.0 seconds
servopos = 600 ' hold at mid servo range (4*150)
gosub ResetTime ' Reset Time to 0d-00:00:00.00
gosub StartTimer ' Start the Elapsed Timer
low Led 'turn on led
low portc.4 'turn on servo
main:
pulsout portc.0,servopos
pause 18
if time => runtime then 'stop servo when target time is reached
high led 'turn off led
goto hold
endif
goto main 'loop until endtime is reached
hold:
@ INT_DISABLE TMR1_INT ; Disable Timer 1 Interrupts
high portc.4 'turn off servo
end
Bookmarks