6 posts / 0 new
Last post
Kostakis
Offline
Last seen:3 years 3 weeks ago
Joined:2015-01-20 16:15
ADC Interrupt

Hi. Is there any example of using adc interrupt?

VesaN
Offline
Last seen:5 years 7 months ago
Guru Master
Joined:2014-06-26 08:49
Hello Kostakis,

Hello Kostakis,

I'm not totally sure, but if you see into the asm fileboot_vectors.syou can see that it exportsEXPORT ADC_Handler [WEAK]

  1. You can use this function in your driver(?) file by just implementing it there like this:

    void ADC_Handler(void) {
    uint16_t conversion = GetWord16(GP_ADC_RESULT_REG);
    // do required things with the conversion, maybe pass to other function etc...
    SetWord16 (GP_ADC_CLEAR_INT_REG 0 x0000);/ /我瘦k interrupt should be cleared
    }
  2. Enable ADC interrupts:

    NVIC_SetPriority(ADC_IRQn, 2);
    NVIC_EnableIRQ(ADC_IRQn);
  3. Initialize ADC (maybe inperiph_setup.c?):

    adc_init(GP_ADC_SE, 0, GP_ADC_ATTN3X); // For single ended 3x attentuation, for example
    SetBits16(GP_ADC_CTRL_REG, GP_ADC_MINT, 1); // Important, or otherwise interrupt will be masked away
  4. Then, perform read with ADC:

    SetBits16(GP_ADC_CTRL_REG, GP_ADC_START, 1);

I'm not totally sure if something is missing/incomplete. Maybe you should disable adc interrupts while you are executing the handler function.

Thanks!

Bharath
Offline
Last seen:1 year 5 months ago
Joined:2016-04-14 07:03
I want to use the same

I want to use the same method.
Can you tell me what is GP_ADC_CLK_SEL and how to set it ?
I tried the above code and it is not generating any interrupt.

Please help me out.

Thanks
Bharath

MT_dialog
Offline
Last seen:2 months 2 weeks ago
Staff
Joined:2015-06-08 11:34
Hi Bharath,

Hi Bharath,

The steps mentioned above are correct, and should trigger an interrupt, make sure that you 've enabled the NVIC for the specified interrupt and also make sure that the interrupts are enabled by the SetBits16(GP_ADC_CTRL_REG, GP_ADC_MINT, 1);, call the enabling of the interrupt just before taking a measurement, this should trigger the interrupt.

Thanks MT_dialog

Bharath
Offline
Last seen:1 year 5 months ago
Joined:2016-04-14 07:03
It only triggered interrupt

It only triggered interrupt once. Why it is not repeating?
How to make it repeat at a particular rate?

Thanks
Bharath

MT_dialog
Offline
Last seen:2 months 2 weeks ago
Staff
Joined:2015-06-08 11:34
Hi Bharath,

Hi Bharath,

You have to explictly start the ADC conversion every time you want to make a measurement, the ADC doesn't free run. If you check the 580 datasheet you will see that the after the conversion is over the GP_ADC_START register flips to 0 and the interrupt bit is set.

Thanks MT_dialog