Commit 1c6a097a authored by mattdr's avatar mattdr
Browse files

state of code at end of ecomarathon 2019. good work team, better luck next year.

parent 2ba86a7a
......@@ -26,7 +26,7 @@ const int led = 13;
const int time_led = 1;
// This scale factor scales the potentiometer
int const SCALE_FACTOR = 240;
int const SCALE_FACTOR = 255;
// This is the PWM frequency and it is very important
int FREQ = 22000; //8000 was our original value;
......@@ -75,6 +75,9 @@ void motor_setup(void) {
analogWriteFrequency(H1, FREQ);
analogWriteFrequency(H2, FREQ);
analogWriteFrequency(H3, FREQ);
analogWriteFrequency(L1, FREQ);
analogWriteFrequency(L2, FREQ);
analogWriteFrequency(L3, FREQ);
turn_all_off();
......@@ -98,6 +101,10 @@ void motor_setup(void) {
pot_0_timer.begin(pot_0_speed_ISR, 33333);
}
int get_scale_factor(){
return SCALE_FACTOR;
}
void pot_0_speed_ISR() {
POT_0_VALUE = get_pot_0_scaled(SCALE_FACTOR, PERIOD_OVER_255);
......@@ -111,9 +118,9 @@ void pot_0_speed_ISR() {
}
void turn_all_off() {
digitalWrite(L1, LOW);
digitalWrite(L2, LOW);
digitalWrite(L3, LOW);
analogWrite(L1, 0);
analogWrite(L2, 0);
analogWrite(L3, 0);
analogWrite(H1, 0);
analogWrite(H2, 0);
analogWrite(H3, 0);
......@@ -182,18 +189,18 @@ void set_phase(int high1, int high2, int high3, int low1, int low2, int low3)
//turn the stuff that should be off, off first
cli();
if (! low1) digitalWrite(L1, low1);
if (! low2) digitalWrite(L2, low2);
if (! low3) digitalWrite(L3, low3);
if (! low1) analogWrite(L1, 0);
if (! low2) analogWrite(L2, 0);
if (! low3) analogWrite(L3, 0);
if (! high1) analogWrite(H1, high1);
if (! high2) analogWrite(H2, high2);
if (! high3) analogWrite(H3, high3);
//turn the stuff that should be on, on
if (low1) digitalWrite(L1, low1);
if (low2) digitalWrite(L2, low2);
if (low3) digitalWrite(L3, low3);
if (low1) analogWrite(L1, 255);
if (low2) analogWrite(L2, 255);
if (low3) analogWrite(L3, 255);
if (high1) analogWrite(H1, high1);
if (high2) analogWrite(H2, high2);
if (high3) analogWrite(H3, high3);
......@@ -258,7 +265,7 @@ void set_phase_float(float f1, float f2, float f3)
{
// f1 used to have low side on now has high side on
// turn off f1 low side first then do f1s high side
digitalWrite(L1, 0);
analogWrite(L1, 0);
analogWrite(H1, f1i);
f1_is_transient = true;
}
......@@ -266,7 +273,7 @@ void set_phase_float(float f1, float f2, float f3)
//f1 used to have high side running now has low side on
// turn off the high side first then do f1s low side
analogWrite(H1, 0);
digitalWrite(L1, 1);
analogWrite(L1, 255);
f1_is_transient = true;
}
......@@ -274,7 +281,7 @@ void set_phase_float(float f1, float f2, float f3)
{
// f2 used to have low side on now has high side on
// turn off f2 low side first then do f2s high side
digitalWrite(L2, 0);
analogWrite(L2, 0);
analogWrite(H2, f2i);
f2_is_transient = true;
}
......@@ -282,7 +289,7 @@ void set_phase_float(float f1, float f2, float f3)
//f2 used to have high side running now has low side on
// turn off the high side first then do f2s low side
analogWrite(H2, 0);
digitalWrite(L2, 1);
analogWrite(L2, 255);
f2_is_transient = true;
}
......@@ -291,7 +298,7 @@ void set_phase_float(float f1, float f2, float f3)
{
// f3 used to have low side on now has high side on
// turn off f3 low side first then do f3s high side
digitalWrite(L3, 0);
analogWrite(L3, 0);
analogWrite(H3, f3i);
f3_is_transient = true;
}
......@@ -299,37 +306,37 @@ void set_phase_float(float f1, float f2, float f3)
//f3 used to have high side running now has low side on
// turn off the high side first then do f3s low side
analogWrite(H3, 0);
digitalWrite(L3, 1);
analogWrite(L3, 255);
f3_is_transient = true;
}
if (! f1_is_transient){
if(f1i == 0){
digitalWrite(L1, 1);
analogWrite(L1, 255);
}
else{
digitalWrite(L1, 0);
analogWrite(L1, 0);
}
analogWrite(H1, f1i);
}
if (! f2_is_transient){
if(f2i == 0){
digitalWrite(L2, 1);
analogWrite(L2, 255);
}
else{
digitalWrite(L2, 0);
analogWrite(L2, 0);
}
analogWrite(H2, f2i);
}
if (! f3_is_transient){
if(f3i == 0){
digitalWrite(L3, 1);
analogWrite(L3, 255);
}
else{
digitalWrite(L3, 0);
analogWrite(L3, 0);
}
analogWrite(H3, f3i);
}
......
......@@ -11,7 +11,7 @@ void motor_butt_control_inefficient(void);
void set_phase_float(float f1, float f2, float f3);
void motor_butt_control_precalculated(void);
void charge_bootstrap_capacitors(void);
int get_scale_factor();
......
......@@ -3,7 +3,7 @@
#include "motor_ctrl.h"
#include "encoder.h"
float CALIBRATION_MAX_PWM = 100.0;
float CALIBRATION_MAX_PWM = 92.3;
const float UPWARD_ROC_LIMITER = 10.0;
float UPWARD_ROC_PREV_VALUE = 0;
......@@ -106,7 +106,7 @@ int debug_pot_0_scaled()
set_calibration_complete();//spoof complete calibration to get proper values
while(1){
Serial.println("value from get_pot_0_scaled");
Serial.println(get_pot_0_scaled(240,0.0000000817));
Serial.println(get_pot_0_scaled(get_scale_factor(),0.0000000817));
delay(200); // do not go too fast!
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment