Hello, I have wired up a frequency meter using 89C4051.The signal is connected to P3.4/T0 pin.The circuit runs on 24MHz crystal.Can anyone give me the code of a frequency counter?Thanks in advance...
Completely unreadable! Post it formatted!
Hi, I have arranged the program in correct order.Please go through it and let me know the mistakes...
ISR PROGRAM ------------ void timer0_isr(void) {
while((tick--)!=0) timer0_isr_go(); TR1=0; TF1=0; TR0=TF0=0; LCD_command(0x01);
}
void timer0_isr_go(void) { TH0=0x3C; TL0=0xBA; }
void timer1_isr(void) { freq++; }
SUBROUTINE ---------------
void measure_freq() {
unsigned char xx2,xx1,xx0; while(1)
{
LCD_command(0x01);
TH0=0x3C;
TL0=0xBA;
tick=0x20;
freq=0;
TH1=0;
TL1=0;
TR0=TR1=1;
while(TF0!=0);
xx2=freq;
xx1=TH1;
xx0=TL1;
init_serial();
serial_data();
printf ("\nValue of XX2 : %d ",xx2);
printf ("\nValue of XX1 : %d ",xx1);
printf ("\nValue of XX0 : %d ",xx0);
} }
"I have arranged the program in correct order"
But you have not posted it using the correct tags - have you?!
Look at this picture: www.danlhenry.com/.../keil_code.png - it shows you that the instructions are really quite simple and very clearly stated.
without really looking at your scribbles (code has comments) I see this
you must be measuring and awfully low frequency.
Erik
"you must be measuring and awfully low frequency."
it depends on how low your "low" is.
you must be measuring and awfully low frequency." it depends on how low your "low" is.
actually, I was wrong, it should have been
"you must be measuring and awfully high frequency. do read the maximun clock rate for the T0 input"
I fail to see how the "high" or "low" limit would have anything to do with the particularly piece of code you were referencing, particularly when you are talking about T0 (when T1 is counting the pulses).
the code wouldn't work, but that's for other reasons.
if you can't see it in the 'code', forget it
"if you can't see it in the 'code', forget it"
sounds like you didn't understand why you objected to his code.
per listed out a fairly good approach to code this.
in general:
1) you will need to put a timer into its counter mode. in its isr, you will need to increment a variable to create a software multi-byte counter. for example, in this case, your TH1:TL1 form a 16-bit counter and freq:TH1:TL1 form a 32 bit counter if freq is a 16-bit type.
your frequency count is essentially freq:TH1:TL1 at end of the counting interval
2) you will need to put another timer into its timer mode. this timer will stop the counter mentioned above. depending on the frequency you are counting, you can use isr or no isr for this timer. and how long you set the interval to depends on the frequency you are counting.
that's pretty much all you need for this task. it is a very simple coding job.
} void timer1_isr(void) { freq++; }
will count for every 64k pulses\
"will count for every 64k pulses\"
yes. that's what freq is supposed to do: to be the high word in a multi-byte read consisting of freq:TH1:TL1.
the isr is the correct isr, even if the rest of the code didn't read TH1:TL1.
the isr portion of the code has nothing to do with the frequency being too high/low, or T0's maximum clock rate.
simply put, you didn't understand the code, or your objection to the code. the code may have other problems but the isr you objected to is doing the right thing.
@Ashley Madison,
Don't you ever get TIRED or nagging?
Jesus!!!! (sorry Jack Sprat)
even if the rest of the code didn't read TH1:TL1. even if there is no gas in my car I'm going to drive to the store
"even if the rest of the code didn't read TH1:TL1."
because the isr you objected to is correct, has nothing to do with T0's maximum clock rate.
"even if there is no gas in my car I'm going to drive to the store"
even if there is no gas in my car, your radio still works so your insistence on the radio not working is wrong.
hope that put it in the right perspective for you.
It sure does, others have tried to apply multiMegaHertz to a clock input and asked "why does it not work" I posted "do read the maximun clock rate for the T0 input"
BTW Jack Sprat, it is nice you came out of the closet.
BTW It is, by now, in my opinion proven that Jack/Ashley is a professional nitpicker