Fixed EN signal issues
Glitchy/bouncy inputs to the EN pin were previously causing two versions of the pulse generator code to run in parallel causing erroneous behavior EN pin handling was moved from IRQ to fixed time polling to eliminate this issue
This commit is contained in:
parent
4e116eae4f
commit
402ae2c0e7
|
@ -68,11 +68,15 @@ void VSENSE_TRIP_callback(void) {
|
|||
|
||||
}
|
||||
|
||||
void disable_gate_driver() {
|
||||
gpio_put(CC_CHARGER_EN_PIN, false);
|
||||
}
|
||||
|
||||
void disable_CC_timing() {
|
||||
|
||||
gpio_put(DIODE_ON_PIN, false); //Turn off ideal diode
|
||||
|
||||
gpio_put(CC_CHARGER_EN_PIN, false); //Disable CC Charger gate driver
|
||||
// gpio_put(CC_CHARGER_EN_PIN, false); //Disable CC Charger gate driver
|
||||
|
||||
pio_sm_set_enabled(pio, sm_clk, false); //Disable CC Charger Clock
|
||||
pio_sm_exec(pio, sm_clk, pio_encode_nop() | pio_encode_sideset_opt(1, 0)); //Set Clock output to 0
|
||||
|
|
|
@ -11,9 +11,9 @@
|
|||
|
||||
//OUTPUT PULSE PARAMETERS (times in usecs)
|
||||
#define OUTPUT_ON_TIME 20
|
||||
#define OUTPUT_OFF_TIME 80
|
||||
#define OUTPUT_OFF_TIME 70
|
||||
#define ISO_PULSE false
|
||||
#define CAP_VOLTAGE_SETPOINT 65 //Don't set higher than 65
|
||||
#define CAP_VOLTAGE_SETPOINT 70 //Don't set higher than 65
|
||||
|
||||
//CC Charger Parameters (don't change unless you know what you're doing)
|
||||
#define CHARGER_CURRENT 850
|
||||
|
@ -21,24 +21,27 @@
|
|||
//Math stuff DO NOT EDIT
|
||||
#define CAP_VOLTAGE_PWM_LEVEL CAP_VOLTAGE_SETPOINT * 303 / 48
|
||||
|
||||
bool tripped = false;
|
||||
bool os = false;
|
||||
|
||||
void cut_on_off_irq(void) {
|
||||
|
||||
if(gpio_get_irq_event_mask(CUT_nEN_PIN) & GPIO_IRQ_EDGE_FALL) {
|
||||
|
||||
gpio_acknowledge_irq(CUT_nEN_PIN, GPIO_IRQ_EDGE_FALL);
|
||||
bool cut_on_off_irq(repeating_timer_t *rt) {
|
||||
|
||||
if(!gpio_get(CUT_nEN_PIN) && !cutting_enabled) {
|
||||
cutting_enabled = true;
|
||||
begin_output_pulses(OUTPUT_ON_TIME, OUTPUT_OFF_TIME, ISO_PULSE);
|
||||
} else if(gpio_get(CUT_nEN_PIN)) {
|
||||
cutting_enabled == false;
|
||||
}
|
||||
|
||||
if(gpio_get_irq_event_mask(CUT_nEN_PIN) & GPIO_IRQ_EDGE_RISE) {
|
||||
|
||||
gpio_acknowledge_irq(CUT_nEN_PIN, GPIO_IRQ_EDGE_RISE);
|
||||
|
||||
if(gpio_get(CUT_nEN_PIN)) {
|
||||
cutting_enabled = false;
|
||||
disable_gate_driver();
|
||||
}
|
||||
|
||||
gpio_put(1, os);
|
||||
os = !os;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
void default_gpio_callback(uint gpio, uint32_t event_mask) {
|
||||
|
@ -64,21 +67,20 @@ int main() {
|
|||
|
||||
gpio_init(CUT_nEN_PIN);
|
||||
gpio_set_dir(CUT_nEN_PIN, GPIO_IN);
|
||||
gpio_set_pulls(CUT_nEN_PIN, true, false);
|
||||
gpio_set_pulls(CUT_nEN_PIN, false, false);
|
||||
|
||||
gpio_init(1);
|
||||
gpio_set_dir(1, GPIO_OUT);
|
||||
gpio_put(1, false);
|
||||
|
||||
irq_set_enabled(IO_IRQ_BANK0, true);
|
||||
|
||||
sleep_ms(1000);
|
||||
|
||||
gpio_set_irq_enabled(CUT_nEN_PIN, GPIO_IRQ_EDGE_RISE | GPIO_IRQ_EDGE_FALL, true);
|
||||
gpio_add_raw_irq_handler(CUT_nEN_PIN, &cut_on_off_irq);
|
||||
repeating_timer_t timer;
|
||||
|
||||
add_repeating_timer_ms(100, cut_on_off_irq, NULL, &timer);
|
||||
|
||||
while (true) {
|
||||
|
||||
// sleep_us(10);
|
||||
// gpio_put(3, true);
|
||||
// sleep_us(10);
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#define OUTPUT_CURRENT_TRIP_PIN 10
|
||||
#define SPARK_THRESHOLD_PWM_PIN 14
|
||||
|
||||
bool cutting_enabled = true;
|
||||
bool cutting_enabled = false;
|
||||
bool off_time_insufficient = false;
|
||||
|
||||
//Enum to keep track of where we are in the pulse sequence
|
||||
|
@ -31,6 +31,8 @@ int64_t change_CC_timing(alarm_id_t id, void *user_data){
|
|||
|
||||
LIMIT_set_timing(185, 7, true);
|
||||
|
||||
alarm_pool_cancel_alarm(alarm_pool_get_default(), id);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
@ -59,24 +61,32 @@ int64_t begin_on_time(alarm_id_t id, void *user_data){
|
|||
|
||||
if(iso_pulse_mode) { //Check pulse mode is iso-pulse
|
||||
|
||||
add_alarm_in_us(pulse_timeout_time, begin_off_time, NULL, true); //Set the alarm in case of pulse timeout
|
||||
|
||||
output_state = WAITING_FOR_IGNITION; //Update pulse generator state
|
||||
|
||||
gpio_put(OUTPUT_EN_PIN, true); //Turn on output FET
|
||||
|
||||
add_alarm_in_us(pulse_timeout_time, begin_off_time, NULL, true); //Set the alarm in case of pulse timeout
|
||||
|
||||
gpio_set_irq_enabled(OUTPUT_CURRENT_TRIP_PIN, GPIO_IRQ_EDGE_RISE, true);//Configure detection of the spark
|
||||
gpio_add_raw_irq_handler(OUTPUT_CURRENT_TRIP_PIN, &output_current_trip_irq);
|
||||
|
||||
} else { //If pulse mode is iso-tonic
|
||||
|
||||
add_alarm_in_us(pulse_on_time, begin_off_time, NULL, true); //Set alarm for the off transition
|
||||
|
||||
output_state = SPARK_ON; //Update pulse generator state
|
||||
|
||||
gpio_put(OUTPUT_EN_PIN, true); //Turn on output FET
|
||||
add_alarm_in_us(pulse_on_time-3, begin_off_time, NULL, true); //Set alarm for the off transition
|
||||
|
||||
}
|
||||
} else {
|
||||
|
||||
gpio_put(OUTPUT_EN_PIN, false);
|
||||
|
||||
}
|
||||
|
||||
alarm_pool_cancel_alarm(alarm_pool_get_default(), id);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
@ -97,7 +107,7 @@ int64_t begin_off_time(alarm_id_t id, void *user_data){
|
|||
enable_CC_timing(); //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
|
||||
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
|
||||
|
||||
} else if(output_state == SPARK_ON && iso_pulse_mode == true) { //Spark is already ignited, ignore this timer callback
|
||||
|
||||
|
@ -105,6 +115,8 @@ int64_t begin_off_time(alarm_id_t id, void *user_data){
|
|||
|
||||
}
|
||||
|
||||
alarm_pool_cancel_alarm(alarm_pool_get_default(), id);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
@ -115,8 +127,8 @@ void first_begin_off_time() {
|
|||
|
||||
enable_CC_timing(); //Start the CC Charger
|
||||
|
||||
add_alarm_in_us(15-4, change_CC_timing, NULL, true); //Setup the alarm to correct CC charger timing
|
||||
add_alarm_in_us(pulse_off_time-8, begin_on_time, NULL, true); //Setup the alarm to turn on the output MOSFET after the off time
|
||||
add_alarm_in_us(15, change_CC_timing, NULL, false); //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
|
||||
}
|
||||
|
||||
void begin_output_pulses(uint32_t on_time, uint32_t off_time, bool iso_pulse) {
|
||||
|
@ -146,4 +158,7 @@ void pulse_generator_init(uint32_t trip_current) {
|
|||
gpio_init(OUTPUT_CURRENT_TRIP_PIN);
|
||||
gpio_set_dir(OUTPUT_CURRENT_TRIP_PIN, GPIO_IN);
|
||||
|
||||
gpio_init(1);
|
||||
gpio_set_dir(1, GPIO_OUT);
|
||||
|
||||
}
|
Loading…
Reference in New Issue