a friend of mine asked my to arrange an output on a 12F1822 at 40 kHz on RA5. I've done in Proton Basic
- Code: Select all
Device 12F1822
Config1 FOSC_INTOSC, WDTE_OFF, PWRTE_OFF, MCLRE_OFF, CP_OFF, CPD_OFF,_
BOREN_OFF, CLKOUTEN_OFF, IESO_OFF, FCMEN_OFF
Config2 WRT_OFF, PLLEN_ON, STVREN_OFF,LVP_OFF
Symbol TMR1IF = PIR1.0 ' TMR1 Overflow Interrupt Flag
Symbol PEIE = INTCON.6
Symbol GIE = INTCON.7 ' Global Interrupt Enable
Symbol TMR0IF = INTCON.2 ' TMR0 Interrupt Flag
Symbol TMR0IE = INTCON.5 ' TMR0 Interrupt Enable
Symbol TRUE = 1 ' Boolean value
Symbol FALSE = 0 ' Boolean value
Symbol tmrset = 125 ' Setting for internal clock
Symbol FREQ_ON T1CON.0 ' enable timer1
OSCCON = %1111000 '32 MHz
Set APFCON.0 ' output on RA5 ( DS41413C-page 123)
CCP1CON = %00000010 ' setting Toggle mode (DS41413C-page 228)
T1CON = %00100000 ' timer1 set at 1:4 prescaler
CCPR1H = 255 ' preset for CCPR1 MSB register
CCPR1L = 206 ' preset for CCPR1 LSB register
Clear PORTA
Clear LATA ' LATCH off
Clear ANSELA ' no analog
OPTION_REG = %10000111 ' timer0 1:256 prescaler. Interrupt every 8 mSec
Set FREQ_ON ' start the frequency output
Set TMR0IE ' start timer0 interrupt
Set GIE ' start general interrupt
While 1 = 1
Wend
Having no 12F1822 I just tried a simulation, but it seems that is not giving more than 8 Hz.
I've searched for an answer about what it should do a Toggle mode, but nothing lead to a clear answer. There are bolgs that mention to obtain high frequencies, but the use to flip the port in a ISR (therefore the CCP1 is configured for interruption).
My question..... Is the Timer1 zeroed once the match has come?
I suppose that it should work as it does with ATmega328. There might be the same technology, after all.