From 8a043b14f274cc5328596876e40c2f2c2d755119 Mon Sep 17 00:00:00 2001 From: DragonflyPS Date: Wed, 31 Jan 2024 09:35:39 -0800 Subject: [PATCH] Updated pulse count code to output on PWM and actually increment --- Firmware/pulse_generator.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Firmware/pulse_generator.c b/Firmware/pulse_generator.c index 2f9f43b..d15409c 100644 --- a/Firmware/pulse_generator.c +++ b/Firmware/pulse_generator.c @@ -8,6 +8,8 @@ #define SPARK_THRESHOLD_PWM_PIN 14 #define SHORT_ALERT_PIN 1 +#define PULSE_COUNTER_PWM_PIN 24 + #define SHORT_THRESHOLD 410 bool cutting_enabled = false; @@ -128,9 +130,13 @@ int64_t begin_off_time(alarm_id_t id, void *user_data){ pulse_history[7] = pulse_history[7] >> 1; //Binary shift the last value, done outside the for loop because nowhere to pull the MSB from - if(output_state == SPARK_ON) //If successful spark then load a 1 into the MSB of the shift register + if(output_state == SPARK_ON) { //If successful spark then load a 1 into the MSB of the shift register and increment pulse counter + pulse_history[7] = pulse_history[7] + (1 << 31); + pulse_counter += 1; + } + output_state = SPARK_OFF; //Set state machine state to SPARK_OFF if(pulse_counter > 410) { @@ -141,6 +147,8 @@ int64_t begin_off_time(alarm_id_t id, void *user_data){ gpio_put(SHORT_ALERT_PIN, true); } + pwm_set_gpio_level(PULSE_COUNTER_PWM_PIN, pulse_counter<<2); + return 0; } @@ -153,6 +161,10 @@ void begin_output_pulses(uint32_t on_time, uint32_t off_time, bool iso_pulse) { pulse_timeout_time = pulse_on_time / 2; iso_pulse_mode = iso_pulse; + for (int i = 0; i < 7; i++) + pulse_history[i] = 0; + pulse_counter = 0; + begin_off_time(-1, NULL); } @@ -174,4 +186,8 @@ void pulse_generator_init(uint32_t trip_current) { pwm_set_gpio_level(SPARK_THRESHOLD_PWM_PIN, trip_current); + gpio_set_function(PULSE_COUNTER_PWM_PIN, GPIO_FUNC_PWM); + pwm_set_wrap(pwm_gpio_to_slice_num(PULSE_COUNTER_PWM_PIN), 2500); + + } \ No newline at end of file