Round robin ADC on HVPKV31

cancel
Showing results for 
Search instead for 
Did you mean: 

Round robin ADC on HVPKV31

542 Views
mattschafer
Contributor I

I'm trying to modify the KMS generated code to enable the round robin sampling of analog inputs on our custom board.  I'm looking in the ADCS_getUserSamples function within the HVPKV31F120M_POS_MXP_1_2_0_426 reference code and see a couple potential issues.

1) We have a few inputs using the SExxb side and it looks like the code below won't configure the b input on ADC1 channels.

/* Configure ADC1 to sample the user channel */
 ADC1->CFG2 |= ADC_CFG2_MUXSEL(adc0HWMux);
/* Input channel select. */
 ADC1->SC1[0] = ADC_SC1_ADCH(adc1Channel);

2) The MUXSEL bits appear to be getting bitwise OR into a register bit that was only cleared during the ADC init.  

ADC0->CFG2 |= ADC_CFG2_MUXSEL(adc0HWMux);
Labels (1)
0 Kudos
2 Replies

269 Views
linestream-adam
Senior Contributor I

Matt,

Thanks for pointing these out.  They will be corrected in the next version of KMS.

  1. In the mean time, you can modify that line to use adc1HWMux instead.
  2. I agree that this is a bug. Fortunately, none of the channels used for motor control sampling have alternate (a / b) channels, so an incorrect value in this register doesn't impact the motor control operation.
    In order to correct the bug, I would suggest modifying those lines to the following:
    /* Restore default adc channels for motor control */
     ADC0->CFG2 &= ~(ADC_CFG2_MUXSEL_MASK);
     ADC1->CFG2 &= ~(ADC_CFG2_MUXSEL_MASK);
    This should clear those bits correctly.
0 Kudos

269 Views
philip_drake
NXP Employee
NXP Employee

Because the channel selection between the motor control feedback channels and the other uses of the ADC the sampling code needs to make sure it is sampling the correct channel. Depending on which pins are configured as feedback inputs (set in the kms_hw.h), the reset values may not correctly configure the ADC input channels.  

We need to create a MUX define for the feedback channel selections and use those defines in the code that restores the desired ADC channels for motor control in the ADCS_getUserSamples() function

In general you should structure your code in a way that you mask and set the bits being changed in one C statement. This is more efficient code in that there is only one peripheral write to the peripheral, plus there is not an intermediate value stored in the bits of the control register.  

/* Restore default adc channels for motor control */
ADC0->CFG2 = (ADC0->CFG2 & ~ADC_CFG2_MUXSEL_MASK) | ADC_CFG2_MUXSEL(adc0HWMux);
ADC1->CFG2 = (ADC1->CFG2 & ~ADC_CFG2_MUXSEL_MASK) | ADC_CFG2_MUXSEL(adc1HWMux);‍‍‍‍

This issue was evident in another customers custom hardware development using the KV4x MCU which has a SIM MUX that needed to be set to select the motor control feedback channels. The use of the MCUXpresso config tool to select the ADC inputs created the code to set the ADC MUX in the SIM_ADCOPT register, but did not add code to restore the MUX back to motor feedback channel selections in the ADCS_getUserSamples() function. 

We hope to fix all of this in  the next release of KMS.

Regards,

Philip Drake

0 Kudos