I'm trying to retrieve the ADC value, and I am using the Chip_ADC_ReadValue() method. But he only enters the Handler method once and not always when the input at the ADC pin changes. I am still not totally aware of what I am doing since I am new in programming micro controllers. I hope somebody can help me.
This is my ADC_Init():
static void ADCInit(){
uint32_t _bitRate = 400000;
ADC_RESOLUTION_T _bitAccuracy = ADC_10BITS;
Chip_ADC_Init(LPC_ADC0, &ADCSetup); //Initialize the ADC Pin
Chip_ADC_EnableChannel(LPC_ADC0, ADC_CH1, ENABLE);
Chip_ADC_Int_SetChannelCmd(LPC_ADC0, ADC_CH1, ENABLE);//Enable Channel 1 of the ADC0 Pin for Interrupt
Chip_ADC_SetStartMode(LPC_ADC0, ADC_START_NOW, ADC_TRIGGERMODE_RISING);//Set it to trigger on the rising event, Set Mode on starting the conversion now
Chip_ADC_SetSampleRate(LPC_ADC0, &ADCSetup, _bitRate);//Set the sample rate to 400kHz
Chip_ADC_SetResolution(LPC_ADC0, &ADCSetup, _bitAccuracy);//Set the accuracy to 10 Bits if one is using more channels the accuracy has to be dropped
/*Enable Interrupt*/
NVIC_SetPriority( ADC0_IRQn, (configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY));
NVIC_EnableIRQ( ADC0_IRQn );
}
And this is my Interrupt Handler:
void ADC0_IRQHandler(void)
{
uint16_t dataADC;
/* Interrupt mode: Call the stream interrupt handler */
Chip_ADC_Int_SetChannelCmd(LPC_ADC0, ADC_CH1, ENABLE);
Chip_ADC_ReadValue(LPC_ADC0, ADC_CH1, &dataADC);
SetADCValue(dataADC);
storeItemInfftBuffer(dataADC);
}
Thanks in advance
Hello eugenr,
You can refer to the lpcopen code for mcb 4357, there has the adc code.
http://www.nxp.com/downloads/en/software/lpcopen_3_01_keil_iar_mcb_4357.zip
It seems you didn't enable the burst mode, if yes, the ADC conversions are software controlled, you need to call :
Chip_ADC_SetStartMode(_LPC_ADC_ID, ADC_START_NOW, ADC_TRIGGERMODE_RISING);
After the ADC convert done, then trigger the next adc conversion.
/* Interrupt routine for ADC example */
static void App_Interrupt_Test(void)
{
/* Enable ADC Interrupt */
NVIC_EnableIRQ(_LPC_ADC_IRQ);
Chip_ADC_Int_SetChannelCmd(_LPC_ADC_ID, _ADC_CHANNLE, ENABLE);
/* Enable burst mode if any, the AD converter does repeated conversions
at the rate selected by the CLKS field in burst mode automatically */
if (Burst_Mode_Flag) {
Chip_ADC_SetBurstCmd(_LPC_ADC_ID, ENABLE);
}
Interrupt_Continue_Flag = 1;
ADC_Interrupt_Done_Flag = 1;
while (Interrupt_Continue_Flag) {
if (!Burst_Mode_Flag && ADC_Interrupt_Done_Flag) {
ADC_Interrupt_Done_Flag = 0;
Chip_ADC_SetStartMode(_LPC_ADC_ID, ADC_START_NOW, ADC_TRIGGERMODE_RISING);
}
}
/* Disable burst mode if any */
if (Burst_Mode_Flag) {
Chip_ADC_SetBurstCmd(_LPC_ADC_ID, DISABLE);
}
/* Disable ADC interrupt */
NVIC_DisableIRQ(_LPC_ADC_IRQ);
}
More details, please refer to the lpcopen code, or refer to my attached adc.c file.
If you still have question, please let me know!
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------