|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
Freq.-counter: using rtcc and timer1 |
Posted: Wed Apr 05, 2006 4:39 am |
|
|
Hello,
I am trying to measure the freq on rb4 with the rtcc, while the timer1 is in use (500ms). But at least their doesn't occor either the rtcc interrupt nor the timer1 interrupt. I'm really frustrated.
First I have tried the final measure with a delay, but it didn't work either.
What am I doing wrong?
Please help!!
Code: | #include <16f876.h>
#device ICD=TRUE
#device ADC=10
#fuses HS,NOWDT,NOPROTECT,PUT,NOBROWNOUT,NOLVP,NOCPD,WRT
#USE DELAY (clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, parity=n, bits=8, force_sw, invert)
//#include <lcd_n.c>
int32 count;
int32 teiler;
int32 sol;
int16 overflow=0;
int8 timer=0;
#priority rtcc,timer2
#int_timer2
time_interrupt()
{
timer++;
}
#int_RTCC
rtcc_isr() //Interrupt-Routine
{
overflow++;
}
void init()
{
//lcd_init();
setup_timer_0 (RTCC_DIV_1|RTCC_EXT_L_TO_H);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DIV_BY_4,255,10);
enable_interrupts(INT_RTCC);
enable_interrupts(INT_TIMER2);
enable_interrupts(GLOBAL);
}
void main()
{
init();
while(1)
{
//measure for prescaler:
setup_counters(RTCC_EXT_L_TO_H,RTCC_DIV_256);
set_rtcc(0);
delay_us(256);
count=get_rtcc();
printf("Grob: %lu",count);
//prescaler:
setup_counters(RTCC_EXT_L_TO_H,RTCC_DIV_2);
teiler=2;
If (count>=4)
{
setup_counters(RTCC_EXT_L_TO_H,RTCC_DIV_4);
teiler=4;
}
If (count>=8)
{
setup_counters(RTCC_EXT_L_TO_H,RTCC_DIV_8);
teiler=8;
}
If (count>=16)
{
setup_counters(RTCC_EXT_L_TO_H,RTCC_DIV_16);
teiler=16;
}
If (count>=32)
{
setup_counters(RTCC_EXT_L_TO_H,RTCC_DIV_32);
teiler=32;
}
//detailed measure:
sol=0;
count=0;
overflow=0;
set_rtcc(0);
set_timer2(0);
clear_interrupt(INT_RTCC);
clear_interrupt(INT_TIMER2);
enable_interrupts(INT_RTCC);
enable_interrupts(INT_TIMER2);
do
{
printf("timer: %U",timer);
} while (timer<250);
count=get_rtcc();
//calculation and output:
sol=2*(int32)teiler*((int32)count+overflow*256);
printf("Frequ: %lu",sol);
printf("Overf: %lu",overflow);
}
}
|
|
|
|
Guest
|
|
Posted: Wed Apr 05, 2006 6:49 am |
|
|
Would be great if anybody could help me... |
|
|
mpfj
Joined: 09 Sep 2003 Posts: 95 Location: UK
|
|
Posted: Wed Apr 05, 2006 7:27 am |
|
|
I don't have a 16F876, but your code appears to work on my 18F8720 demo board.
I would suggest you try something a bit simpler, i.e. setup *just* the timer interrupt or *just* the RTCC interrupt and see if they work ... e.g.
Code: | #include <16f876.h>
#device ICD=TRUE
#fuses HS,NOWDT,NOPROTECT,PUT,NOBROWNOUT,NOLVP,NOCPD,WRT
#use DELAY (clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, parity=n, bits=8)
int8 timer = 0;
#int_timer2
void timer_interrupt(void) {
timer++;
}
void main(void) {
setup_timer_2(T2_DIV_BY_4,255,10);
set_timer2(0);
clear_interrupt(INT_TIMER2);
enable_interrupts(INT_TIMER2);
enable_interrupts(GLOBAL);
while (1) {
printf("timer: %U", timer);
}
} |
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|