Originally Posted by
MillicentBear
I have been testing a program for a 12F683 to drive an RC servo. The compiler is Picbasic Pro ver 3 and both QL 200 and IDE 2 programmers give the same result. The programmed chip does nothing. Reducling the program to a simple loop turning a pin on and off with config setting Clk Out on pin 4, the analyser shows the clk operating at the default 4MHz instead of the config set 8MHz. After many hours and much reading of the datasheet and so on, no result. I sense the problem lies with the configuration statements, but even with only those in the .INFO file there is no response.
Has anyone a suggestion on what direction to go?
Don't know if this will help at all (I haven't read the whole thread yet) but here's one I use on a project of mine. Remember that, in my case, I only have to drive the servo from one extreme to another. I'm not using proportional control at all - just one side or the other.
But this works - so maybe it'll help.
Andy
Code:
'12F683 MCU USED FOR SERVO CONTROL
#CONFIG
__config _HFINT_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_ON & _CP_OFF
#ENDCONFIG
DEFINE OSC 8 'LETS PBP KNOW WE WILL BE RUNNING AT 8MHZ
DISABLE 'NO DEBUG, NO INTERRUPTS
'PIN DEFENITIONS
'GP0 USED FOR ICSP DATA
'GP1 USED FOR ICSP CLOCK
'GP2 USED TO DRIVE SERVO (SIGNAL LINE)
'GP3 USED FOR MCLR AND ICSP PROGRAMMING
'GP4 USED FOR LED
'GP5 USED FOR TRIGGER FROM MAIN PROCESSOR
'SET UP THE SPECIAL REGISTERS
OSCCON = %01110001 '8MHZ INTERNAL CLOCK USED
CMCON0 = %00000111 'CIN PINS ARE I/O, COUT PIN IS I/O
OPTION_REG = 0 'WEAK PULL UPS ARE ENABLED
TRISIO = %00101011 'GP4 AND GP2 ARE OUTPUTS, THE REST ARE INPUTS
ANSEL = 0 'NO ANALOG PORTS - ALL DIGITAL
WPU = %00100000 'GP5 WEAK PULL UP ENABLED. GP3 WEAK PULL UP AUTOMATICALLY ENABLED
'AS THE PIN IS DEFINED AS MCLR
IOC = 0 'NO INTERRUPT ON CHANGE
'PIN ALIASES
SERVO VAR GPIO.2
TRIGGER VAR GPIO.5
LED VAR GPIO.4
'VARIABLES
PERIOD_COUNT VAR BYTE 'TO TIME THE 20mS PERIOD
PULSE VAR BYTE 'PULSE LENGTH IN 100uS INCREMENTS
SERVO = 0 'MAKE SURE NO SIGNAL
LED = 0 'MAKE SURE LED IS OFF
MAIN:
DO 'ENDLESS LOOP
IF TRIGGER = 1 THEN 'CLOSE THE DAMPER
PULSE = 20 '2.0mS PULSE TO SERVO
LED = 1 'TURN ON LED
ELSE 'OPEN THE DAMPER
PULSE = 10 '1.0mS PULSE TO SERVO
LED = 0 'TURN OFF LED
ENDIF
FOR PERIOD_COUNT = 1 TO 200 '20mS PERIOD
IF PERIOD_COUNT > PULSE THEN 'MAKE LINE LOW FOR REST OF 20mS PERIOD
SERVO = 0 'MAKE SURE SERVO SIGNAL IS NOW LOW
ELSE
SERVO = 1 'SERVO SIGNAL LINE HIGH FOR 1.0 OR 2.0mS
ENDIF
PAUSEUS 100 '100uS PAUSE
NEXT PERIOD_COUNT
LOOP
END
Bookmarks