I have a problem using the timer1 and timer2 as a counter

General discussion on mikroC PRO for PIC32.
Post Reply
Author
Message
fadi albaghdadi
Posts: 3
Joined: 28 Aug 2019 12:11

I have a problem using the timer1 and timer2 as a counter

#1 Post by fadi albaghdadi » 18 Sep 2019 17:22

void Timer2_interrupt() iv IVT_TIMER_2 ilevel 7 ics ICS_SRS {
if(T2IF_bit==1) {
LATb = ~ PORTb; // Invert PORTB
T2IF_bit = 0;
}
}

void InitTimer2(){

ON__T2CON_bit = 0; // Enable Timer1
TCS_bit =0;
TCKPS0_bit = 0; // Set Timer Input Clock
TCKPS1_bit = 0; // Prescale value to 1:256
TMR2 = 0;
PR2 = 65535;
T2IF_bit = 0;
T2IP0_bit = 1; // set interrupt
T2IP1_bit = 1; // priority
T2IP2_bit = 1; // to 7
T2IE_bit = 1; // Enable Timer1 Interrupt
ON__T2CON_bit = 1; // Enable Timer1

EnableInterrupts(); // Enable all interrupts
}

void main() {
AD1PCFG = 0xFFFF; // Initialize AN pins as digital
TRISb = 0; // initialize PORTB as output
LATb = 0xffff; // Initialize PORTB value
InitTimer2();

while(1){
if (TMR2 >=5) {
//LATb = ~ PORTb; // Invert PORTB

}else
{
//LATb = ~ PORTb;
}
}
}

User avatar
jovana.medakovic
mikroElektronika team
Posts: 986
Joined: 18 Dec 2018 10:36

Re: I have a problem using the timer1 and timer2 as a counte

#2 Post by jovana.medakovic » 19 Sep 2019 11:41

Hello,

Can you zip and send me your code for review?

Kind regards,
Jovana

Post Reply

Return to “mikroC PRO for PIC32 General”