1
Dependencies: mbed-dev-f303 FastPWM3
Diff: main.cpp
- Revision:
- 45:aadebe074af6
- Parent:
- 44:efcde0af8390
- Child:
- 47:55bdc4d5096b
--- a/main.cpp Sat Jul 14 22:03:52 2018 +0000 +++ b/main.cpp Mon Jul 30 20:25:24 2018 +0000 @@ -55,7 +55,7 @@ void onMsgReceived() { //msgAvailable = true; - //printf("%.3f %.3f %.3f\n\r", controller.theta_mech, controller.dtheta_mech, controller.i_q); + can.read(rxMsg); if((rxMsg.id == CAN_ID)){ controller.timeout = 0; @@ -162,7 +162,7 @@ controller.adc2_raw = ADC2->DR; // Read ADC Data Registers controller.adc1_raw = ADC1->DR; controller.adc3_raw = ADC3->DR; - spi.Sample(); // sample position sensor + spi.Sample(DT); // sample position sensor controller.theta_elec = spi.GetElecPosition(); controller.theta_mech = (1.0f/GR)*spi.GetMechPosition(); controller.dtheta_mech = (1.0f/GR)*spi.GetMechVelocity(); @@ -273,7 +273,7 @@ break; case 'z': spi.SetMechOffset(0); - spi.Sample(); + spi.Sample(DT); wait_us(20); M_OFFSET = spi.GetMechPosition(); if (!prefs.ready()) prefs.open(); @@ -342,15 +342,16 @@ } int main() { + controller.v_bus = V_BUS; controller.mode = 0; Init_All_HW(&gpio); // Setup PWM, ADC, GPIO wait(.1); gpio.enable->write(1); - TIM1->CCR3 = 0x708*(1.0f); // Write duty cycles - TIM1->CCR2 = 0x708*(1.0f); - TIM1->CCR1 = 0x708*(1.0f); + TIM1->CCR3 = PWM_ARR*(1.0f); // Write duty cycles + TIM1->CCR2 = PWM_ARR*(1.0f); + TIM1->CCR1 = PWM_ARR*(1.0f); zero_current(&controller.adc1_offset, &controller.adc2_offset); // Measure current sensor zero-offset gpio.enable->write(0); reset_foc(&controller); // Reset current controller