KV56 HSADC Does Not Seem To Be Converting Correctly

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

KV56 HSADC Does Not Seem To Be Converting Correctly

Jump to solution
927 Views
derekcook
Senior Contributor I

I followed the twrkv58f220m_hsadc_dual_parallel_conversion example for my own project but did not do a differential conversion and the HSADCs do not seem to be converting correctly. I am using the KV56 100 pin part. I expect 2048 counts on Ph A, B, and C below and the voltage matches what I'd expect for 2048 counts but I am getting around 4095 counts. Same below with Dc bus voltage below. I expect 0 counts but seem to be getting a few counts making the voltage reading noisy. 

These are the pins I am using:

PinNamePin selectionHSADC connection
18AHSADC1A_CH2 / HSADC0A_CH2HSADC0A_CH2 / HSADC1A_CH2
20BHSADC1B _CH2 / HSADC0A_CH10HSADC0A_CH6 mux ch10 / HSADC1B_CH2
PTB0CHSADC0B _CH2HSADC0B_CH2
PTB2DCHSADC0A _CH14HSADC0A_CH6 mux ch 14

Below is my code - (I originally tried to use 2 channels on HSDC0 and 2 channels on HSADC1 but I commented out HSADC1 because I thought maybe that approach was causing issues).

Init function: 

HSADC_GetDefaultConfig(&hsadcConfigStruct);
HSADC_Init(HSADC0_BASEADDR, &hsadcConfigStruct);
//HSADC_Init(HSADC1_BASEADDR, &hsadcConfigStruct);

/* Configure each converter. */
HSADC_GetDefaultConverterConfig(&hsadcConverterConfigStruct);
hsadcConverterConfigStruct.powerUpCalibrationModeMask = kHSADC_CalibrationModeSingleEnded;
hsadcConverterConfigStruct.clockDivisor = 3U;

/* Enable the calibration in power up period. */
HSADC_SetConverterConfig(HSADC0_BASEADDR, kHSADC_ConverterA | kHSADC_ConverterB, &hsadcConverterConfigStruct);
//HSADC_SetConverterConfig(HSADC1_BASEADDR, kHSADC_ConverterA | kHSADC_ConverterB, &hsadcConverterConfigStruct);

/* Enable the power for each converter. */
HSADC_EnableConverterPower(HSADC0_BASEADDR, kHSADC_ConverterA | kHSADC_ConverterB, true);
//HSADC_EnableConverterPower(HSADC1_BASEADDR, kHSADC_ConverterA | kHSADC_ConverterB, true);
while (
(kHSADC_ConverterAPowerDownFlag | kHSADC_ConverterBPowerDownFlag) ==
((kHSADC_ConverterAPowerDownFlag | kHSADC_ConverterBPowerDownFlag) & HSADC_GetStatusFlags(HSADC0_BASEADDR)))
{
}

/* Wait the calibration process complete. None End of Scan flag will be set after power up calibration process. */
while ((kHSADC_ConverterAEndOfCalibrationFlag | kHSADC_ConverterBEndOfCalibrationFlag) !=
((kHSADC_ConverterAEndOfCalibrationFlag | kHSADC_ConverterBEndOfCalibrationFlag) &
HSADC_GetStatusFlags(HSADC0_BASEADDR)))
{
}
// while (
// (kHSADC_ConverterAPowerDownFlag | kHSADC_ConverterBPowerDownFlag) ==
// ((kHSADC_ConverterAPowerDownFlag | kHSADC_ConverterBPowerDownFlag) & HSADC_GetStatusFlags(HSADC1_BASEADDR)))
// {
// }

HSADC_ClearStatusFlags(HSADC0_BASEADDR,
(kHSADC_ConverterAEndOfCalibrationFlag | kHSADC_ConverterBEndOfCalibrationFlag));
//
// HSADC_ClearStatusFlags(HSADC1_BASEADDR,
// (kHSADC_ConverterAEndOfCalibrationFlag | kHSADC_ConverterBEndOfCalibrationFlag));

