Skip to content

Commit

Permalink
Prevent lockup if default values aren't set
Browse files Browse the repository at this point in the history
  • Loading branch information
noisymime committed Apr 24, 2024
1 parent a9d61fb commit 61b6025
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
15 changes: 11 additions & 4 deletions ardustim/ardustim/ardustim.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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) );
}

Expand Down Expand Up @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions ardustim/ardustim/comms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
/*!
Expand Down Expand Up @@ -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<Wheels[config.wheel].wheel_max_edges; x++)
{
if(x != 0) { Serial.print(","); }
Expand Down
2 changes: 2 additions & 0 deletions ardustim/ardustim/storage.ino
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void loadConfig()
//New arduino
config.wheel = 5; //36-1
currentStatus.rpm = 3000;
currentStatus.base_rpm = 3000;
config.mode = POT_RPM;

config.fixed_rpm = 3500;
Expand Down Expand Up @@ -63,6 +64,7 @@ void loadConfig()
if(config.wheel >= 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; }
}
Expand Down

0 comments on commit 61b6025

Please sign in to comment.