Hi,
I want to use ADC module to get AMP0 and AN1_0 in BLDC_sensorless example code.
My codes are like this,
void initGDU()
{
GDUE_GCSE0 = 1; // enable Current Sense Amplifier 0
}
void initGPIO(void)
{
DDRADH_DDRADH0 = 1; /*AN1_3 set*/
PTAD_PTADH0 = 1;
}
volatile short PTUTriggerEventList[PTU_TOT_TRIGGERs_GEN_NO][PTU_TOT_LISTS_NO][4] ={
{ /*DelayT0 */
{0x0100, 0x0200, 0x0000, 0x0000}, {0x0000, 0x0000, 0x0000, 0x0000}
},
{
{0x0100, 0x0200, 0x0000, 0x0000}, {0x0000, 0x0000, 0x0000, 0x0000}
}
};
volatile char ADC0CommandList[6][4] = {
{ 0x40, 0xD0, 0x00, 0x00 }, // current sense channel, end of sequence [D0]
{ 0xC0, 0xCB, 0x00, 0x00 }, // end of list + no int [C0], HD voltage [CB], 4 clock cycles sample time [00], reserved [00]
{ 0x00, 0x00, 0x00, 0x00 },
{ 0x00, 0x00, 0x00, 0x00 },
{ 0x00, 0x00, 0x00, 0x00 },
{ 0x00, 0x00, 0x00, 0x00 } };
PR_SECTION(adcLists)
volatile char ADC1CommandList[6][4] = {
{ 0x40, 0xCA, 0x00, 0x00 }, // [end of list] + no int [C0], phase voltage [CA], 4 clock cycles sample time [00]
{ 0xC0, 0x50, 0x00, 0x00 }, // ADC1 AN1_0
{ 0x00, 0x00, 0x00, 0x00 },
{ 0x00, 0x00, 0x00, 0x00 },
{ 0x00, 0x00, 0x00, 0x00 },
{ 0x00, 0x00, 0x00, 0x00 } };
volatile unsigned short ADC0ResultList[6] = { 0, 0, 0, 0, 0, 0 };
volatile unsigned short ADC1ResultList[6] = { 0, 0, 0, 0, 0, 0 };
void UpdateDutycycle(void) {
tU16 delay1, delay2;
PMFVAL0 = duty_cycle;
delay1 = duty_cycle >> 2; // middle of the pulse - DC Bus current
if (delay1 < MIN_ADC_TRIGGER_FIRST)
delay1 = MIN_ADC_TRIGGER_FIRST;
PTUTriggerEventList[0][0][0] = delay1;
delay2 = MLIB_Mul(duty_cycle,BEMF_SENSING_POINT_FRAC,F16); // end of the pulse
if (delay2 < MIN_ADC_TRIGGER_FIRST)
delay2 = MIN_ADC_TRIGGER_FIRST;
PTUTriggerEventList[1][0][0] = delay2; // ADC1 - phase voltage
if (delay2 < (delay1 + MIN_ADC_TRIGGER_SECOND))
delay2 = delay1 + MIN_ADC_TRIGGER_SECOND;
PTUTriggerEventList[0][0][1] = delay2; // ADC0 second sample - DC Bus Voltage
PTUTriggerEventList[1][0][1] = delay2+35;
PTUC_PTULDOK = 1;
}
It looks like that the ADC values are measured, but the BLDC motor is not rotating normally(repeat stop and go).
what's the problem of my code?? I beg your opinion.