View previous topic :: View next topic |
Author |
Message |
ccowley
Joined: 12 Sep 2009 Posts: 19
|
Timer1 interrupt problem on 2424EP512GU810 |
Posted: Wed Jan 22, 2014 8:20 pm |
|
|
Does anyone know what I might be doing wrong? I can't seem to get the timer1 interrupt to do anything. My code receives data from a serial device I've called TAD. It also sends to it the main loop, but it won't send the character from the timer1 ISR. It works fine with an 8 bit micro, but not with this. I am assuming I am missing something simple, but everything I have tried has failed.
Thanks!
Code: | //Testcode.c
#include <Testcode.h>
char c = 'N';
int rcvFlag = 0;
int timeToSend = 38;
int pCountdown, fCountdown, cCountdown, gCountdown, hCountdown;
int silenceFlag=0;
#INT_TIMER1
void timer1_isr(void)
{
--timeToSend;
if (timeToSend == 0)
{
putc(0x43,TAD); //Send "C" to TAD
timeToSend = 38;
}
}
#INT_RDA
void rda_isr(void)
{
c = getc();
rcvFlag = 1;
}
void main()
{
setup_timer1(TMR_INTERNAL | TMR_DIV_BY_8, 40880); //32.704ms overflow
enable_interrupts(INTR_GLOBAL);
char setAlarm = 'N';
while(TRUE)
{
if (c == 'J')
{
c = 'N';
output_high (Out1);
output_high (Out2);
output_high (Out3);
output_high (Out4);
rcvFlag = 0;
//delay_ms (5000);
}
fputc ('D', TAD);
delay_ms (2000);
if (rcvFlag == 0)
{
output_low (Out1);
output_low (Out2);
output_low (Out3);
output_low (Out4);
}
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jan 23, 2014 2:16 am |
|
|
Your program isn't complete. You're not showing us everything, but it
appears that you left out enabling Timer1 interrupts. Example:
Code: |
enable_interrupts(INT_TIMER1); |
This is also required on an 8-bit PIC. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Thu Jan 23, 2014 4:50 am |
|
|
Also, a 'caveat' (we can't tell since you don't include the CPU clock details). Remember that on the PIC24, the peripheral clock, is normally OSC/2, while on the PIC18 it is OSC/4. Easy to miss difference....
Best Wishes |
|
|
ccowley
Joined: 12 Sep 2009 Posts: 19
|
|
Posted: Thu Jan 23, 2014 9:56 am |
|
|
Thank you! I had stared at and compared back and forth between the old 8 bit and the new code and for some reason I was not seeing it. You were right, it was the enable_interrupts(INT_TIMER1) I was overlooking. It works properly now.
I will double check on the clock. It's running at 20MHz. I went with the settings that the Setup Wizard suggested to keep the timing the same as it was on 8MHz 8 bit, which used the following settings:
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256|RTCC_8_bit); //32.7 ms overflow
Thanks again for the help! |
|
|
|