Skip to content

Commit

Permalink
Working fixed RPM mode
Browse files Browse the repository at this point in the history
  • Loading branch information
noisymime committed Jul 19, 2020
1 parent 3296ab4 commit 2600eb4
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 68 deletions.
12 changes: 6 additions & 6 deletions UI/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,26 @@
<div class="col-6 col-4-medium col-12-small">RPM Mode: </div>
<div class="col-1 col-6-medium col-12-small">
<select id="rpmSelect" onChange="setRPMMode()">
<option value="0">Use potentiometer</option>
<option value="2">Use potentiometer</option>
<option value="1">Fixed RPM</option>
<option value="2">Sweep</option>
<option value="0">Sweep</option>
</select>
</div>
</div>
<div class="row">
<div class="col-6 col-4-medium col-12-small">Fixed RPM: </div>
<div class="col-1 col-6-medium col-12-small">
<input type="number" id="fixedRPM" min="0" max="10000" step="1" value="2500.0" onChange="updateRPM()">
<input type="number" id="fixedRPM" min="0" max="10000" step="1" value="2500" onChange="setFixedRPM()">
</div>
</div>
<div class="row">
<div class="col-6 col-4-medium col-12-small">RPM Sweep range: </div>
<div class="col-6 col-6-medium col-12-small">
<input type="number" id="rpmSweepMin" min="0" max="10000" step="1" value="100.0" onChange="updateSweepRPM()">
<input type="number" id="rpmSweepMin" min="0" max="10000" step="1" value="100" onChange="setSweepRPM()">
</div>

<div class="col-6 col-6-medium col-12-small">
<input type="number" id="rpmSweepMax" min="0" max="10000" step="1" value="6000" onChange="updateSweepRPM()">
<input type="number" id="rpmSweepMax" min="0" max="10000" step="1" value="6000" onChange="setSweepRPM()">
</div>
</div>
</div>
Expand All @@ -81,7 +81,7 @@
data-value-dec="0"
data-width="400"
data-height="400"
data-animation-duration="100"
data-animation-duration="50"
data-animated-value="true"
data-animation-rule="linear"
></canvas>
Expand Down
58 changes: 49 additions & 9 deletions UI/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,6 @@ function updatePattern()

const parser = port.pipe(new Readline({ delimiter: '\r\n' }));
console.log(`Sending 'S' command with pattern ${patternID}`);
//const parser = port.pipe(new ByteLength({length: 8}))
//port.write('S'); //Send the command to change the pattern

var buffer = new Buffer(2);
buffer[0] = 0x53; // Ascii 'S'
Expand Down Expand Up @@ -377,19 +375,60 @@ function refreshPattern(data)

}

function updateRPM()
function setRPMMode()
{
//Send a new fixed RPM value back to the arduino
//Change between pot, fixed and sweep RPM modes

var newMode = parseInt(document.getElementById('rpmSelect').value);

const parser = port.pipe(new Readline({ delimiter: '\r\n' }));
console.log(`Sending 'M' command to change RPM mode to ${newMode}`);

var buffer = new Buffer(2);
buffer[0] = 0x4D; // Ascii 'M'
buffer[1] = newMode;
port.write(buffer); //Send the new pattern ID

//If the new mode is fixed RPM or linear sweep, then send the RPM set values for them
if(newMode == 0)
{
//Sweep RPM mode
setSweepRPM();
}
else if (newMode == 1)
{
//Fixed RPM mode
setFixedRPM();
}

}

function updateSweepRPM()
function setFixedRPM()
{
//Send new sweep RPM values back to the arduino
var newRPM = parseInt(document.getElementById('fixedRPM').value);
//console.log(`Desired RPM: ${newRPM}`);

var rpmBuffer = Buffer.alloc(3);
rpmBuffer[0] = 0x66; // Ascii 'f'
rpmBuffer.writeInt16LE(newRPM, 1);
//console.log(rpmBuffer);

port.write(rpmBuffer);
}

function setRPMMode()
function setSweepRPM()
{
//Change between pot, fixed and sweep RPM modes
var newRPM_min = parseInt(document.getElementById('rpmSweepMin').value);
var newRPM_max = parseInt(document.getElementById('rpmSweepMax').value);
//console.log(`Desired RPM: ${newRPM}`);

var rpmBuffer = Buffer.alloc(5);
rpmBuffer[0] = 0x73; // Ascii 's'
rpmBuffer.writeInt16LE(newRPM_min, 1);
rpmBuffer.writeInt16LE(newRPM_max, 3);
//console.log(rpmBuffer);

port.write(rpmBuffer);
}

