ADC problem with ISR

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
giu83
Level 1
Level 1
First reply posted First question asked Welcome!

Hi.

I am new with Psoc products and I create a simple project that read voltage from a pin (P0.5) with 10 bit ADC. The micro is CY8C4045LQI-S412.

main.c

int main(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
ADC_1_Start();
while(ADC_1_IsBusy()!=ADC_1_STATUS_IDLE);
ADC_1_ISR_Start();
ADC_1_StartConvert(0);

/* Place your initialization/startup code here (e.g. MyInst_Start()) */

for(;;)
{
/* Place your application code here. */
}
}

ADC_1_ISR.c

CY_ISR(ADC_1_ISR_Interrupt)
{ uint16 voltage;
#ifdef ADC_1_ISR_INTERRUPT_INTERRUPT_CALLBACK
ADC_1_ISR_Interrupt_InterruptCallback();
#endif /* ADC_1_ISR_INTERRUPT_INTERRUPT_CALLBACK */

/* Place your Interrupt code here. */
/* `#START ADC_1_ISR_Interrupt` */
while(ADC_1_IsBusy()!=ADC_1_STATUS_IDLE);
voltage=ADC_1_GetResult_mVolts(0);
ADC_1_ISR_ClearPending();
/* `#END` */
}

The ADC status remain in "converting" (0x40) in the while loop. And also... without while loop check, after clearpending the interrupt routine is invoked continuously.

Whitout interrupt, if I use ADC_1_ReadResult_mVolts or ADC_1_StartConvert + ADC_1_IsBusy + ADC_1_GetResult_mVolts, the voltage is read correctly.

What is the problem in the code above?

Thanks a lot.

Best regards

0 Likes
1 Solution
Vasanth
Moderator
Moderator
Moderator
250 sign-ins 500 solutions authored First question asked

Hi,

Kindly see the ADC component datasheet section which specifies the ADC component itself makes use of the interrupt for its working.

 

Vasanth_0-1633525284591.png

You can also check out the call-back functions if you need to do anything after conversion.

Best Regards,
Vasanth

View solution in original post

0 Likes
3 Replies
Vasanth
Moderator
Moderator
Moderator
250 sign-ins 500 solutions authored First question asked

Hi,

Kindly see the ADC component datasheet section which specifies the ADC component itself makes use of the interrupt for its working.

 

Vasanth_0-1633525284591.png

You can also check out the call-back functions if you need to do anything after conversion.

Best Regards,
Vasanth

0 Likes
giu83
Level 1
Level 1
First reply posted First question asked Welcome!

Hi Vasanth,

I have added declaration and macro define in cyapicallbacks.h. Also I have added the definition of  the function in main.c.
I perform ADC_1_StartConvert every 4 seconds but the callback function never be called.

cyapicallbacks.h

#ifndef CYAPICALLBACKS_H
#define CYAPICALLBACKS_H

/*Define your macro callbacks here */
/*For more information, refer to the Writing Code topic in the PSoC Creator Help.*/
#define ADC_EXIT_CALLBACK
void ADC_ExitCallback();

#endif /* CYAPICALLBACKS_H */

0 Likes
Vasanth
Moderator
Moderator
Moderator
250 sign-ins 500 solutions authored First question asked

Hi,

Macro Callbacks is a term defined in PSoC Creator to call user code from macros specified in a Component's generated code. These macros can be used by defining them in the user-defined header file named cyapicallbacks.h. This file will be included in all generated source files that offer callbacks.

A callback requires you to complete the following:

1.Define a macro to signal the presence of a callback (in cyapicallbacks.h).

2.Write the function declaration (in cyapicallbacks.h).

3.Write the function implementation (in any user file).

To complete the example, the cyapicallbacks.h file would include this code:

#define SimpleComp_1_START_CALLBACK

void SimpleComp_1_Start_Callback( void );

In any other user file, you could include cyapicallbacks.h and write the SimpleComp_1_Start_Callback() function.

Best Regards,
Vasanth

0 Likes