- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Solved! Go to Solution.
- Labels:
-
PSoC 4 MCU
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Kindly see the ADC component datasheet section which specifies the ADC component itself makes use of the interrupt for its working.
You can also check out the call-back functions if you need to do anything after conversion.
Best Regards,
Vasanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Kindly see the ADC component datasheet section which specifies the ADC component itself makes use of the interrupt for its working.
You can also check out the call-back functions if you need to do anything after conversion.
Best Regards,
Vasanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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