So I pretty much have my clock working but it is not working 1t 100% the way I want. I still seem to be getting an inconsistent RPM reading. Though it is vastly improved. Previous versions had much more shift of characters, I think do to the greater shift in RPM measurement. Part of that may have had to do with a sensor and or magnet that was poorly mounted tossing some vibration into the mix.
But the display is still not rock solid and would like to get some thoughts on trouble shooting this. I have vastly simplified my CCP interrupt code.
I calculate the rpm in the main loop and set up all of the interrupt times to turn on the LEDs. I am taking 16 samples before calculating the RPM and setting up the timers. For brevity I have excluded the code that setups up the LED time tables and bit map for the LEDs.
The video below shows what I mean. What is strange is the reading on the scope appears to be rock solid but if I do a measurement on the period, it does seem to be changing.
I am still getting a clicking that I solved once put had to disassemble The disk. I am wondering if that would cause the inconsistent RPM I might try to clear that up and see if if it fixes it.
Not real good at math. Does it look like that period change is consistent with the RPM change?
P.S. It is not near as nosily as it sounds in the video but it is there.
But the display is still not rock solid and would like to get some thoughts on trouble shooting this. I have vastly simplified my CCP interrupt code.
Code:
if (PIR4bits.CCP5IF == 1)
{
PIR4bits.CCP5IF = 0;
// Calculate ticks per revolution from Timer 1 capture
unsigned long thisCCPPeriod;
thisCCPPeriod = CCPR5H;
thisCCPPeriod = (thisCCPPeriod << 8) | CCPR5L;
ticksPerRev = (thisCCPPeriod - prevCCPPeriod);
prevCCPPeriod = thisCCPPeriod;
revTimeUpdated = 1;
totalOverflows=0;
// Setup Timer 3 to turn on the LED in Slot 0
T3CONbits.TMR3ON = 0; // Timer 3 off
frameCounter = 0;
TMR3H = (frameDelayTimes[frameCounter] >> 8);
TMR3L = (frameDelayTimes[frameCounter] & 0xFF);
ledsOn = 1;
T3CONbits.TMR3ON = 1; // Timer 3 on
}
I calculate the rpm in the main loop and set up all of the interrupt times to turn on the LEDs. I am taking 16 samples before calculating the RPM and setting up the timers. For brevity I have excluded the code that setups up the LED time tables and bit map for the LEDs.
Code:
INTCONbits.GIE = 0;
oldTicksPerRev = ticksPerRev;
revTimeUpdated = 0;
INTCONbits.GIE = 1;
totRotationTicks = totRotationTicks + oldTicksPerRev;
rotationTimesCount++;
if (rotationTimesCount >= MAXROTATIONTIMES)
{
rotationTimesCount = 0;
avgRotationTicks = totRotationTicks / MAXROTATIONTIMES;
totRotationTicks = 0;
ticksPerDegree = (float)(avgRotationTicks / 360.0);
float timePerRev = avgRotationTicks * 0.0000305;
rpm = (1 / timePerRev) * 60;
}
I am still getting a clicking that I solved once put had to disassemble The disk. I am wondering if that would cause the inconsistent RPM I might try to clear that up and see if if it fixes it.
Not real good at math. Does it look like that period change is consistent with the RPM change?
P.S. It is not near as nosily as it sounds in the video but it is there.
Last edited: