# 56F8367EVM  - motor control calculation time "overflow"

Discussion created by Kristof Geldhof on Sep 10, 2007
Latest reply on Sep 11, 2007 by Pascal Irrle
Hello,

I implemented a simple (proportional) controller to control the current in an inductor. For this goal I used a PWM-triggered timer bean, which triggers the ADC of a 56F8367EVM evaluation board. I wrote a few lines of code in the ADC_OnEnd interrupt routine in order to calculate the duty ratio for the next PWM period:

void AD1_OnEnd(void)
{
unsigned int   AdcSample,AdcSample_corr;
byte                i;

// read ADC result
if (AD1_GetChanValue(0,&AdcSample)!=ERR_OK) {asm(debughlt);}

// Correct linearity and offset of analog measuring circuit and ADC
AdcSample_corr=sub(AdcSample,ADC_offset);
i_measured=mult(AdcSample_corr,ADC_to_current);

// current control: calculate duty cycle for next PWM period
Duty=controllerP(i_desired,i_measured,&currentCtrlPIprm);
fault=PWMC1_SetDuty(2,Duty.ValHigh);
fault=PWMC1_SetDuty(3,Duty.ValLow);

// Test pulse (GPIO_C bit 3)
i=5;
GPIO_C_DR=0x0008;
while (i--){asm{nop;}}
GPIO_C_DR&=~0x0008;

// load PWM values
PWMC1_Load();
}

The function "controllerP" performs a multiplication of (i_desired-i_measured) with a constant factor. With the help of the test pulse and a scope I found that the execution of this routine takes about 25 us. This seems a lot to me for a few simple calculations. The PWM-period is 125 us. As the ADC samples halfway the PWM period, only 125/2-25=37.5 would be still available for other calculations. As I plan to implement a sensorless control, the computational overhead would certainly become too big I assume...

Is this great computational burden normal? Is it because I'm running in debug mode?

Thanks for any help.
Kristof Geldhof

used products: evaluation module 56F8367EVM, CodeWarrior version 5.6.1.

--
Alban Edit: Please always include FSL Part Number in Message Subject line.

Message Edited by Alban on 2007-09-12 12:02 AM