|
|
|
|
@ -3,8 +3,8 @@
|
|
|
|
|
#include "roller_speed.h"
|
|
|
|
|
#include "io.h"
|
|
|
|
|
|
|
|
|
|
#include "freertos/FreeRTOS.h"
|
|
|
|
|
#include "driver/mcpwm.h"
|
|
|
|
|
#include "freertos/FreeRTOS.h"
|
|
|
|
|
#include "freertos/queue.h"
|
|
|
|
|
#include "soc/rtc.h"
|
|
|
|
|
|
|
|
|
|
@ -50,17 +50,19 @@ static bool speed_pulse_isr_handler(mcpwm_unit_t mcpwm, mcpwm_capture_channel_id
|
|
|
|
|
int64_t time_now;
|
|
|
|
|
|
|
|
|
|
time_now = esp_timer_get_time();
|
|
|
|
|
new_measurement.timestamp = time_now;
|
|
|
|
|
new_measurement.pulses = roller_pulses[r_id];
|
|
|
|
|
// Just make sure we have a previous edge to compare to, and that it was no more than ZERO_SPEED_TIMEOUT_US ago
|
|
|
|
|
if ((roller_last_timestamp[r_id] != 0) and ((time_now - roller_last_timestamp[r_id]) < ZERO_SPEED_TIMEOUT_US)) {
|
|
|
|
|
new_measurement.timestamp = time_now;
|
|
|
|
|
new_measurement.period = edata->cap_value - roller_last_edge_time[r_id];
|
|
|
|
|
// Technically passing the roller pulses with the rest of the measurement here means that it won't be updated
|
|
|
|
|
// for the first pulse detected after being stopped, but for the purposes of tracking total revs in a given
|
|
|
|
|
// period of several seconds this shouldn't matter.
|
|
|
|
|
new_measurement.pulses = roller_pulses[r_id];
|
|
|
|
|
xQueueOverwriteFromISR(roller_measurement_queue[r_id], &new_measurement, &high_task_wakeup);
|
|
|
|
|
} else {
|
|
|
|
|
// If there's no previous edge detected, or it's too far away, we still want to give an update with the new
|
|
|
|
|
// pulse count
|
|
|
|
|
new_measurement.period = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
xQueueOverwriteFromISR(roller_measurement_queue[r_id], &new_measurement, &high_task_wakeup);
|
|
|
|
|
|
|
|
|
|
roller_last_edge_time[r_id] = edata->cap_value;
|
|
|
|
|
roller_last_timestamp[r_id] = time_now;
|
|
|
|
|
|
|
|
|
|
@ -71,6 +73,8 @@ float get_roller_speed(roller_id_t roller_id) {
|
|
|
|
|
pulse_measurement_t pulse_measurement;
|
|
|
|
|
// Get the pulse period in APB clock ticks.
|
|
|
|
|
xQueuePeek(roller_measurement_queue[roller_id], &pulse_measurement, 0);
|
|
|
|
|
|
|
|
|
|
// A period of zero means that it didn't actually have a previous pulse to compare to
|
|
|
|
|
if ((pulse_measurement.period == 0) or
|
|
|
|
|
((esp_timer_get_time() - pulse_measurement.timestamp) >= ZERO_SPEED_TIMEOUT_US)) {
|
|
|
|
|
return 0.0;
|
|
|
|
|
|