function redrawGears(pattern, degrees)
Expand Down Expand Up @@ -440,20 +479,21 @@ function disableRPM()
RPMInterval = 0;
port.unpipe();
port.read(); //Flush the port
parser.read();
}

function receiveRPM(data)
{
console.log(`Received RPM: ${data}`);
currentRPM = parseInt(data);
//console.log(`New RPM: ${currentRPM}`);
}

function updateRPM()
{
console.log("Requesting new RPM");
port.write("R"); //Request next RPM read
document.gauges[0].value = currentRPM;
console.log(`New gauge RPM: ${document.gauges[0].value}`);
}


Expand Down
28 changes: 19 additions & 9 deletions ardustim/src/ardustim.ino
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "user_defaults.h"
#include "wheel_defs.h"
#include <avr/pgmspace.h>
#include <EEPROM.h>

/* Sensistive stuff used in ISR's */
volatile uint8_t fraction = 0;
Expand Down Expand Up @@ -194,8 +195,8 @@ void setup() {
pinMode(9, OUTPUT); /* Secondary (cam usually) output */
pinMode(10, OUTPUT); /* Knock signal for seank, ony on LS1 pattern, NOT IMPL YET */
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
pinMode(53, OUTPUT); /* Knock signal for seank, ony on LS1 pattern, NOT IMPL YET */
pinMode(52, OUTPUT); /* Knock signal for seank, ony on LS1 pattern, NOT IMPL YET */
pinMode(53, OUTPUT);
pinMode(52, OUTPUT);
#endif

sei(); // Enable interrupts
Expand All @@ -204,6 +205,11 @@ void setup() {
/* Make sure we are using the DEFAULT RPM on startup */
reset_new_OCR1A(wanted_rpm);

//Set RPM mode
mode = EEPROM.read(EEPROM_LAST_MODE);
if(mode > POT_RPM) { mode = POT_RPM; }


} // End setup


Expand All @@ -216,7 +222,7 @@ ISR(ADC_vect){
if (analog_port == 0)
{
adc0 = ADCL | (ADCH << 8);
adc0_read_complete = true;
adc0_read_complete = true;
/* Flip to channel 1 */
//ADMUX |= B00000001;
//analog_port = 1;
Expand Down Expand Up @@ -390,14 +396,18 @@ void loop()

if(Serial.available() > 0) { commandParser(); }

if (adc0_read_complete == true)
if(mode == POT_RPM)
{
adc0_read_complete = false;
tmp_rpm = adc0 << TMP_RPM_SHIFT;
if (tmp_rpm > TMP_RPM_CAP) { tmp_rpm = TMP_RPM_CAP; }
wanted_rpm = tmp_rpm;
reset_new_OCR1A(tmp_rpm);
if (adc0_read_complete == true)
{
adc0_read_complete = false;
tmp_rpm = adc0 << TMP_RPM_SHIFT;
if (tmp_rpm > TMP_RPM_CAP) { tmp_rpm = TMP_RPM_CAP; }
wanted_rpm = tmp_rpm;
reset_new_OCR1A(tmp_rpm);
}
}

}


Expand Down
80 changes: 37 additions & 43 deletions ardustim/src/comms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,24 @@ void commandParser()
{
char buf[80];
byte tmp_wheel;
byte tmp_mode;
if (cmdPending == false) { currentCommand = Serial.read(); }

switch (currentCommand)
{
case 'a':
break;

case 'f': //Set the fixed RPM value
mode = FIXED_RPM;
while(Serial.available() < 2) {} //Wait for the new RPM bytes
wanted_rpm = word(Serial.read(), Serial.read());
//wanted_rpm = 2000;
//reset_new_OCR1A(wanted_rpm);
setRPM(wanted_rpm);
break;


case 'L': // send the list of wheel names
//First byte sent is the number of wheels
//Serial.println(MAX_WHEELS);
Expand All @@ -91,6 +102,15 @@ void commandParser()
}
break;

case 'M': ///Change the RPM mode
while(Serial.available() < 1) {} //Wait for the new mode byte
tmp_mode = Serial.read();
if(tmp_mode <= POT_RPM)
{
mode = tmp_mode;
}
break;

case 'n': //Send the number of wheels
Serial.println(MAX_WHEELS);
break;
Expand Down Expand Up @@ -118,6 +138,18 @@ void commandParser()
Serial.println(wanted_rpm);
break;

case 's': //Set the high and low RPM for sweep mode
mode = LINEAR_SWEPT_RPM;
while(Serial.available() < 4) {} //Wait for 4 bytes representing the new low and high RPMs

sweep_low_rpm = word(Serial.read(), Serial.read());
sweep_high_rpm = word(Serial.read(), Serial.read());

sweep_low_rpm = 100;
sweep_high_rpm = 4000;
compute_sweep_stages(&sweep_low_rpm, &sweep_high_rpm);
break;

case 'S': //Set the current wheel
while(Serial.available() < 1) {}
tmp_wheel = Serial.read();
Expand Down Expand Up @@ -231,34 +263,12 @@ void setRPM(uint32_t newRPM)
sweep_lock = true;
if (SweepSteps)
free(SweepSteps);
mode = FIXED_RPM;
//mode = FIXED_RPM;
reset_new_OCR1A(newRPM);
wanted_rpm = newRPM;

//mySUI.print_P(new_rpm_chosen);
//mySUI.println(wanted_rpm);
sweep_lock = false;
}


//! Returns a list of user selectable wheel patterns
/*!
* Iterates through the list of wheel patterns and prints them back to the user
*/
void list_wheels_cb()
{
byte i = 0;
for (i=0;i<MAX_WHEELS;i++)
{
/*
mySUI.print(i+1);
mySUI.print_P(colon_space);
mySUI.println_P((Wheels[i].decoder_name));
*/
}
}


//! Toggle the wheel direction, useful for debugging
/*!
* Reverses the emitting wheel pattern direction. Used mainly as a debugging aid
Expand Down Expand Up @@ -297,39 +307,23 @@ void reverse_wheel_direction_cb()
* we use this to keep things as quick as possible. This function takes
* no parameters (it cannot due to SerialUI) and returns void
*/
void sweep_rpm_cb()
void sweep_rpm_cb(uint16_t tmp_low_rpm, uint16_t tmp_high_rpm)
{
/*
uint16_t tmp_low_rpm;
uint16_t tmp_high_rpm;
uint8_t j;

char sweep_buffer[20] = {0};

mySUI.showEnterDataPrompt();
j = mySUI.readBytesToEOL(sweep_buffer,20);
j = sscanf(sweep_buffer,"%i,%i,%i",&tmp_low_rpm,&tmp_high_rpm,&sweep_rate);
// Validate input ranges
if ((j == 3) &&
if (
(tmp_low_rpm >= 10) &&
(tmp_high_rpm < 51200) &&
(sweep_rate >= 1) &&
(sweep_rate < 51200) &&
(tmp_low_rpm < tmp_high_rpm))
{
mySUI.print_P(sweeping_from_colon_space);
mySUI.print(tmp_low_rpm);
mySUI.print_P(arrows);
mySUI.print(tmp_high_rpm);
mySUI.print_P(space_at_colon_space);
mySUI.print(sweep_rate);
mySUI.println_P(space_rpm_per_sec);

compute_sweep_stages(&tmp_low_rpm, &tmp_high_rpm);
}
else {
mySUI.returnError(range_error);
}
*/

}


Expand Down
2 changes: 1 addition & 1 deletion ardustim/src/comms.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ void select_next_wheel_cb();
void select_previous_wheel_cb();
void toggle_invert_primary_cb();
void toggle_invert_secondary_cb();
void list_wheels_cb();
void select_wheel_cb();
void set_rpm_cb();
void sweep_rpm_cb();
void reverse_wheel_direction_cb();
void setRPM(uint32_t);

/* General functions */
void serialSetup();
Expand Down
2 changes: 2 additions & 0 deletions ardustim/src/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@
#define SUI_NO_INCLUDE_EXTRA_SAFETYCHECKS
#define LOG_2 0.30102999566

#define EEPROM_LAST_MODE 100

#endif
1 change: 1 addition & 0 deletions ardustim/src/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ enum {
enum {
LINEAR_SWEPT_RPM,
FIXED_RPM,
POT_RPM
};

#endif

0 comments on commit 2600eb4

Please sign in to comment.