I am trying to make a speedometer cum odometer. I'm using a PIC based MCU. The speed I'm getting is as an analog input. (at 0V, I get 0 Km/hr and at 25V, I get 25Km/hr). I can easily measure the speed using the ADC conversion. The issue I'm facing is how do I measure the distance here. Does anyone have any ideas for the same?
One thing I can think of is having a delay of 100ms in the code and multiplying the instantaneous speed by 100mS. Since all other function execution should take a maximum of 1-5mS (including ADC conversion and sending bits to LCD displays etc), I can neglect that time and consider the distance here. But this method is not very exact. Does anyone have a better solution?
PFA the basic code
currentSpeedVoltage = ADC_Read(9);
currentSpeedVoltage = (currentSpeedVoltage * 0.001220703125); //(0.001220703125 = 5/4096) (12 bit resolution for ADC)
currentSpeed = (currentSpeedVoltage*25)/18; // assumed here that at 18 Volts, we show the speed as 25 Km/hr.
distance += (currentSpeedx100x5*(pow(10,-5))/18)/1000;
One thing I can think of is having a delay of 100ms in the code and multiplying the instantaneous speed by 100mS. Since all other function execution should take a maximum of 1-5mS (including ADC conversion and sending bits to LCD displays etc), I can neglect that time and consider the distance here. But this method is not very exact. Does anyone have a better solution?
PFA the basic code
currentSpeedVoltage = ADC_Read(9);
currentSpeedVoltage = (currentSpeedVoltage * 0.001220703125); //(0.001220703125 = 5/4096) (12 bit resolution for ADC)
currentSpeed = (currentSpeedVoltage*25)/18; // assumed here that at 18 Volts, we show the speed as 25 Km/hr.
distance += (currentSpeedx100x5*(pow(10,-5))/18)/1000;