View previous topic :: View next topic |
Author |
Message |
Guest Who Needs Help Guest
|
Timer1 as a 32bit counter |
Posted: Wed Jan 21, 2004 9:26 am |
|
|
Can someone help me out with getting a 32bit value from Timer1? I thought this would work, but I am getting odd results:
Code: |
int16 high16_counter;
int32 last_counter;
#int_TIMER1
TIMER1_isr() {
high16_counter++;
}
int1 got_half_sample;
int1 got_sample;
void stop_scanning(void) {
disable_interrupts(INT_EXT);
disable_interrupts(INT_TIMER1);
}
void start_scanning(void) {
setup_timer_1(T1_DISABLED);
got_half_sample=FALSE;
got_sample=FALSE;
enable_interrupts(INT_EXT);
}
#int_EXT
EXT_isr2() {
if (got_half_sample) {
setup_timer_1(T1_DISABLED);
disable_interrupts(INT_TIMER1);
if (TMR1F) {high16_counter++;}
TMR1F=0;
disable_interrupts(int_EXT);
got_sample=TRUE;
last_counter=make32(high16_counter,get_timer1());
}
else {
setup_timer_1(T1_DISABLED);
set_timer1(0);
T1CON=0x01; //setup_timer_1 ( T1_INTERNAL | T1_DIV_BY_1 );
TMR1F=0;
high16_counter=0;
enable_interrupts(INT_TIMER1);
got_half_sample=TRUE;
}
}
|
Basically I want to count the number of cycles between pulses on B0. I call start_scanning() when I want a new 32bit value, and then wait until got_sample is true. First, it doesn't look like int_Timer1 is triggering because the high16 counter never increments. Second, the low 16bit values are never the same (way off) between samples even though the frequency into B0 is steady.
Thanks for any help you can provide. |
|
|
Guest Who Needs Help Guest
|
|
Posted: Wed Jan 21, 2004 9:28 am |
|
|
I forgot to mention that this is for a PIC16C926, and that I am using various versions of PCM (3.182 mostly) |
|
|
Guest
|
|
Posted: Wed Jan 21, 2004 6:36 pm |
|
|
Wow, no one wanted to help.
I figured it out, I had to clear the int_ext interrupt flag before enable int_ext interrupts in start_scanning(). Else as soon as I enabled the interrupt it would service it, and then the counter not setup correctly. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jan 21, 2004 6:57 pm |
|
|
It's not that no one wanted to help.
Sometimes, the people who regularly post replies on here
are extremely busy at their companies. It's like that for
me today. I have got to get this board layout done. |
|
|
NEWBOY
Joined: 19 Dec 2003 Posts: 9
|
|
Posted: Tue Jan 27, 2004 2:31 pm |
|
|
Hi
Did your program for the 32 bit counter for Timer1 work
As a learner in C could you be kind enough to explain it to me.
i am thinking of using it with a few MODS on the 18F452 to count a master clock at 40mHz
Santana |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Tue Jan 27, 2004 4:28 pm |
|
|
Start with this . No time to test it !!
Code: |
int16 high16_counter;
int16 low16_counter;
int32 last_counter;
#int_TIMER1
TIMER1_isr()
{
low16_counter = get_timer1();
if(!low16_counter)
{
high16_counter++;
}
}
#int_EXT
EXT_isr2()
{
set_timer_1(1);
enable_interrupts(INT_TIMER1);
edge_count++;
}
main()
{
setup_timer_1 ( T1_INTERNAL | T1_DIV_BY_1 );
enable_interrupts(GLOBAL);
while(1)
{
if(!edge_count)
{
ext_int_edge( H_TO_L );
enable_interrupts(INT_EXT);
}
else
{
if(edge_count == 1)
{
ext_int_edge( L_TO_H );
}
if(edge_count == 2)
{
disable_interrupts(INT_EXT);
disable_interrupts(INT_TIMER1);
last_counter=make32(high16_counter,low16_counter);
edge_count = 0;
delay_ms(500);
printf("\r\nPulses %4X %4X", high16_counter,low16_counter);
}
}
}
}
|
hope this help you,
Humberto |
|
|
NEWBOY
Joined: 19 Dec 2003 Posts: 9
|
|
Posted: Thu Jan 29, 2004 3:38 pm |
|
|
It did help
Thank you very much
Santana |
|
|
|