??? 01/03/12 11:28 Read: times |
#185285 - frequency counter Responding to: ???'s previous message |
i am sorry for las post.
i need to tell that no any problem in hardware. when i give input by 555 timer at p3.4 it is not displaying that frquency which i give input. as example when input frequency is 120khz then out put is 222khz and when input frequency is 960khz then out out is 1288khz. sir as i think the problem is that wrong measure of duration of 1 cycle. so plz /*******************************************/ /* Frequency Counter With */ /* 89s52 + 4094 */ /*******************************************/ #include <REGX52.H> #include <math.h> sbit CLK = P1^1; sbit DIN = P1^0; sbit strobe = P1^2; sbit key = P3^2; unsigned int calc_del; unsigned char scale =6; unsigned char buffer[4],dig[4]; float sample[5]; unsigned long f; unsigned char segment[10]={0x40,0xF9,0x24,0x30,0x19,0x12,0x02,0xF8,0x00,0x10}; unsigned char a,b,c,d,e; void delay(y){ unsigned int i; for(i=0;i<y;i++){;} } void int_to_digits(unsigned long number) //store the digits of an integer number in the variable a,b,c,d { float itd_a,itd_b,itd_c,itd_d,itd_e; itd_a = itd_a = number / 10.0; dig[3] = floor((modf(itd_a,&itd_b)* 10)); itd_b = itd_b / 10.0; dig[2] = floor((modf(itd_b,&itd_c)* 10)); itd_c = itd_c / 10.0; dig[1] = floor((modf(itd_c,&itd_d)* 10)); itd_d = itd_d / 10.0; dig[0] = floor((modf(itd_d,&itd_e)* 10)); } void count_pulses() interrupt 1 //counter 0 interrupt { if (scale < 200) scale++; //ex_pulses++; } void write_led() { char i,j; for(j=0;j<4;j++) { for(i=0;i<8; i++) { if(buffer[j]&0x80) DIN = 1; else DIN=0; CLK= 1; buffer[j] <<=1; CLK = 0; } } strobe = 1; ; strobe = 0; } void move_Buffer() { buffer[3] = segment[dig[0]]; buffer[2] = segment[dig[1]]; buffer[1] = segment[dig[2]]; buffer[0] = segment[dig[3]]; } void reset() // reset display { if( key == 0) { f=0; } } void main() { EA = 1; EX0 = 0; EX1 = 0; ET0 = 1; //Enable the Timer/counter 0 interrupt TR0 = 1; //Enable Timer/counter 0 to count TMOD = 0x25; //counter 0 in mode 1 (16 bit counter) , timer 1 in mode 2 (auto reload from TH1) TL0 = 0; //empty the counting registers TH0 = 0; //empty the counting registers TH1 = 100; //start timer 1 from 0 ET1 = 1; //enable timer 1 interrrupt TR1 = 1; //Enable Timer/counter 1 to count PT0 = 1; PT1 = 0; while(1) { calc_del++; if (calc_del > (2248/scale)) // update data { calc_del = 0; f = (TL0 +TH0*256); sample[4] = sample[0] ; sample[3] = sample[1] ; sample[2] = sample[2] ; sample[1] = sample[3] ; sample[0] = f; { TL0=0; TH0=0; if (TH0 < 10) { if (scale > 9) { scale--; } } } f = floor((sample[0]+sample[1]+sample[2]+sample[3]+sample[4])/5)*scale; // calculate the average of 5 readings reset(); int_to_digits(f); move_Buffer(); write_led(); delay(20); } } } thanks anil kumar |
Topic | Author | Date |
frequency counter | 01/01/70 00:00 | |
Care for details | 01/01/70 00:00 | |
frequency counter | 01/01/70 00:00 | |
Still not correctly posted code. Still arbitrary floats... | 01/01/70 00:00 | |
Check some small things | 01/01/70 00:00 | |
typical | 01/01/70 00:00 | |
what a mess | 01/01/70 00:00 |