Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Using Timer Register Value for PWM pulse width

Status
Not open for further replies.

faysal_002299

New Member
Dear all,
I am using the following code for calculating the pulse width of a PWM. But can't come up with any result. Please help me.
_________________________________________________________________

// initialization of Timer3. Timer3 will be used for calculating the time for a number of pulses
void InitTMR3(void)
{
T3CON = 0x0030; // internal Tcy/256 clock
TMR3 = 0;
PR3 = 0x8000;
return;
}

// INT2 for capturing the input PWM. May be I can replace this with IC or CN pins
void __attribute__((__interrupt__)) _INT2Interrupt(void)
{
Count=Count + 1; // Counting every positive edge of the PWM
if (Count>60) // I want to count the time for every 60 pulses
{
SendData(TMR3); // SendData function sends information to host PC
TMR3 = 0; // Again start counting from beginning after every 60 pulses
Count=0; // Start counting again after every 60 pulses
}
IFS1bits.INT2IF=0; //clear INT2 interrupt flag
}
_________________________________________________________________

I am confused about the TMR3 as I am not getting any value from it. Isn't it suppose to work as a counter? If anybody know any alternative solution I would be grateful. For any further question please ask me.

with thanks
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top