/* Make each converter exit stop mode. */
HSADC_EnableConverter(HSADC0_BASEADDR, kHSADC_ConverterA | kHSADC_ConverterB, true);
// HSADC_EnableConverter(HSADC1_BASEADDR, kHSADC_ConverterA | kHSADC_ConverterB, true);

ret = ConfigureFastADCSamples();

Function to configure the channels:

/* Configure the samples. */
HSADC_GetDefaultSampleConfig(&hsadcSampleConfigStruct);

/* For converter HSADC0 Conv A. */
// HSADC0A_CH14 (CH6 mux 4)
hsadcSampleConfigStruct.channelNumber = DCBUSV_HSADC0A_CH6_CHANNEL_NUM1;
hsadcSampleConfigStruct.channel67MuxNumber = DCBUSV_HSADC0A_CH6_CHANNEL67_NUM1_MUXNUM;
hsadcSampleConfigStruct.enableDifferentialPair = 0;//DCBUSV_HSADC0A_CH6_CHANNEL67_NUM1_ENABLE_DIFF;
// hsadcSampleConfigStruct.offsetValue = 0;
HSADC_SetSampleConfig(HSADC0_BASEADDR, 0U, &hsadcSampleConfigStruct);

/* For converter HSADC1 Conv A. */
// HSADC0A CH2
hsadcSampleConfigStruct.channelNumber = PHA_HSADC1A_CH2_CHANNEL_NUM1;
hsadcSampleConfigStruct.channel67MuxNumber = PHA_HSADC1A_CH2_CHANNEL67_NUM1_MUXNUM;
hsadcSampleConfigStruct.enableDifferentialPair = 0;//PHA_HSADC1A_CH2_CHANNEL67_NUM1_ENABLE_DIFF;
//hsadcSampleConfigStruct.offsetValue = MOTOR_PHASE_OFFSET;
HSADC_SetSampleConfig(HSADC0_BASEADDR, 1U, &hsadcSampleConfigStruct);

/* For converter HSADC0 Conv B. */
/* For converter B.
* In HSADC_SetSampleConfig(), the channel number 0~7 represents input 0~7 of converter A and channel number 8~15
* represents input 0~7 of converter B.
*/
// HSADC0B_CH2
hsadcSampleConfigStruct.channelNumber = (PHC_HSADC0B_CH2_CHANNEL_NUM1 + 8U);
hsadcSampleConfigStruct.channel67MuxNumber = PHC_HSADC0B_CH2_CHANNEL67_NUM1_MUXNUM;
hsadcSampleConfigStruct.enableDifferentialPair = 0; //PHC_HSADC0B_CH2_CHANNEL67_NUM1_ENABLE_DIFF;
//hsadcSampleConfigStruct.offsetValue = MOTOR_PHASE_OFFSET;
HSADC_SetSampleConfig(HSADC0_BASEADDR, 8U, &hsadcSampleConfigStruct);

// /* For converter HSADC1 Conv B. */
// /* For converter B.
// * In HSADC_SetSampleConfig(), the channel number 0~7 represents input 0~7 of converter A and channel number 8~15
// * represents input 0~7 of converter B.
// */
// hsadcSampleConfigStruct.channelNumber = (PHB_HSADC1B_CH2_CHANNEL_NUM1 + 8U);
// hsadcSampleConfigStruct.channel67MuxNumber = PHB_HSADC1B_CH2_CHANNEL67_NUM1_MUXNUM;
// hsadcSampleConfigStruct.enableDifferentialPair = 0; //PHB_HSADC1B_CH2_CHANNEL67_NUM1_ENABLE_DIFF;
// //hsadcSampleConfigStruct.offsetValue = MOTOR_PHASE_OFFSET;
// HSADC_SetSampleConfig(HSADC1_BASEADDR, PHB_HSADC1B_SAMPLE_NUM, &hsadcSampleConfigStruct);

