You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When the speed reaches 4r/s (4 * 2.2 * 3.6 = 31.68 km/h), the interval measured by TIM3 is (1/f)/[1/(64M/7814)] = 8190/f = 8190/4 = 2048; the value in EBiCS is [(int)2200 / ((int)2048 >> 3)] * 36 / 10 = 28.8, nearly 2 km/h error produced.
you can draw two functions in the calculator
y = 2.2*3.6*x
y = 3.6*floor(2200/floor(8190/x/8))
to see the maximum error 4.3 km/h. 29 km/h will be shown as 25 km/h!
I have extracted related code from your project (with many unindented code):
int main(void)
{
...
while (1)
{
...
// SPEED signal processing
if (ui8_SPEED_flag) {
if(uint32_SPEED_counter > 200) { //debounce
MS.Speed = uint32_SPEED_counter;
uint32_SPEED_counter = 0;
ui8_SPEED_flag = 0;
}
}
...
if (ui32_tim3_counter > 500) {
if(uint32_SPEED_counter > 127999)
MS.Speed = 128000;
...
ui8_slowloop_counter++;
if (ui8_slowloop_counter > 3) {
ui8_slowloop_counter = 0;
send_ant_page(0, &MS, &MP);
}
ui32_tim3_counter = 0;
}
...
}
}
// elapse frequency of TIM3 is 64M/7814 (Hz), interval is about 122.1 us
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if (htim == &htim3) {
if(ui32_tim3_counter < 32000)
ui32_tim3_counter++;
...
if (uint32_SPEED_counter < 128000)
uint32_SPEED_counter++; //counter for external Speed sensor
}
}
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
...
//Speed processing
if(GPIO_Pin == Speed_EXTI5_Pin)
ui8_SPEED_flag = 1; //with debounce
}
void send_ant_page(uint8_t page, MotorState_t* MS, MotorParams_t* MP)
{
...
// *3,6 for km/h then *10 for LEV standard definition.
uint16_t speedx10 = MP->wheel_cirumference / ((MS->Speed*MP->pulses_per_revolution) >> 3) * 36;
ui8_tx_buffer[9] = speedx10 & 0xFF; //low byte of speed
ui8_tx_buffer[10] = speedx10>>8 & 0x07; //lower 3 Bytes(needs correction) of high byte
...
HAL_UART_Transmit_DMA(&huart1, (uint8_t *)&ui8_tx_buffer, 12);
}
Thanks.
The text was updated successfully, but these errors were encountered:
In case of 2.2 m of wheel circumference, single magnet in the spokes:
When the speed reaches 4r/s (4 * 2.2 * 3.6 = 31.68 km/h), the interval measured by TIM3 is (1/f)/[1/(64M/7814)] = 8190/f = 8190/4 = 2048; the value in EBiCS is [(int)2200 / ((int)2048 >> 3)] * 36 / 10 = 28.8, nearly 2 km/h error produced.
you can draw two functions in the calculator
to see the maximum error 4.3 km/h. 29 km/h will be shown as 25 km/h!
I have extracted related code from your project (with many unindented code):
Thanks.
The text was updated successfully, but these errors were encountered: