Test the set param mode
Diff: FOC/foc.cpp
- Revision:
- 52:8e74c22ed89f
- Parent:
- 51:6cd89bd6fcaa
--- a/FOC/foc.cpp Wed Jul 17 03:40:12 2019 +0000 +++ b/FOC/foc.cpp Sun Jul 21 21:42:49 2019 +0000 @@ -65,18 +65,18 @@ void zero_current(int *offset_1, int *offset_2){ // Measure zero-offset of the current sensors int adc1_offset = 0; int adc2_offset = 0; - int n = 1024; + int n = 2048; for (int i = 0; i<n; i++){ // Average n samples of the ADC TIM1->CCR3 = (PWM_ARR>>1)*(1.0f); // Write duty cycles TIM1->CCR2 = (PWM_ARR>>1)*(1.0f); TIM1->CCR1 = (PWM_ARR>>1)*(1.0f); ADC1->CR2 |= 0x40000000; // Begin sample and conversion - wait(.001); + wait(.0001); adc2_offset += ADC2->DR; adc1_offset += ADC1->DR; } - *offset_1 = adc1_offset/n; - *offset_2 = adc2_offset/n; + *offset_1 = (int)((float)adc1_offset/(float)n); + *offset_2 = (int)((float)adc2_offset/(float)n); } void init_controller_params(ControllerStruct *controller){ @@ -196,8 +196,8 @@ limit_norm(&controller->v_d, &controller->v_q, OVERMODULATION*controller->v_bus); // Normalize voltage vector to lie within curcle of radius v_bus float dtc_d = controller->v_d/controller->v_bus; float dtc_q = controller->v_q/controller->v_bus; - linearize_dtc(&dtc_d); - linearize_dtc(&dtc_q); + //linearize_dtc(&dtc_d); + //linearize_dtc(&dtc_q); controller->v_d = dtc_d*controller->v_bus; controller->v_q = dtc_q*controller->v_bus; abc(controller->theta_elec + 0.0f*DT*controller->dtheta_elec, controller->v_d, controller->v_q, &controller->v_u, &controller->v_v, &controller->v_w); //inverse dq0 transform on voltages