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...
"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
Erik
"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
because the isr you objected to is correct, no, it is not, the name is "freq" not "MSB_of_freq"
now nitpick about variable names
"no, it is not, the name is "freq" not "MSB_of_freq""
so if your objection were about the name of that variable, why did you object to the isr or ask him to look at T0's maximum clock rate? how are they related?
"now nitpick about variable names"
whenever you see people picking on trivial things like this, you know that they have run out of legit arguments.
except that your mistakes aren't trivial: you insisted that a correct piece of code is wrong, and you ask him looking into T0's maximum clock rate when it has nothing to do with what he is trying to do.
in the end, you "justified" all of this on him not naming the variable in a way that you can understand.
you will get more respect if you simply admit to your errors. trying to justify your way out of an obvious mistake is just silly.
you insisted that a correct piece of code is wrong
And you've demonstrated several times over since you popped in here that you don't know a thing about distinguishing a correct piece of code from a bad one.
you will get more respect if
You're grossly mistaken if you think that you, of all people, are the person who should be giving others advice about how to gain respect. If you knew how to do that, you'ld have at least managed to gain some yourself. Guess what: you didn't.