From 3c1446ef2a45565056d45649cddf16ba83ae411f Mon Sep 17 00:00:00 2001 From: DragonflyPS Date: Sat, 10 Feb 2024 11:14:25 -0800 Subject: [PATCH] Fixed board clicking when enabled and no load connected Added a check before turning on the charger for the cap voltage. Don't limit duty cycle on turn on if cap voltage is above 35V. Don't turn on diode unless voltage is below 50V --- Powercore-V2.0 Firmware/CC_Charger.c | 10 +++++----- Powercore-V2.0 Firmware/CC_Charger.h | 2 +- Powercore-V2.0 Firmware/main.c | 5 ++++- Powercore-V2.0 Firmware/pulse_generator.c | 20 ++++++++++++++----- .../KiCAD/fp-info-cache | 2 +- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/Powercore-V2.0 Firmware/CC_Charger.c b/Powercore-V2.0 Firmware/CC_Charger.c index 054a994..4312ded 100644 --- a/Powercore-V2.0 Firmware/CC_Charger.c +++ b/Powercore-V2.0 Firmware/CC_Charger.c @@ -2,6 +2,7 @@ #include "hardware/pio.h" #include "hardware/pwm.h" #include "CC_Charger.h" +#include "hardware/adc.h" // Our assembled programs: #include "CLK.pio.h" @@ -29,7 +30,6 @@ //Telemetry: #define VSENSE_TRIP_PIN 11 -#define CAP_VSENSE_PIN 27 PIO pio; @@ -39,8 +39,8 @@ uint offset_clk, offset_timing; uint32_t default_clk_period = 133; //3.216usec uint32_t default_limit_wait_time = 185; //3.024usec uint32_t default_limit_on_time = 7; //0.136usec -uint32_t default_blanking_wait_time = 185; //0.112usec -uint32_t default_blanking_on_time = 12; //3.032usec +uint32_t default_blanking_wait_time = 185; //0.112usec +uint32_t default_blanking_on_time = 12; //3.032usec bool caps_charged = false; @@ -88,7 +88,7 @@ void disable_CC_timing() { } -void enable_CC_timing() { +void enable_CC_timing(bool diode_on) { //Don't start the charger if the caps are already charged if(caps_charged == false){ @@ -105,7 +105,7 @@ void enable_CC_timing() { gpio_put(CC_CHARGER_EN_PIN, true); //Enable the CC Charger gate driver - gpio_put(DIODE_ON_PIN, true); //Turn on the ideal diode + gpio_put(DIODE_ON_PIN, diode_on); //Turn on the ideal diode } } diff --git a/Powercore-V2.0 Firmware/CC_Charger.h b/Powercore-V2.0 Firmware/CC_Charger.h index 996d1bb..7b74ff1 100644 --- a/Powercore-V2.0 Firmware/CC_Charger.h +++ b/Powercore-V2.0 Firmware/CC_Charger.h @@ -18,7 +18,7 @@ void disable_CC_timing(); /*! \brief Enable Constant Current Charger timing outputs, effectively turns on CC charger \ingroup CC_Charger */ -void enable_CC_timing(); +void enable_CC_timing(bool diode_on); /*! \brief Sets the CC charger clock period, indirectly sets the switching frequency of the CC charger \ingroup CC_Charger diff --git a/Powercore-V2.0 Firmware/main.c b/Powercore-V2.0 Firmware/main.c index e176196..2f56fb3 100644 --- a/Powercore-V2.0 Firmware/main.c +++ b/Powercore-V2.0 Firmware/main.c @@ -2,6 +2,7 @@ #include "pico/stdlib.h" #include "pico/time.h" #include "hardware/pwm.h" +#include "hardware/adc.h" #include "CC_Charger.h" #include "pulse_generator.h" @@ -11,7 +12,7 @@ //OUTPUT PULSE PARAMETERS (times in usecs) #define OUTPUT_ON_TIME 20 -#define OUTPUT_OFF_TIME 70 +#define OUTPUT_OFF_TIME 80 #define ISO_PULSE false #define CAP_VOLTAGE_SETPOINT 70 @@ -64,6 +65,8 @@ int main() { sleep_ms(1000); + adc_init(); + CC_Charger_init(CHARGER_CURRENT, CAP_VOLTAGE_PWM_LEVEL); //Setup the CC Charger Outputs pulse_generator_init(70); //Setup Pulse generator diff --git a/Powercore-V2.0 Firmware/pulse_generator.c b/Powercore-V2.0 Firmware/pulse_generator.c index cafc228..5ecc65f 100644 --- a/Powercore-V2.0 Firmware/pulse_generator.c +++ b/Powercore-V2.0 Firmware/pulse_generator.c @@ -2,6 +2,7 @@ #include "pulse_generator.h" #include "CC_Charger.h" #include "hardware/pwm.h" +#include "hardware/adc.h" #define OUTPUT_EN_PIN 2 #define OUTPUT_CURRENT_TRIP_PIN 10 @@ -10,6 +11,8 @@ #define PULSE_COUNTER_PWM_PIN 24 +#define CAP_VSENSE_PIN 27 + #define SHORT_THRESHOLD 410 bool cutting_enabled = false; @@ -114,11 +117,17 @@ int64_t begin_off_time(alarm_id_t id, void *user_data){ gpio_set_irq_enabled(OUTPUT_CURRENT_TRIP_PIN, GPIO_IRQ_EDGE_RISE, false); //Disable the ignition sense irq - LIMIT_set_timing(97, 7, false); //Limit CC Charger PWM duty cycle to avoid inrush (was 97) + adc_select_input(1); + uint16_t v_cap = adc_read(); + bool low_v = v_cap < 900; + gpio_put(SHORT_ALERT_PIN, low_v); + if(low_v) + LIMIT_set_timing(97, 7, false); //Limit CC Charger PWM duty cycle to avoid inrush (was 97) - enable_CC_timing(); //Start CC Charger + enable_CC_timing(v_cap < 1300); //Start CC Charger - add_alarm_in_us(15, change_CC_timing, NULL, true); //Setup the alarm to correct CC charger timing + if(low_v) + add_alarm_in_us(15, change_CC_timing, NULL, true); //Setup the alarm to correct CC charger timing add_alarm_in_us(pulse_off_time-11, begin_on_time, NULL, true); //Setup the alarm to turn on the output MOSFET after the off time pulse_counter -= pulse_history[0] & (uint32_t)0x1; //Subtract the 512th pulse state from the counter @@ -141,7 +150,7 @@ int64_t begin_off_time(alarm_id_t id, void *user_data){ output_state = SPARK_OFF; //Set state machine state to SPARK_OFF - if(pulse_counter > 410) { + if(pulse_counter > 513) { cutting_enabled = false; short_tripped = true; disable_CC_timing(); @@ -163,7 +172,7 @@ int64_t first_off_time(){ LIMIT_set_timing(97, 7, false); //Limit CC Charger PWM duty cycle to avoid inrush (was 97) - enable_CC_timing(); //Start CC Charger + enable_CC_timing(true); //Start CC Charger add_alarm_in_us(15, change_CC_timing, NULL, true); //Setup the alarm to correct CC charger timing add_alarm_in_us(pulse_off_time-11, begin_on_time, NULL, true); //Setup the alarm to turn on the output MOSFET after the off time @@ -212,5 +221,6 @@ void pulse_generator_init(uint32_t trip_current) { gpio_add_raw_irq_handler(OUTPUT_CURRENT_TRIP_PIN, &output_current_trip_irq); + adc_gpio_init(CAP_VSENSE_PIN); } \ No newline at end of file diff --git a/Powercore-V2.0 Motherboard/KiCAD/fp-info-cache b/Powercore-V2.0 Motherboard/KiCAD/fp-info-cache index ca90b0f..558d57d 100644 --- a/Powercore-V2.0 Motherboard/KiCAD/fp-info-cache +++ b/Powercore-V2.0 Motherboard/KiCAD/fp-info-cache @@ -1,4 +1,4 @@ -21654338788247244 +21654338790288434 Audio_Module Reverb_BTDR-1H Digital Reverberation Unit, http://www.belton.co.kr/inc/downfile.php?seq=17&file=pdf (footprint from http://www.uk-electronic.de/PDF/BTDR-1.pdf)