We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I was thinking whether its feasible to use a 8-bit counter with auto-reload to capture the number of peaks detected within 100ms.
I see. So i have to run the timer for some time(lets say 3 sec) and whenever theres a high-to-low transition, the timer will capture the high-to-low transition and stores the position in TL2 and TH2?
And from TH2 and TL2, how do i find out the time?
"to be loaded into the capture registers (RCAP2H, RCAP2L"
If you had a normal clock ticking one step every ms, and you have the ability to now and then capture a value - how would you then figure out how long time have passed?
I'll use the bit "C/T2" and uses the system clock divided by 12.
How do i set my timer to one milliseconds ticks?
My processor is 25Mhz...
So i use the formula:
1/12 * 25 = 2.083us
I know from this that each step from the timer is 2.083us.
I know how to configure the timer already. Whenever theres is a pulse, an interrupts will occurs and copy the values of RCAP2H and RCAP2L. But i do not know how to make it such that when it recorded 4 pulses, it will stop and later loop back again. I know i have to use the DJNZ instruction, but where do i put the DJNZ instruction?
Can someone pls advice me on what to do?
If you are not comfortable with assembler, maybe you should do it in C.
Yea.. i was thinking of doint the math routine in C. But how do i call a C function from asm?
"how do i call a C function from asm?"
http://www.keil.com/support/man/docs/c51/c51_ap_ctoasm.htm
I see... thanks.. I just found out that my ocillator is running a 2Mhz. Which is 6us per tick. Do i have to add an external crystal of 1Khz to get 1ms per tick?
Wrong.. shld be 12Khz crystal... Isit available in the market?
"should be 12Khz crystal"
No. That should be 12kHz - the upper & lower case matter - see www.8052.com/.../read.phtml
I see... isit available in the market? Because all i see is in Mhz...
If you have hardware that: - always divides the crystal frequency with 12 - and there is no prescaler support - and you need the timer to tick at 1ms then you would need a 12kHz crystal.
However, most timers have a large set of options for specifying a frequency, and for setting up how it is expected to be run. That may include support for different clock sources, use of prescalers etc.
If you want to generate interrupts everh 1ms, then you figure out how many ticks the timer need to tick until 1ms has passed, given the frequency that your timer steps with.
In this case, you are going to measure the time between heart beats. You only need a calibrated time. It isn't important if your timing manges to measure time with higher resolution than required, as long as you make sure that you know about any timer overflows.
If the timer doesn't tick at 1ms, then it's enough to know exactly what speed it runs in, to allow you to multiply/divide the results you get with whatever scale factor is needed to convert the time into seconds, milliseconds or whatever you want.
As suggested earlier, measure he time it takes to capture a fixed number of pulse events. If you use the capture registers to pick up the values from the free-running timer, all you need to do is figure out exactly how many ticks the timer has stepped during these heartbeat intervals. If it ticks at 1MHz, then obviously every tick is worth 1us. If it ticks at 200kHz, then every tick is worth 5us, ...
Use whatever prescaler options you have to initialize the timer, and use that precision for the timing.
One question. I know that my hardware always divide the crystal frequency by 12. But what do you mean by prescaler support?
Isit a function where you can choose the frequency that you want to run at?