Added pulse limiting capability

This commit is contained in:
DragonflyPS 2024-02-19 15:26:47 -08:00
parent f2afd85eff
commit e23cc53d5d
3 changed files with 17 additions and 8 deletions

View File

@ -10,10 +10,11 @@
#define CUT_nEN_PIN 0
//OUTPUT PULSE PARAMETERS (times in usecs)
#define OUTPUT_ON_TIME 20
#define OUTPUT_OFF_TIME 70
#define ISO_PULSE true
#define CAP_VOLTAGE_SETPOINT 65
#define OUTPUT_ON_TIME 32
#define OUTPUT_OFF_TIME 256
#define ISO_PULSE false
#define CAP_VOLTAGE_SETPOINT 70
#define PULSE_COUNT 30
//CC Charger Parameters (don't change unless you know what you're doing)
#define CHARGER_CURRENT 850
@ -37,7 +38,7 @@ 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);
begin_output_pulses(OUTPUT_ON_TIME, OUTPUT_OFF_TIME, ISO_PULSE, PULSE_COUNT);
} else if(gpio_get(CUT_nEN_PIN)) {

View File

@ -37,6 +37,9 @@ alarm_id_t timeout_alarm_id;
uint32_t pulse_history[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
uint32_t pulse_counter = 0;
uint8_t pulses_to_attempt = 0;
uint8_t pulse_attempt_counter = 0;
//Prototype functions
int64_t begin_off_time(alarm_id_t id, void *user_data);
@ -82,6 +85,8 @@ int64_t begin_on_time(alarm_id_t id, void *user_data){
if(cutting_enabled) { //Check that cutting is still enabled
pulse_attempt_counter += 1;
output_state = WAITING_FOR_IGNITION; //Update pulse generator state
gpio_set_irq_enabled(OUTPUT_CURRENT_TRIP_PIN, GPIO_IRQ_EDGE_RISE, true); //Configure detection of the spark
@ -142,7 +147,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 > 513) {
if(pulse_counter > 513 || pulse_attempt_counter >= pulses_to_attempt) {
cutting_enabled = false;
short_tripped = true;
disable_CC_timing();
@ -171,7 +176,7 @@ void first_off_time(){
}
void begin_output_pulses(uint32_t on_time, uint32_t off_time, bool iso_pulse) {
void begin_output_pulses(uint32_t on_time, uint32_t off_time, bool iso_pulse, uint8_t pulse_count) {
//Load in the pulse parameters
pulse_on_time = on_time;
@ -179,6 +184,9 @@ 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;
pulses_to_attempt = pulse_count;
pulse_attempt_counter = 0;
for (int i = 0; i < 15; i++)
pulse_history[i] = 0;
pulse_counter = 0;

View File

@ -14,7 +14,7 @@ void short_alert_off();
/*! \brief Start the EDM machine, ie, begin cutting
\ingroup pulse_generator
*/
void begin_output_pulses(uint32_t on_time, uint32_t off_time, bool iso_pulse);
void begin_output_pulses(uint32_t on_time, uint32_t off_time, bool iso_pulse, uint8_t pulse_count);
/*! \brief Setup pins/dirs for the pulse generator
\ingroup pulse_generator