Too many IRQs for ADC (LPC4078)

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

Too many IRQs for ADC (LPC4078)

688 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by g_mocken on Tue Feb 02 08:51:56 MST 2016
Following the sample code and docs, I initialize the AD conversion roughly like the following:

static ADC_CLOCK_SETUP_T ADCSetup;
Chip_ADC_Init(LPC_ADC, &ADCSetup);
Chip_ADC_EnableChannel(LPC_ADC, _ADC_CHANNEL, ENABLE);
Chip_ADC_SetBurstCmd(LPC_ADC, ENABLE);
Chip_ADC_SetStartMode(LPC_ADC, ADC_NO_START, ADC_TRIGGERMODE_RISING);
Chip_ADC_SetSampleRate(LPC_ADC, &ADCSetup, 1000); // <-- sample rate 1000 Hz

NVIC_EnableIRQ(ADC_IRQn);
Chip_ADC_Int_SetChannelCmd(LPC_ADC, _ADC_CHANNEL, ENABLE);


My ISR looks like this:

uint16_t dataADC;
Chip_ADC_ReadValue(LPC_ADC, _ADC_CHANNEL, &dataADC);
NVIC_ClearPendingIRQ(ADC_IRQn);

The result however is (I checked by toggeling a GPIO line and using a scope) that the ISR is called at a rate of around 6379 Hz instead of 1000 Hz (as configured). The ADC samples themselves are correct.

When I vary the sample rate in Chip_ADC_SetSampleRate(), the IRQ rate also changes, but the relation between the two does not make much sense (e.g. twice the rate: 2000 Hz result in measured 4560 Hz)

Is there something wrong in the clock setup or is there any additional IRQ register that I need to clear in the ISR (to preventing it from being called several times for the same IRQ)?

Any hints would be appreciated,

G.
Labels (1)
0 Kudos
Reply
1 Reply

607 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by g_mocken on Thu Feb 04 04:09:20 MST 2016
Problem identified:

Chip_ADC_SetSampleRate() calls getClkDiv(). The latter does not return anything useful, if the desired rate cannot be achieved with the current peripheral clock, as it is the case here:
1kHz desired, meaning a ADC clock of 31kHz.
With PCLK=60 Mhz and a maximum divider of 256 we get 60 Mhz / 256 = 234kHz >> 31 kHz.

Lowering PCLK to 8 Mhz  would probably work (but would seriously affect other peripherals). I have now resorted to using a software timer and the ADC in non-Burst mode (i.e. single shots).

I would still suggest to change Chip_ADC_SetSampleRate() and let it return the actually achieved sample rate (or at least return an error in such a case as mine).
0 Kudos
Reply