RPM and period numbers per chip
Rpm 4620 877a
5000 15090 14999
6000 12575 12499
7000 10777 10712
8000 9430 9373
9000 8383 8331
10000 7545 7499
RPM and period numbers per chip
Rpm 4620 877a
5000 15090 14999
6000 12575 12499
7000 10777 10712
8000 9430 9373
9000 8383 8331
10000 7545 7499
Do you have another 18F type besides a 4620 you can test this on?
That would tell you if it's a hardware bug on the 4620. This part has
a massive list of errata & odd problems with ECCP, Timer1, Timer3,
and more.
I might have a 4520 floating around. Can you suggest a part number that will work with the boards I already have made? I will order it today if you have a suggestion.
A 4520 should drop right in, but this one also has a boat-load of errata for CCP, timer, and
a bunch more. I would test it if you already have one before buying another PIC.
The 18F4431 is my own personal favorite, and I also like the older 18F452. The drop-in
replacement (your 4520) for the 452 has way too many bugs.
Thanks it looks like a couple different config flags need to be changed to go with the 4431. The pinout appears to be the same.?.
It's the same pinout. It also has a lot of extra features.
But - I would try that 4520 if you can find it.
Where are you getting your PICs from? I have samples, and would be
more than willing to shoot you an 18F4431 if you cover postage.
Last edited by Bruce; - 28th January 2010 at 22:08.
I usually go through Mouser but I would rather spend money with you. Do you want to Paypal the freight? My paypal acct is [email protected].
I need a 44 pin TQFP
Shipping is
xBase
506 Park St
Sterling CO 80751
Hell with your 719 area code you can't be far anyway.
Thanks
Toby
I think you need to clear the timer sooner. (Immediately after capture).
The program goes through the whole conversion to RPM with multiplications and DIV32's before clearing the timer.
The 18F's multiply faster because they have a hardware multiplier.
So it clears the timer quicker and ends up with bigger numbers.
The 4620 numbers are closer to reality, but it's still wrong.
Clear the timer immediately after a capture and both chips should read the same numbers (or really close).
hth,
DT
Hi Darrel,
With both PICs running at 20MHz, CCPR1L & CCPR1H should have the same values - sinceCode:Start: If Capture = 0 then ' ignores 1st capture Goto Start endif T1CON.0=1 Capture = 0 CaptureLoop: If Capture = 0 then Goto CaptureLoop endif T1Con.0=0 period.LowByte=CCPR1L period.HighByte=CCPR1H
it's all done in hardware with the capture module capturing the value of timer1 after the
4 rising edges.
And the value being captured is before the multiply.
Yes the captured value is stored in CCPR1L:H, but the CCP module does not clear Timer1. You have to do that. And it's not being cleared until after the math.
Then it goes back up to Loop: and clears it again, without any reference to the incoming signal. (actually, it is referenced to the last capture plus math time).
If you only clear it once, immediately after the capture, then it will be ready for the next capture.
The first capture is always wrong, and must be discarded.
Added: I guess if Timer1 was Stopped in the ClearTimer1 routine (or at Loop: ), what you have would work better, but it will only capture every other 4-pulses. (8-pulses total)Code:Loop: TMR1H = 0 'Clear 8-bit register TMR1L = 0 'Clear 8-bit register capture = 0 'Clear Timer Start: If Capture = 0 then Goto Start endif T1CON.0=1 Capture = 0 CaptureLoop: If Capture = 0 then Goto CaptureLoop endif T1Con.0=0 period.LowByte=CCPR1L period.HighByte=CCPR1H RPM = 10000 RPM = RPM * RPM ' 100,000,000 RPM = DIV32 period ' 100,000,000 / RevCount RPM = RPM * 60 ' Per minute RPM = DIV32 400 RPM = (RPM*5) SEROUT2 LCD,84, [Prefix,CursorPS,20,"RPM ",dec5 RPM, " ", DEC CCPR1L, " ", dec CCPR1H] Gosub ClearTimer1 Goto Loop
Last edited by Darrel Taylor; - 28th January 2010 at 23:08. Reason: Added
DT
Oi vey,
I just saw ...
T1Con.0=0
Ignore what I just said, and I'm off to proteus to make sure before I open my mouth again.
![]()
DT
Cool. If I'm wrong, he gets a free PIC & you get the eBeer....
Like I said before, there could indeed be a timing difference between these points;
That would for sure be the cause.Code:T1CON.0=1 Capture = 0
Last edited by Bruce; - 29th January 2010 at 00:15.
Here is what I have now. I have set it up for every rising pulse and changed the math because when I incorporate this into my other code, waiting for four pulses delays alot of events.
Its still off with the output RPM numbers by the same percentage.
Code:DEFINE OSC 20 Prefix con $FE ' needed before each command LcdCls CON $51 ' clear LCD (use PAUSE 5 after) CursorPS con $45 'Cursor Position Capture VAR PIR1.2 ' CCP1 capture flag CCP1IF Overflow VAR PIR1.0 ' Timer1 overflow flag TMR1IF: RPM var word period var Word TotalTime var word 'Holds seconds and tics LCD VAR PortC.6 'LCD output Gate1 Var PortC.1 Gate2 var PortD.1 Gate3 var PortD.2 Gate4 var PortD.3 Gate5 var PortD.6 Gate6 var PortD.7 Gate7 var PortD.5 Gate8 var PortD.4 WOT var PortB.0 ADCON0 =0 'A/D Off ADCON1.3=1 'All AN channels digital ADCON1.2=1 ''' ADCON1.1=1 ''' ADCON1.0=1 ''' TRISE.0=1 'EO input TRISE.1=1 'E1 input CCP1CON = %00000101 ; Capture mode, every rising edge 0101 T1CON.7=1 'enable timer 16 bit ` T1CON.6=1 'Timer1 OSC T1CON.5=1 '1:4 prescaler T1CON.4=0 '1:4 prescaler T1CON.3=0 'Timer1 OSC off T1CON.2=0 'sychro clock T1CON.1=0 'internal clock T1CON.0=0 'stop timer pause 10 SEROUT2 LCD,84, [Prefix, LcdCls] Include "modedefs.bas" ' Mode definitions for Serout SEROUT2 LCD,84, [Prefix,CursorPS,0,"RPM test"] pause 500 TMR1H = 0 'Clear 8-bit register TMR1L = 0 'Clear 8-bit register capture = 0 'Clear Timer Calc_RPM_Timer: TMR1H = 0 'Clear 8-bit register TMR1L = 0 'Clear 8-bit register capture = 0 'Clear Timer StartRPM: If Capture = 0 then Goto StartRPM endif T1CON.0=1 Capture = 0 CaptureLoop: If Capture = 0 then Goto CaptureLoop endif T1Con.0=0 period.LowByte=CCPR1L period.HighByte=CCPR1H TMR1H = 0 TMR1L = 0 Capture = 0 Overflow = 0 RPM = 10000 RPM = RPM * RPM ' 100,000,000 RPM = DIV32 period ' 100,000,000 / RevCount RPM = RPM * 60 ' Per minute RPM = DIV32 1600 RPM = (RPM*5) SEROUT2 LCD,84, [Prefix,CursorPS,20,"RPM ",dec5 RPM] goto Calc_RPM_Timer return
Bookmarks