interrupt void mainISR(void) { // toggle status LED if(gLEDcnt++ > (uint_least32_t)(USER_ISR_FREQ_Hz / LED_BLINK_FREQ_Hz)) { HAL_toggleLed(halHandle,(GPIO_Number_e)HAL_Gpio_LED2); gLEDcnt = 0; } // acknowledge the ADC interrupt HAL_acqAdcInt(halHandle,ADC_IntNumber_1); // convert the ADC data HAL_readAdcData(halHandle,&gAdcData); // run the controller CTRL_run(ctrlHandle,halHandle,&gAdcData,&gPwmData); // write the PWM compare values HAL_writePwmData(halHandle,&gPwmData); // setup the controller CTRL_setup(ctrlHandle); return; } // end of mainISR() function
interrupt void mainISR(void) { // toggle status LED if(gLEDcnt++ > (uint_least32_t)(USER_ISR_FREQ_Hz / LED_BLINK_FREQ_Hz)) { HAL_toggleLed(halHandle,(GPIO_Number_e)HAL_Gpio_LED2); gLEDcnt = 0; } // acknowledge the ADC interrupt HAL_acqAdcInt(halHandle,ADC_IntNumber_1); // convert the ADC data HAL_readAdcData(halHandle,&gAdcData); // run the controller CTRL_run(ctrlHandle,halHandle,&gAdcData,&gPwmData); // write the PWM compare values HAL_writePwmData(halHandle,&gPwmData); if(FW_getFlag_enableFw(fwHandle) == true) { FW_incCounter(fwHandle); if(FW_getCounter(fwHandle) > FW_getNumIsrTicksPerFwTick(fwHandle)) { _iq refValue; _iq fbackValue; _iq output; FW_clearCounter(fwHandle); refValue = gMotorVars.VsRef; fbackValue = gMotorVars.Vs; FW_run(fwHandle, refValue, fbackValue, &output); CTRL_setId_ref_pu(ctrlHandle, output); gMotorVars.IdRef_A = _IQmpy(CTRL_getId_ref_pu(ctrlHandle), _IQ(USER_IQ_FULL_SCALE_CURRENT_A)); } } else { CTRL_setId_ref_pu(ctrlHandle, _IQmpy(gMotorVars.IdRef_A, _IQ(1.0/USER_IQ_FULL_SCALE_CURRENT_A))); } // setup the controller CTRL_setup(ctrlHandle); return; } // end of mainISR() function
interrupt void mainISR(void) { uint32_t timer0Cnt; uint32_t timer1Cnt; // read the timer 1 value and update the CPU usage module timer1Cnt = HAL_readTimerCnt(halHandle,1); CPU_USAGE_updateCnts(cpu_usageHandle,timer1Cnt); // read the timer 0 value and update the FEM timer0Cnt = HAL_readTimerCnt(halHandle,0); FEM_updateCnts(femHandle,timer0Cnt); FEM_run(femHandle); // toggle status LED if(gLEDcnt++ > (uint_least32_t)(USER_ISR_FREQ_Hz / LED_BLINK_FREQ_Hz)) { HAL_toggleLed(halHandle,(GPIO_Number_e)HAL_Gpio_LED2); gLEDcnt = 0; } // acknowledge the ADC interrupt HAL_acqAdcInt(halHandle,ADC_IntNumber_1); // convert the ADC data HAL_readAdcData(halHandle,&gAdcData); // run the controller CTRL_run(ctrlHandle,halHandle,&gAdcData,&gPwmData); // write the PWM compare values HAL_writePwmData(halHandle,&gPwmData); // setup the controller CTRL_setup(ctrlHandle); // read the timer 1 value and update the CPU usage module timer1Cnt = HAL_readTimerCnt(halHandle,1); CPU_USAGE_updateCnts(cpu_usageHandle,timer1Cnt); // run the CPU usage module CPU_USAGE_run(cpu_usageHandle); return; } // end of mainISR() function
interrupt void mainISR(void) { static uint16_t stCnt = 0; // toggle status LED if(gLEDcnt++ > (uint_least32_t)(USER_ISR_FREQ_Hz / LED_BLINK_FREQ_Hz)) { HAL_toggleLed(halHandle,(GPIO_Number_e)HAL_Gpio_LED2); gLEDcnt = 0; } // acknowledge the ADC interrupt HAL_acqAdcInt(halHandle,ADC_IntNumber_1); // convert the ADC data HAL_readAdcData(halHandle,&gAdcData); // Run the SpinTAC Components if(stCnt++ >= ISR_TICKS_PER_SPINTAC_TICK) { ST_runVelId(stHandle, ctrlHandle); stCnt = 1; } // run the controller CTRL_run(ctrlHandle,halHandle,&gAdcData,&gPwmData); // write the PWM compare values HAL_writePwmData(halHandle,&gPwmData); // setup the controller CTRL_setup(ctrlHandle); if(CTRL_getMotorType(ctrlHandle) == MOTOR_Type_Pm) { // reset Ls Q format to a higher value when Ls identification starts CTRL_resetLs_qFmt(ctrlHandle, gMax_Ls_qFmt); } return; } // end of mainISR() function
interrupt void mainISR(void) { static uint16_t stCnt = 0; // toggle status LED if(gLEDcnt++ > (uint_least32_t)(USER_ISR_FREQ_Hz / LED_BLINK_FREQ_Hz)) { HAL_toggleLed(halHandle,(GPIO_Number_e)HAL_Gpio_LED2); gLEDcnt = 0; } // acknowledge the ADC interrupt HAL_acqAdcInt(halHandle,ADC_IntNumber_1); // convert the ADC data HAL_readAdcData(halHandle,&gAdcData); // Run the SpinTAC Components if(stCnt++ >= ISR_TICKS_PER_SPINTAC_TICK) { ST_runVelPlanTick(stHandle); ST_runVelPlan(stHandle, ctrlHandle); ST_runVelMove(stHandle, ctrlHandle); ST_runVelCtl(stHandle, ctrlHandle); stCnt = 1; } // run the controller CTRL_run(ctrlHandle,halHandle,&gAdcData,&gPwmData); // write the PWM compare values HAL_writePwmData(halHandle,&gPwmData); // setup the controller CTRL_setup(ctrlHandle); return; } // end of mainISR() function
/**************************************************************************** * ADC ISR ***************************************************************************/ void isr_ADC1(void) { // acknowledge the ADC interrupt ADC_clearIntFlag(halHandle->adcHandle, ADC_IntNumber_1); // convert the ADC data HAL_readAdcData(halHandle, &gAdcData); // run the controller CTRL_run(ctrlHandle, halHandle, &gAdcData, &gPwmData); // write the PWM compare values HAL_writePwmData(halHandle, &gPwmData); // setup the controller CTRL_setup(ctrlHandle); return; }
interrupt void mainISR(void) { // toggle status LED if(gLEDcnt++ > (uint_least32_t)(USER_ISR_FREQ_Hz / LED_BLINK_FREQ_Hz)) { HAL_toggleLed(halHandle,(GPIO_Number_e)HAL_Gpio_LED2); gLEDcnt = 0; } // Check if speed reference signal is active // If more than 2000 service routine cycles pass without signal, disable motor if (gSpeedRef_Ok++ > 2000) { gSpeedRef_duty = _IQ(0); gMotorVars.Flag_Run_Identify = 0; gSpeedRef_Ok = 0; } // acknowledge the ADC interrupt HAL_acqAdcInt(halHandle,ADC_IntNumber_1); // convert the ADC data HAL_readAdcData(halHandle,&gAdcData); // run the controller CTRL_run(ctrlHandle,halHandle,&gAdcData,&gPwmData); // write the PWM compare values HAL_writePwmData(halHandle,&gPwmData); // setup the controller CTRL_setup(ctrlHandle); return; } // end of mainISR() function
interrupt void mainISR(void) { _iq angle_pu = 0; _iq speed_pu; _iq speed_ref_pu = TRAJ_getIntValue(((CTRL_Obj *)ctrlHandle)->trajHandle_spd); _iq speed_outMax_pu = TRAJ_getIntValue(((CTRL_Obj *)ctrlHandle)->trajHandle_spdMax); MATH_vec2 Iab_pu; MATH_vec2 Vab_pu; MATH_vec2 Vdq_out_pu; MATH_vec2 Vab_out_pu; MATH_vec2 phasor; // toggle status LED if(gLEDcnt++ > (uint_least32_t)(USER_ISR_FREQ_Hz / LED_BLINK_FREQ_Hz)) { HAL_toggleLed(halHandle,(GPIO_Number_e)HAL_Gpio_LED2); gLEDcnt = 0; } // acknowledge the ADC interrupt HAL_acqAdcInt(halHandle,ADC_IntNumber_1); // convert the ADC data HAL_readAdcData(halHandle,&gAdcData); { uint_least16_t count_isr = CTRL_getCount_isr(ctrlHandle); uint_least16_t numIsrTicksPerCtrlTick = CTRL_getNumIsrTicksPerCtrlTick(ctrlHandle); // if needed, run the controller if(count_isr >= numIsrTicksPerCtrlTick) { CTRL_State_e ctrlState = CTRL_getState(ctrlHandle); bool flag_enableSpeedCtrl; bool flag_enableCurrentCtrl; MATH_vec2 Idq_offset_pu; MATH_vec2 Vdq_offset_pu; // reset the isr count CTRL_resetCounter_isr(ctrlHandle); // run Clarke transform on current CLARKE_run(clarkeHandle_I,&gAdcData.I,&Iab_pu); // run Clarke transform on voltage CLARKE_run(clarkeHandle_V,&gAdcData.V,&Vab_pu); { // run the estimator EST_run(estHandle, \ &Iab_pu, \ &Vab_pu, \ gAdcData.dcBus, \ speed_ref_pu); flag_enableSpeedCtrl = EST_doSpeedCtrl(estHandle); flag_enableCurrentCtrl = EST_doCurrentCtrl(estHandle); } // generate the motor electrical angle angle_pu = EST_getAngle_pu(estHandle); speed_pu = EST_getFm_pu(estHandle); // compute the sin/cos phasor CTRL_computePhasor(angle_pu,&phasor); // set the phasor in the Park transform PARK_setPhasor(parkHandle,&phasor); // run the Park transform PARK_run(parkHandle,&Iab_pu,CTRL_getIdq_in_addr(ctrlHandle)); // set the offset based on the Id trajectory Idq_offset_pu.value[0] = TRAJ_getIntValue(((CTRL_Obj *)ctrlHandle)->trajHandle_Id); Idq_offset_pu.value[1] = _IQ(0.0); Vdq_offset_pu.value[0] = 0; Vdq_offset_pu.value[1] = 0; CTRL_setup_user(ctrlHandle, angle_pu, speed_ref_pu, speed_pu, speed_outMax_pu, &Idq_offset_pu, &Vdq_offset_pu, flag_enableSpeedCtrl, flag_enableCurrentCtrl); // run the appropriate controller if(ctrlState == CTRL_State_OnLine) { // run the online controller CTRL_runPiOnly(ctrlHandle); //,&gAdcData,&gPwmData); // get the controller output CTRL_getVdq_out_pu(ctrlHandle,&Vdq_out_pu); // set the phasor in the inverse Park transform IPARK_setPhasor(iparkHandle,&phasor); // run the inverse Park module IPARK_run(iparkHandle,&Vdq_out_pu,&Vab_out_pu); // run the space Vector Generator (SVGEN) module SVGEN_run(svgenHandle,&Vab_out_pu,&(gPwmData.Tabc)); } else if(ctrlState == CTRL_State_OffLine) { // run the offline controller CTRL_runOffLine(ctrlHandle,halHandle,&gAdcData,&gPwmData); } } else { // increment the isr count CTRL_incrCounter_isr(ctrlHandle); } } // write the PWM compare values HAL_writePwmData(halHandle,&gPwmData); return; } // end of mainISR() function
interrupt void mainISR(void) { static uint16_t stCnt = 0; // toggle status LED if(gLEDcnt++ > (uint_least32_t)(USER_ISR_FREQ_Hz / LED_BLINK_FREQ_Hz)) { HAL_toggleLed(halHandle,(GPIO_Number_e)HAL_Gpio_LED2); gLEDcnt = 0; } // acknowledge the ADC interrupt HAL_acqAdcInt(halHandle,ADC_IntNumber_1); // convert the ADC data HAL_readAdcData(halHandle,&gAdcData); // run the current reconstruction algorithm SVGENCURRENT_RunRegenCurrent(svgencurrentHandle, (MATH_vec3 *)(gAdcData.I.value)); // Run the SpinTAC Components if(stCnt++ >= ISR_TICKS_PER_SPINTAC_TICK) { ST_runVelMove(stHandle, ctrlHandle); ST_runVelCtl(stHandle, ctrlHandle); stCnt = 1; } // run the controller CTRL_run(ctrlHandle,halHandle,&gAdcData,&gPwmData); // write the PWM compare values HAL_writePwmData(halHandle,&gPwmData); // run the current ignore algorithm { uint16_t pwmValue_1 = HAL_readPwmCmpA(halHandle,PWM_Number_1); uint16_t pwmValue_2 = HAL_readPwmCmpA(halHandle,PWM_Number_2); uint16_t pwmValue_3 = HAL_readPwmCmpA(halHandle,PWM_Number_3); // run the current ignore algorithm SVGENCURRENT_RunIgnoreShunt(svgencurrentHandle,pwmValue_1,pwmValue_2,pwmValue_3); } // Set trigger point in the middle of the low side pulse HAL_setTrigger(halHandle,SVGENCURRENT_getMinWidth(svgencurrentHandle)); if(FW_getFlag_enableFw(fwHandle) == true) { FW_incCounter(fwHandle); if(FW_getCounter(fwHandle) > FW_getNumIsrTicksPerFwTick(fwHandle)) { _iq refValue; _iq fbackValue; _iq output; FW_clearCounter(fwHandle); refValue = gMotorVars.VsRef; fbackValue = gMotorVars.Vs; FW_run(fwHandle, refValue, fbackValue, &output); CTRL_setId_ref_pu(ctrlHandle, output); gMotorVars.IdRef_A = _IQmpy(CTRL_getId_ref_pu(ctrlHandle), _IQ(USER_IQ_FULL_SCALE_CURRENT_A)); } } else { CTRL_setId_ref_pu(ctrlHandle, _IQmpy(gMotorVars.IdRef_A, _IQ(1.0/USER_IQ_FULL_SCALE_CURRENT_A))); } // setup the controller CTRL_setup(ctrlHandle); return; } // end of mainISR() function
interrupt void mainISR(void) { static uint16_t stCnt = 0; // toggle status LED if(gLEDcnt++ > (uint_least32_t)(USER_ISR_FREQ_Hz / LED_BLINK_FREQ_Hz)) { HAL_toggleLed(halHandle,(GPIO_Number_e)HAL_Gpio_LED2); gLEDcnt = 0; } // acknowledge the ADC interrupt HAL_acqAdcInt(halHandle,ADC_IntNumber_1); // convert the ADC data HAL_readAdcData(halHandle,&gAdcData); // Run the SpinTAC Components if(stCnt++ >= ISR_TICKS_PER_SPINTAC_TICK) { ST_runVelCtl(stHandle, ctrlHandle); stCnt = 1; } // run the controller CTRL_run(ctrlHandle,halHandle,&gAdcData,&gPwmData); // write the PWM compare values HAL_writePwmData(halHandle,&gPwmData); if (!(SpeedRef_krpm_previous == gMotorVars.SpeedRef_krpm)) { Graph_Flag_Enable_update = true; Graph_Counter = 0; SpeedRef_krpm_previous = gMotorVars.SpeedRef_krpm; } gMotorVars.Iq_A = _IQmpy(CTRL_getIq_in_pu(ctrlHandle), _IQ(USER_IQ_FULL_SCALE_CURRENT_A)); // store graph value if(Graph_Flag_Enable_update) { if(Graph_Counter >= GRAPH_SIZE) { Graph_Flag_Enable_update = false; } else { if(Graph_Tick_Counter == 0) { Graph_Data[Graph_Counter] = gMotorVars.Speed_krpm; Graph_Data2[Graph_Counter] = gMotorVars.Iq_A; Graph_Counter++; Graph_Tick_Counter = Graph_Tick_Counter_Value - 1; } else { Graph_Tick_Counter--; } } } // setup the controller CTRL_setup(ctrlHandle); return; } // end of mainISR() function