Hi Alain,
Thank you for your answer.
In the attachment are the code in PBP and a scheme in Proteus.
Please, May you see it?
I cannot interpret the numbers on LCD display.
Thank you again.
Hi Alain,
Thank you for your answer.
In the attachment are the code in PBP and a scheme in Proteus.
Please, May you see it?
I cannot interpret the numbers on LCD display.
Thank you again.
Hi, Vlad
@ 5 Hz ... period is 200 ms ... Timer1 has a 65536 µs range, so just can use a prescaler value of 4 ...
to read Timer1 ... better try :
Code:mainloop: If counter = 2 then T1CON.0 = 0 time.LowByte = TMR1L time.HighByte = TMR1H TMR1L = 0 TMR1H = 0 lcdout $FE, 1 lcdout $FE, $82, dec time, " " pause 300 counter = 0 endif Goto mainloop
note ,here, you only read the Pic Timer ... you have to add 2 times 65536 units ( timer overflows )
so, your count value is not good ...
200000 = 3.05 ... times 65536 ! AND overall you do not stop timer @ the end of the period ... but just when counter reaches value of 2 ...
so, doing it like you began to ...
1) TMR1 interrupt just has to increment the "counter" value
2) you must use another interrupt ( RB0 INT i.e.) to start or stop your timer1 ...
AND
3) ON Interrupt cannot be used for a precise timing measurement as it waits for the current PbP Command to complete ... so latency is variable, and overall ... far from negligible.
So, ....
Talking Frankly ... this way to measure pulses won't give satisfactory results ...
a ( much ) simpler way would be to try ...
and result will be Time X 10 µsecs ... I encourage you to read your relevant Manual chapters to understand what's happening with this short example ...Code:MeasLoop: Pulsin PortB.0,1,PulsHi RCTime PortB.0,0,Pulslo Time = PulsHi+PulsLo LCD Out $FE,$82, dec Time ' etc,etc ... Pause 500 Goto measLoop
You know what ??? pulse measurements with interrupts are not exactly the best way to begin learning PbP ...
Alain
************************************************** ***********************
Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
************************************************** ***********************
IF there is the word "Problem" in your question ...
certainly the answer is " RTFM " or " RTFDataSheet " !!!
*****************************************
Wonderful!!It seems very simple of the way that you indicate to me. I have proven it and works perfectly. The only problem that I see is that to very low frecuency (< 1Hz ) it value is erroneous and to high frequencies (> 1 kHz) the read value is erroneous too.
Thank you very very much Alain!!!!Code:pulsHi var word pulsLo var word Time var word MeasLoop: Pulsin PortB.0,1,PulsHi RCTime PortB.0,0,Pulslo Time = PulsHi+PulsLo LCDOut $FE,1, dec Time ' etc,etc ... Goto measLoop
Flavio
Last edited by xvladx; - 15th April 2010 at 21:47.
Alain
I can not understand the sense of RCTime. Why it is used?
Thanks a lot
ok ok, I undestood the usin of RCTime. I was read an old post yours.
The last question is...exists some process to measure to low frequencies lower than 0,8 Hz??
thank you
Ok, Vlad
Erroneous, erroneous ... you're joking, I hope !!! 2x10µs for a 1ms period is 2% ... use a 20 Mhz Xtal and it will be 2x2µs ... .4% !!!
The limitation is in maths involved.
You want a high precision wide range freq. meter ??? ... begin by considering your Xtals precision and The Pic Osc stability vs temp. ...
the only way is to use timers and interrupts ... with additionnal variables that extend timers range.
somewhat like you started with ...
but AT LEAST using Darrel's instant interrupts ... and probably the "N Bits maths" both from Darrel's goodies.
Alain
************************************************** ***********************
Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
************************************************** ***********************
IF there is the word "Problem" in your question ...
certainly the answer is " RTFM " or " RTFDataSheet " !!!
*****************************************
Alain
I call erroneous when the counter pass through 65535 and then the counter start again. When de width of pulse is too big I must to handler the final count.
Please be patient with me! I´m newbie!
Bookmarks