From 61b6025351e783b5b6d175030b6889cfbde2bea2 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Wed, 24 Apr 2024 18:07:15 +1000 Subject: [PATCH] Prevent lockup if default values aren't set --- ardustim/ardustim/ardustim.ino | 15 +++++++++++---- ardustim/ardustim/comms.cpp | 3 --- ardustim/ardustim/storage.ino | 2 ++ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/ardustim/ardustim/ardustim.ino b/ardustim/ardustim/ardustim.ino index b10bc09..970f18c 100644 --- a/ardustim/ardustim/ardustim.ino +++ b/ardustim/ardustim/ardustim.ino @@ -281,7 +281,7 @@ ISR(TIMER1_COMPA_vect) void loop() { - uint16_t tmp_rpm = 0; + uint16_t tmp_rpm = currentStatus.base_rpm; /* Just handle the Serial UI, everything else is in * interrupt handlers or callbacks from SerialUI. */ @@ -298,29 +298,32 @@ void loop() } else if (config.mode == LINEAR_SWEPT_RPM) { + if(micros() > (sweep_time_counter + config.sweep_interval)) { sweep_time_counter = micros(); if(sweep_direction == ASCENDING) { - tmp_rpm = currentStatus.rpm + 1; + tmp_rpm = currentStatus.base_rpm + 1; if(tmp_rpm >= config.sweep_high_rpm) { sweep_direction = DESCENDING; } } else { - tmp_rpm = currentStatus.rpm - 1; + tmp_rpm = currentStatus.base_rpm - 1; if(tmp_rpm <= config.sweep_low_rpm) { sweep_direction = ASCENDING; } } } + } else if (config.mode == FIXED_RPM) { tmp_rpm = config.fixed_rpm; } currentStatus.base_rpm = tmp_rpm; - currentStatus.compressionModifier = calculateCompressionModifier(); + currentStatus.compressionModifier = calculateCompressionModifier(); if(currentStatus.compressionModifier >= currentStatus.base_rpm ) { currentStatus.compressionModifier = 0; } + setRPM( (currentStatus.base_rpm - currentStatus.compressionModifier) ); } @@ -350,6 +353,10 @@ uint16_t calculateCompressionModifier() modAngle = crankAngle % 90; compressionModifier = pgm_read_byte(&sin_100_90[modAngle]); break; + default: + modAngle = (crankAngle % 180) ; + compressionModifier = pgm_read_byte(&sin_100_180[modAngle]); + break; } return compressionModifier; diff --git a/ardustim/ardustim/comms.cpp b/ardustim/ardustim/comms.cpp index d37e026..cbe40c9 100644 --- a/ardustim/ardustim/comms.cpp +++ b/ardustim/ardustim/comms.cpp @@ -39,7 +39,6 @@ extern volatile uint16_t new_OCR1A; bool cmdPending; byte currentCommand; -uint16_t numTeeth; //! Initializes the serial port and sets up the Menu /*! @@ -117,8 +116,6 @@ void commandParser() break; case 'P': //Send the pattern for the current wheel - numTeeth = pgm_read_word(Wheels[config.wheel].wheel_max_edges); - for(uint16_t x=0; x= MAX_WHEELS) { config.wheel = 5; } if(config.mode >= MAX_MODES) { config.mode = FIXED_RPM; } if(currentStatus.rpm > 15000) { currentStatus.rpm = 4000; } + if(currentStatus.base_rpm > 15000) { currentStatus.base_rpm = 4000; } if(config.compressionType > COMPRESSION_TYPE_8CYL_4STROKE) { config.compressionType = COMPRESSION_TYPE_4CYL_4STROKE; } if(config.compressionRPM > 1000) { config.compressionRPM = 400; } }