I am having a weird problem here, and I'm wondering if someone has any idea
what's going on. I'm building a new version of my charcoal smoker temperature
controller, and decided to incorporate a damper on the airbox. That way, when it wants
to cool off the smoker, the damper closes and it cools off quicker.
I decided to use an R/C servo to control the damper, that way it is easy to adjust the
open / close points. Rather than have my main processor (18F2550) control the servo, I
decided to use a 12F683 and just have a line from the main processor that goes high or low.
This way, the main processor doesn't have to worry about creating the pulse that controls
the servo.
I only need the servo all the way one way (1mS pulse) or the other (2mS pulse), no proportional
control is needed.
Below is the original way I wrote the code. The numbers for pulse count and pulse
are what worked out to the two pulse lengths and the 20mS period. It worked fine.
I wanted to have a little more resolution for adjustments, so I decided to change the 100uS
pause to 50uS and double the other three numbers. When I looked at the signal on the scope,
it was nowhere near what I wanted. In fact, I had to lower the three numbers almost to
where they were in the original!
Is 50uS just too fast for 8Mhz? If not, what else could have caused this effect?
Code:
#CONFIG
__config _INTRC_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 TRIGGER INPUT
'GP5 USED FOR LED
'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 = %00011011 'GP5 AND GP2 ARE OUTPUTS, THE REST ARE INPUTS
ANSEL = 0 'NO ANALOG PORTS - ALL DIGITAL
WPU = %00010000 'GP4 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.4
LED VAR GPIO.5
'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 = 19 '2.0mS PULSE TO SERVO
LED = 1 'TURN ON LED
ELSE 'OPEN THE DAMPER
PULSE = 8 '1.0mS PULSE TO SERVO
LED = 0 'TURN OFF LED
ENDIF
FOR PERIOD_COUNT = 1 TO 187 '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