News:

;) This forum is the property of Proton software developers

Main Menu

Timer 1 with 33FJ12GP202

Started by Wimax, May 01, 2022, 07:01 PM

Previous topic - Next topic

Wimax

I am experiencing a problem with Timer1 with the 33FJ12GP202.
It works as expected if I don't include some instructions related to the A/D converter in the code.
This code works as expected (LED3 blinks periodically thanks to the Timer1 interrupt):

Device=33FJ12GP202

Declare Xtal= 39.6288

PLL_Setup(43, 2, 4, $0300)   ' Device @ 39.6288 MHz
Config FBS = BWRP_WRPROTECT_OFF
Config FGS = GWRP_OFF
Config FOSCSEL = FNOSC_PRIPLL, IESO_ON
Config FOSC = POSCMD_XT, IOL1WAY_OFF, FCKSM_CSECME
Config FWDT = WDTPOST_PS256, WINDIS_OFF, FWDTEN_OFF
Config FPOR = FPWRT_PWR128, ALTI2C_OFF
Config FICD = ICS_PGD1, JTAGEN_OFF


Declare Adin_Tad = cFRC ' RC oscillator chosen
Declare Adin_Stime = 50 ' Allow 50us sample time
Declare I2C_Slow_Bus 1  ' Slow down I2C bus

Include "PWM_33_Max.inc"                      ' Load the Hardware PWM procedures into the program
Declare CCP1_Pin PORTB.7
Declare CCP2_Pin PORTB.10
PPS_Output(cOut_Pin_RP7, cOut_Fn_OC1)   ' Make RP7(RB7) the pin for  PWM1
PPS_Output(cOut_Pin_RP10,cOut_Fn_OC2)   ' Make RP10(RB10) the pin for  PWM2

'AD1CON2 = 0 ' AVdd, AVss, MUXA only
'AD1PCFGL = 5 ' Analogue input on pin AN5

Symbol LED = PORTB.15 ' Alias the LED
Symbol LED2= PORTB.14 ' Alias the LED 2
Symbol LED3= PORTB.13 ' Alias the LED 3

GoTo Inizio

Isr- T1Interrupt ' Context save
Toggle LED3
IFS0bits_T1IF = 0 ' Reset the Timer1 interrupt flag
EndIsr- ' Context restore and exit the interrupt

Inizio:

High LED
High LED2
High LED3


TMR1 = 0
T1CON = %1000000000100000 ' Start Timer1
PR1 = 61920 ' Load Timer1 period
' Discontinue operation in Idle mode
' Gated time accumulation disabled
' 1:64 prescaler
' Do not synchronise external clock input
' Internal clock
IFS0bits_T1IF = 0 ' Clear Timer1 interrupt flag
IPC0bits_T1IP0 = 0 ' Set priority
IEC0bits_T1IE = 1 ' Enable the Timer1 interrupt


DelayMS 1000

Main:

DelayMS 1      ' Do nothing...

GoTo Main

if I add these two lines for the A/D :

AD1CON2 = 0 ' AVdd, AVss, MUXA only
AD1PCFGL = 5 ' Analogue input on pin AN5

It doesn't works.

What am i doing wrong? The instructions for the A/D are necessary as I need to use the device.... . Why does enabling block operation ? I also tried reversing the order by moving the istructions after the interrupt enable, but it still doesn't work.

Wimax

When will I learn to read a datasheet correctly ?   ::)  ;D To correctly select the ANx port as analog input, the corresponding bit must be set to ZERO !
It was sufficient to write AD1PCFGL = 0xFFDF and now it performs very well !