CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

pic16f877 - frequency counter

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
slyman



Joined: 02 Apr 2015
Posts: 5

View user's profile Send private message

pic16f877 - frequency counter
PostPosted: Fri Apr 17, 2015 1:18 pm     Reply with quote

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
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Fri Apr 17, 2015 2:19 pm     Reply with quote

Please start by explaining how you think your code achieves its objective.

Mike
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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