slyman
Joined: 02 Apr 2015 Posts: 5
|
pic16f877 - frequency counter |
Posted: Fri Apr 17, 2015 1:18 pm |
|
|
Hi everyone
I'm trying to measure line frequency.
Code: |
#include <16f877.h>
#use delay(clock=4000000)
#fuses XT,NOWDT
#USE TIMER(TIMER=1,TICK=1ms,BITS=8,NOISR) //1ms time count
#define use_portb_lcd TRUE
#include<lcd.c>
unsigned int8 simdiki_zaman, onceki_zaman=0,frekans,periyot ;
#int_timer0
void timer0_kesmesi()
{
set_timer0(255); // interrupt will take place at each rising edge
simdiki_zaman=get_ticks();
}
void main()
{
set_tris_a(0xff);
set_tris_b(0x00);
output_b(0x00);
lcd_init();
setup_timer_0(RTCC_EXT_L_TO_H | RTCC_DIV_1);
set_timer0 (255);
enable_interrupts(INT_timer0);
enable_interrupts(GLOBAL);
while(1)
{
frekans= 1/(simdiki_zaman-onceki_zaman); // f=1/T
onceki_zaman=simdiki_zaman;
printf(lcd_putc,"\f frekans=%uHz ",frekans);
delay_ms(100);
}
}
|
display values is:
frekans =0 |
|