Hi All,
Well, the count didn’t work as expected, seems the count function will only work for >100-150 rpm measurements, :-(. Even an event measured in 1 second, multiplied out the LCD reads it as 60rpm, ;-(
So far my code is as follows:
I have left in the timer interupt running as it shows that the pic is running for now.Code:INCLUDE "DT_INTS-14.bas" ' Base Interrupt System INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts INCLUDE "Elapsed_INT.bas" ' Elapsed Timer Routines DEFINE OSC 4 '4 MHz Osc DEFINE LCD_COMMANDUS 2000 DEFINE ADC_BITS 10 DEFINE ADC_CLOCK 3 DEFINE ADC_SAMPLEUS 10 T1CON = %00000000 '1:1 Prescaler TMR1H = 0 ;Clear registers TMR1L = 0 TRISB = %00000001 'Set PortB.0 as input for Hall sensor ADCON0 = %11100001 ADCON1 = %10000000 'Right Justify, VDD as vref Hall var word 'VAR for hall sensor Period var word P1 var word W2 var word ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler INT_INT, _HallCount, PBP, yes ; INT_Handler TMR0_INT, _TimePeriod, PBP, yes INT_Handler TMR1_INT, _ClockCount, PBP, yes endm INT_CREATE ; Creates the interrupt processor ENDASM OPTION_REG = OPTION_REG & $80 | 1 ; Set TMR0 Prescaler to 256, leave RBPU alone @ INT_ENABLE INT_INT ; enable external (INT) interrupts '@ INT_ENABLE TMR0_INT ; enable Timer 0 interrupts @ INT_ENABLE TMR1_INT ; Enable Timer 1 Interrupts wsave VAR BYTE $20 SYSTEM ' location for W if in bank0 'wsave VAR BYTE $70 SYSTEM ' alternate save location for W GOSUB ResetTime ' Reset Time to 0d-00:00:00.00 GOSUB StartTimer ' Start the Elapsed Timer Main: IF SecondsChanged = 1 THEN SecondsChanged = 0 LCDOUT $FE,$C0, DEC Days,"d-",DEC2 Hours,":",DEC2 Minutes,":",DEC2 Seconds ENDIF LCDOut $FE, $80, "Period = ", DEC P1 DIG 3, DEC P1 DIG 2, dec P1 dig 3 GOTO Main '---[INT - interrupt]--------------------------------------------------- HallCount: @ bcf T1CON,TMR1ON ; Switch off timer period.lowbyte = TMR1L 'Record Result period.highbyte = TMR1H @ clrf TMR1H ; Reset registers to zero @ clrf TMR1L @ bsf T1CON,TMR1ON ;Start timer period = (period / 5) * 2 'Gives period value in microseconds p1 = period @ INT_RETURN
The output to the LCD now changes depending on the speed of the rotations, however I'm not sure if my prescaler is setup right (4mhz osc) and if the calc to get the microseconds is correct for my osc (thanks BobEdge).




Bookmarks