Commit cfdcede9 authored by mattdr's avatar mattdr
Browse files

new delay added to find z offset

parent 297c0f79
......@@ -38,7 +38,7 @@ int button_offset_increment = 5;
// how long in microsec (us) to delay between phases while calibrating
// the wheel
int CALIBRATION_DELAY = 28500;
int CALIBRATION_DELAY = 18500; // previous: 28500
// Timer setup (for speed calc)
IntervalTimer speed_timer;
......@@ -224,8 +224,20 @@ int get_phase_number(int elec_position)
// Interupt Service routine that will find zero
void isr_index(void){
Zoffset = encoder.calcPosn();
calibrated = true;
static int count = 0;
static unsigned long last_interrupt_time = 0;
unsigned long interrupt_time = millis();
if (interrupt_time - last_interrupt_time > 500)
{
count += 1;
}
if (count >= 2)
{
Zoffset = encoder.calcPosn();
calibrated = true;
}
return;
}
......
......@@ -12,10 +12,13 @@ void setup()
// Pin Jumper to decide whether we print our options or skip straight to
// Precalculated Butt Control
checkDebugJumper();
delay(1000);
motor_setup();
encoder_setup();
//deal with serial (might want this faster)
Serial.begin(9600);//Serial.begin(2000000); //FASTER!
// Hit space bar to start calibration
......
......@@ -78,9 +78,17 @@ int get_pot_0_scaled(int scaleFactor, float period_over_255)
volatile float raw_potval = analogRead(A0);
float potval = raw_potval;
//triggere pot has a raw value of 260-1023 ie 763 is the range (starting at 260)
potval = potval - 260; // This makes the trigger pot go from 0-763
potval = ROC_limiter(potval);
//This code creates a limit on the amount of power durring calibration
// This code creates a limit on the amount of power durring calibration
if (!is_calibration_complete()){
if (potval > CALIBRATION_MAX_PWM){
potval = CALIBRATION_MAX_PWM;
......@@ -89,22 +97,35 @@ int get_pot_0_scaled(int scaleFactor, float period_over_255)
potval = potval/1024;
potval = potval/763; //previously 1024 for slide pot now 763 for trigger pot
potval = potval * scaleFactor;
potval -= 3.0; // this just disables the first three pot ticks
// This code is used to make sure that the pwm nver has a period
// lower than 250 ns (as this may be problematic for gate drivrs)
if ((period_over_255 * potval) < 250.0E-9){
return (int)0;
}
// if ((period_over_255 * potval) < 250.0E-9){
// return (int)0;
// }
if (potval > 255) //limit the top
{
potval = 255;
}
if (potval < 0)
{
potval = 0;
}
// if (getDebugOn()){
// Serial.println("value from get_pot_0_scaled");
// Serial.println((int)potval);
// }
return (int)potval;
}
......
Markdown is supported
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