Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LPC54628: Update the ADC clock divider based on the input clock source #7201

Merged
merged 1 commit into from Jun 18, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -30,9 +30,13 @@ static ADC_Type *const adc_addrs[] = ADC_BASE_PTRS;
extern void ADC_ClockPower_Configuration(void);

#define MAX_FADC 6000000
#define MAX_ADC_CLOCK 80000000

void analogin_init(analogin_t *obj, PinName pin)
{
uint32_t clkval;
uint32_t clkdiv = 1;

obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
MBED_ASSERT(obj->adc != (ADCName)NC);

Expand All @@ -42,23 +46,29 @@ void analogin_init(analogin_t *obj, PinName pin)
uint32_t pin_number = pin & 0x1F;
uint8_t port_number = pin / 32;

/* Clear the DIGIMODE bit */
reg = IOCON->PIO[port_number][pin_number] & ~IOCON_PIO_DIGIMODE_MASK;
IOCON->PIO[port_number][pin_number] = reg;

ADC_ClockPower_Configuration();

/* Ensure the ADC clock derived from the system clock is less than 80MHz */
clkval = CLOCK_GetFreq(kCLOCK_CoreSysClk);
while ((clkval / clkdiv) > MAX_ADC_CLOCK) {
clkdiv++;
}

/* Calibration after power up. */
if (!(ADC_DoSelfCalibration(adc_addrs[instance]))) {
/* Calibration failed */
return;
}

ADC_GetDefaultConfig(&adc_config);
adc_config.clockDividerNumber = 1;
adc_config.clockDividerNumber = clkdiv;

ADC_Init(adc_addrs[instance], &adc_config);
pinmap_pinout(pin, PinMap_ADC);

/* Clear the DIGIMODE bit */
reg = IOCON->PIO[port_number][pin_number] & ~IOCON_PIO_DIGIMODE_MASK;
IOCON->PIO[port_number][pin_number] = reg;
}

uint16_t analogin_read_u16(analogin_t *obj)
Expand All @@ -70,7 +80,7 @@ uint16_t analogin_read_u16(analogin_t *obj)

adcConvSeqConfigStruct.channelMask = (1U << channel);
adcConvSeqConfigStruct.triggerMask = 0U;
adcConvSeqConfigStruct.triggerPolarity = kADC_TriggerPolarityNegativeEdge;
adcConvSeqConfigStruct.triggerPolarity = kADC_TriggerPolarityPositiveEdge;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any partricular reason why this polarity flip was needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to match the values set inside the MCUXpresso SDK examples.

adcConvSeqConfigStruct.enableSingleStep = false;
adcConvSeqConfigStruct.enableSyncBypass = false;
adcConvSeqConfigStruct.interruptMode = kADC_InterruptForEachSequence;
Expand Down