Is it possible to use Timer0 instead of Timer1 on a 18F4550 using Darrel's blinky program?
Darrel's blinky code works just fine at Prescaler 1 with Timer1 but I can't seem to get any variation in blink speed out of Timer0. I tried a gazillion combinations and I admit I'm not sure about the other settings in T0CON.
I don't have access to a scope right now and this desktop doesn't have enough memory to run Saleae from 1MHz and up.
LED2 was added to confirm I didn't screw up the PIC and it is blinking as expected. LED1 seems to be blinking very fast because it is just slightly paler than the other LEDs on the Lab X1 bargraph.
Or are the blinking so fast at any prescaler that I won't be able to see a difference? I was able to detect "very fast" blinking in Timer1 at 1:1 though.
Robert
PBP v2.60c
Code:
@ __CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
@ __CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H
@ __CONFIG _CONFIG2L, _PWRT_OFF_2L & _BOR_ON_2L & _BORV_1_2L & _VREGEN_ON_2L
@ __CONFIG _CONFIG2H, _WDT_OFF_2H
@ __CONFIG _CONFIG3H, _CCP2MX_ON_3H & _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
@ __CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_OFF_4L & _XINST_OFF_4L
DEFINE OSC 48
ADCON1 = %00001111
INTCON2 = %00000000
T0CON = %10000000 ; Prescaler = 2
' T0CON = %10000001 ; Prescaler = 4
' T0CON = %10000010 ; Prescaler = 8
' T0CON = %10000011 ; Prescaler = 16
' T0CON = %10000100 ; Prescaler = 32
' T0CON = %10000101 ; Prescaler = 64
' T0CON = %10000110 ; Prescaler = 128
' T0CON = %10000111 ; Prescaler = 256
' bit 7 TMR0ON: Timer0 On/Off Control bit
' 1 = Enables Timer0
' 0 = Stops Timer0
' bit 6 T08BIT: Timer0 8-Bit/16-Bit Control bit
' 1 = Timer0 is configured as an 8-bit timer/counter
' 0 = Timer0 is configured as a 16-bit timer/counter
' bit 5 T0CS: Timer0 Clock Source Select bit
' 1 = Transition on T0CKI pin
' 0 = Internal instruction cycle clock (CLKO)
' bit 4 T0SE: Timer0 Source Edge Select bit
' 1 = Increment on high-to-low transition on T0CKI pin
' 0 = Increment on low-to-high transition on T0CKI pin
' bit 3 PSA: Timer0 Prescaler Assignment bit
' 1 = TImer0 prescaler is NOT assigned. Timer0 clock input bypasses prescaler.
' 0 = Timer0 prescaler is assigned. Timer0 clock input comes from prescaler output.
' bit 2-0 T0PS2:T0PS0: Timer0 Prescaler Select bits
' 111 = 1:256 Prescale value
' 110 = 1:128 Prescale value
' 101 = 1:64 Prescale value
' 100 = 1:32 Prescale value
' 011 = 1:16 Prescale value
' 010 = 1:8 Prescale value
' 001 = 1:4 Prescale value
' 000 = 1:2 Prescale value
INCLUDE "DT_INTS-18.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ' Include if using PBP interrupts
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR0_INT, _ToggleLED, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
DEFINE LCD_DREG PORTD
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTE
DEFINE LCD_RSBIT 0
DEFINE LCD_EREG PORTE
DEFINE LCD_EBIT 1
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 1000
DEFINE LCD_DATAUS 50
TRISA = %00000000
TRISB = %00000000
TRISC = %00000000
TRISD = %00000000
TRISE = %00000000
LED1 VAR PORTD.0
LED2 VAR PORTD.1
@ INT_ENABLE TMR0_INT ; enable Timer 0 interrupts
PAUSE 1500 ' wait for PIC and LCD to stabilize
LCDOUT $FE,1,"Timer test Lab X1"
Main:
TOGGLE LED2
PAUSE 500
GOTO Main
ToggleLED:
TOGGLE LED1
@ INT_RETURN
END
I don't have access to a scope right now and this desktop doesn't have enough memory to run Saleae from 1MHz and up.
LED2 was added to confirm I didn't screw up the PIC and it is blinking as expected. LED1 seems to be blinking very fast because it is just slightly paler than the other LEDs on the Lab X1 bargraph.
Or are the blinking so fast at any prescaler that I won't be able to see a difference? I was able to detect "very fast" blinking in Timer1 at 1:1 though.
Robert
PBP v2.60c