uint16_t sampleMaskRet = HSADC_SAMPLE_MASK(0U) /* For converter A. */
| HSADC_SAMPLE_MASK(1U) /* For converter A. */
| HSADC_SAMPLE_MASK(8U) /* For converter B. */
| HSADC_SAMPLE_MASK(9U); /* For converter B. */
HSADC_EnableSample(HSADC0_BASEADDR, sampleMaskRet, true);
HSADC_EnableSample(HSADC0_BASEADDR, (uint16_t)(~sampleMaskRet), false); /* Disable other sample slots. */

Trigger a conversion:

void TriggerFastADCConversion()
{
// Block while we manually trigger ADC conversion for fast samples
// Using HSADC this will only block for 900ns with a 75MHz clock selection
/* Trigger the converter.
* Trigger converter A would execute both converter's conversion when in
* "kHSADC_DualConverterWorkAsTriggeredParallel" and simultaneous work mode.
*/

uint16_t status = 0;

HSADC_DoSoftwareTriggerConverter(HSADC0_BASEADDR, kHSADC_ConverterA);
//HSADC_DoSoftwareTriggerConverter(HSADC1_BASEADDR, kHSADC_ConverterA);

/* Wait the conversion to be done. */
while (kHSADC_ConverterAEndOfScanFlag !=
(kHSADC_ConverterAEndOfScanFlag & HSADC_GetStatusFlags(HSADC0_BASEADDR)))
{
}

// /* Wait the conversion to be done. */
// while (kHSADC_ConverterAEndOfScanFlag !=
// (kHSADC_ConverterAEndOfScanFlag & HSADC_GetStatusFlags(HSADC1_BASEADDR)))
// {
// }
}

And then to read the result: 


void MCDRV_RawAdcGet(GE_Primary_Container_t *pContainer)
{
int16_t phARaw = 0;
int16_t phBRaw = 0;
int16_t phCRaw = 0;
int16_t dcBus_Raw = 0;

if (sampleMask == (sampleMask & HSADC_GetSampleReadyStatusFlags(HSADC0_BASEADDR)))
{
phARaw = ((int16_t) (HSADC_GetSampleResultValue(HSADC0_BASEADDR, 1U) & 0x0FFF));
phBRaw = ((int16_t) (HSADC_GetSampleResultValue(HSADC0_BASEADDR, 9U) & 0x0FFF));
phCRaw = ((int16_t) (HSADC_GetSampleResultValue(HSADC0_BASEADDR, 8U) & 0x0FFF));
dcBus_Raw = ((int16_t) (HSADC_GetSampleResultValue(HSADC0_BASEADDR, 0U) & 0x0FFF));
}

pContainer->mpDrive->mAcPMSMController.mDcBusRaw = dcBus_Raw;

pContainer->mpDrive->mAcPMSMController.m3PhABCRaw.PhA = phARaw;
pContainer->mpDrive->mAcPMSMController.m3PhABCRaw.PhB = phBRaw;
pContainer->mpDrive->mAcPMSMController.m3PhABCRaw.PhC = phCRaw;
}

 

0 Kudos
1 Solution
915 Views
derekcook
Senior Contributor I

I think I figured this out - my ADC was only reading 0 to 0.38V and then rolling over. The problem was that I did not realize the format of the RESULT register: 

derekcook_0-1657220210014.png

 

 

The ADC conversion is shifted left by 3 bits. Therefore, I need to shift the value right by 3 bits to read 12 bit 0 to 4095 number. 

View solution in original post

0 Kudos
1 Reply
916 Views
derekcook
Senior Contributor I

I think I figured this out - my ADC was only reading 0 to 0.38V and then rolling over. The problem was that I did not realize the format of the RESULT register: 

derekcook_0-1657220210014.png

 

 

The ADC conversion is shifted left by 3 bits. Therefore, I need to shift the value right by 3 bits to read 12 bit 0 to 4095 number. 

0 Kudos