Thanks, Dave. But that thread deals more with the display driving aspect rather than the speed measurement.
I just cant figure out the discrepancy in my reading using the capture command.
Anand
Thanks, Dave. But that thread deals more with the display driving aspect rather than the speed measurement.
I just cant figure out the discrepancy in my reading using the capture command.
Anand
well, I haven't go through the code, but internal OSC have it's own accuracy, I would compare with a real one first.
Next, how accurate your Frequency measure is? What are you using to measure it? That's pretty low frequency... pretty low frequency will add lots of count if not 100% spot on.
Try on higher frequency and see if the results are better.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Yes, I understand the internal oscillator wouldnt be extremely accurate. I did try it with a 4MHz external crystal, same readings.
The test source for square waves is a pic based instrument called 'Superprobe'; a great little instrument, the plans for which are available here: http://members.cox.net/berniekm/super.html
I did suspect the accuracy of the Superprobe, but checked it with a scope, and its spot on.
So, the issue boils down to my having messed up the capture code in some indeterminable way; or my understanding of the prescalers being totally off
The wrong results I get are very consistent for a given frequency. But, the ratio of observed readings to expected ones is not the same for different frequencies. Another mystery.
Anand
Last edited by ardhuru; - 20th May 2011 at 12:37.
Lets look at this and see what its doing:
You need to wait for a rasing edge before you start the counter, then on next rising edge, stop and get the counts. Or even better, set a word = to count, after you turn the timer off. then reset it and turn it back on. Right now you don't turn it back on until after you have sent data out. You are missing a portion of your signal this way.Code:INTCON = 0 ' Interrupts off CCP1CON = %00000101 ' Capture mode, capture on rising edge T1CON = 0 ' TMR1 prescale=4, clock=Fosc/4, TMR1=off T1CON.4 = 0 T1CON.5 = 1 CLEAR Reload: TMR1H = 0 ' Clear high byte of TMR1 counter TMR1L = 0 ' Clear low byte T1CON.0 = 1 ' Turn TMR1 on here 'here you turn on the timer, but at what state is your signal? Next you wait for capture flag, but again, if the flag sets on rising edge (or falling) but you started in the middle of a "high", you will stop when 75% of the cycle is done. Capture = 0 ' Clear capture int flag bit While !Capture ' Wait here until capture on rising edge Wend T1CON.0 = 0 ' Turn TMR1 off here ' Rising edge detected / stuff 'captured' Timer1 value in T1 T1.HighByte = CCPR1H ' I don't understand why you replace T1 count with CCPR1 T1.LowByte = CCPR1L 'T1 has the counts you are comparing in your spreadsheet DEBUG #T1,13,10 GOTO ReLoad
HTH
-Bert
The glass is not half full or half empty, Its twice as big as needed for the job!
http://foamcasualty.com/ - Warbird R/C scratch building with foam!
Bert, thanks for the insight.
I'm still trying to wrap my brain around what you suggested. Are you saying the Debug might be affecting the captured value?
Sorry I'm being so dense here.
Have a look at this document
http://ww1.microchip.com/downloads/e...doc/41214a.pdf
Last edited by mister_e; - 21st May 2011 at 10:21. Reason: Microchip's CCP Tips& Trick pdf
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Steve, thanks for that pointer. Things are very well explained indeed. Clarified some things, but am still not out of the woods yet.
Is my understanding correct here?
Slowest speed to be measured is 300 rpm. That is 5 Hz.
Maximum time to be measured between consecutive high going edges is therefore 200,000 us.
Therefore, T1, set to a prescaler of 1:4 should read 50,000 for a frequency of 5 Hz?
This is at clock frequency of 4 MHz, Capture configured to increment every rising edge.
Bookmarks