I need to set precise on/off timings for a blinking LED and I was surprised to see that when I switched to a 2N2222 transistor (with a 10k resistor between the GPIO.0 output and Base) in order to drive 4 LEDs that the overall on/off rate changed (it appears longer). I'm using a 20Mhz oscillator to get the best resolution possible, so am I doing something wrong? If I want a precise duty cycle is the only way by trial and error?
Code:
DEFINE OSC 20
@ DEVICE pic12F629, HS_OSC
@ DEVICE pic12F629, WDT_ON
@ DEVICE pic12F629, PWRT_ON
@ DEVICE pic12F629, MCLR_OFF
@ DEVICE pic12F629, BOD_ON
@ DEVICE pic12F629, PROTECT_OFF
@ DEVICE pic12F629, CPD_OFF
CMCON = 7 'Turn off comparators
TRISIO.0 = 0 'Make GPIO.0 pin output
LED_0 VAR GPIO.0 ' Alias GPIO.0 to LED
DUTY VAR BYTE
CYCLE VAR BYTE
STEP_CNTR var byte
LGHTS_ON_MS CON 1410 '36 frames given the oscilattor accuracy
LGHTS_OFF_MS CON 550 '12 frames given the oscilattor accuracy
Cycle = 1
STEP_CNTR = 2
lblLoop:
' Fade in
For Duty = 0 TO 255 step STEP_CNTR
PWM LED_0, Duty, Cycle
Next
' Stay on LGHTS_ON_MS
High LED_0
Pause LGHTS_ON_MS
' Fade out
For Duty = 255 TO 0 STEP -STEP_CNTR
PWM LED_0, Duty, Cycle
Next
' Stay off for LGHTS_OFF_MS
Pause LGHTS_OFF_MS
GoTo lblLoop
End
Also, I'm using PWM to fade in/out the LED to give the appearance of incandescents - does that even work with a 2N2222 transistor?
Bookmarks