DRV8323RS Version
Dependencies: mbed-dev-f303 FastPWM3
Diff: Calibration/calibration.cpp
- Revision:
- 47:e1196a851f76
- Parent:
- 46:2d4b1dafcfe3
--- a/Calibration/calibration.cpp Thu Jul 12 02:50:34 2018 +0000 +++ b/Calibration/calibration.cpp Wed Dec 05 04:07:46 2018 +0000 @@ -16,7 +16,7 @@ printf("\n\r Checking phase ordering\n\r"); float theta_ref = 0; float theta_actual = 0; - float v_d = .05f; //Put all volts on the D-Axis + float v_d = V_CAL; //Put all volts on the D-Axis float v_q = 0.0f; float v_u, v_v, v_w = 0; float dtc_u, dtc_v, dtc_w = .5f; @@ -32,7 +32,7 @@ wait_us(100); } //ps->ZeroPosition(); - ps->Sample(); + ps->Sample(DT); wait_us(1000); //float theta_start = ps->GetMechPositionFixed(); //get initial rotor position float theta_start; @@ -51,7 +51,7 @@ TIM1->CCR3 = (PWM_ARR>>1)*(1.0f-dtc_u); //Set duty cycles TIM1->CCR2 = (PWM_ARR>>1)*(1.0f-dtc_v); TIM1->CCR1 = (PWM_ARR>>1)*(1.0f-dtc_w); - ps->Sample(); //sample position sensor + ps->Sample(DT); //sample position sensor theta_actual = ps->GetMechPositionFixed(); if(theta_ref==0){theta_start = theta_actual;} if(sample_counter > 200){ @@ -84,7 +84,7 @@ float * error_filt; const int n = 128*NPP; // number of positions to be sampled per mechanical rotation. Multiple of NPP for filtering reasons (see later) - const int n2 = 50; // increments between saved samples (for smoothing motion) + const int n2 = 40; // increments between saved samples (for smoothing motion) float delta = 2*PI*NPP/(n*n2); // change in angle between samples error_f = new float[n](); // error vector rotating forwards error_b = new float[n](); // error vector rotating backwards @@ -101,7 +101,7 @@ raw_b = new int[n](); float theta_ref = 0; float theta_actual = 0; - float v_d = .05f; // Put volts on the D-Axis + float v_d = V_CAL; // Put volts on the D-Axis float v_q = 0.0f; float v_u, v_v, v_w = 0; float dtc_u, dtc_v, dtc_w = .5f; @@ -122,7 +122,7 @@ } wait_us(100); } - ps->Sample(); + ps->Sample(DT); controller->i_b = I_SCALE*(float)(controller->adc2_raw - controller->adc2_offset); //Calculate phase currents from ADC readings controller->i_c = I_SCALE*(float)(controller->adc1_raw - controller->adc1_offset); controller->i_a = -controller->i_b - controller->i_c; @@ -144,9 +144,9 @@ TIM1->CCR2 = (PWM_ARR>>1)*(1.0f-dtc_w); } wait_us(100); - ps->Sample(); + ps->Sample(DT); } - ps->Sample(); + ps->Sample(DT); theta_actual = ps->GetMechPositionFixed(); error_f[i] = theta_ref/NPP - theta_actual; raw_f[i] = ps->GetRawPosition(); @@ -169,9 +169,9 @@ TIM1->CCR2 = (PWM_ARR>>1)*(1.0f-dtc_w); } wait_us(100); - ps->Sample(); + ps->Sample(DT); } - ps->Sample(); // sample position sensor + ps->Sample(DT); // sample position sensor theta_actual = ps->GetMechPositionFixed(); // get mechanical position error_b[i] = theta_ref/NPP - theta_actual; raw_b[i] = ps->GetRawPosition();