- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello, I am running a very basic application of varying input voltage into an ADC and changing the LED color based on the voltage range. I keep receiving an error about not being able to define my variable adcSample (which is the result from the ADC).
int main()
{
/* Initialize ADC. Conversion is not enabled yet. */
void ADC_Start();
/* Start ADC conversion. */
void ADC_StartConvert();
adcSample = ADC_GetResult16(uint32 0)
Solved! Go to Solution.
- Labels:
-
BLE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I cannot see a line like
uint16 adcSample;
or
int adcSample;
Additionally: You did not check whether a conversion result is already availlable. Check your ADC datasheet for the correct API.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I cannot see a line like
uint16 adcSample;
or
int adcSample;
Additionally: You did not check whether a conversion result is already availlable. Check your ADC datasheet for the correct API.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I had not copied that part of the code. Here it is:
/* ADC measurement status and result */
int16 adcSample = 0;
uint8 userRefresh = USER_LED_REFRESH - 1u;
int main()
{
/* Initialize ADC. Conversion is not enabled yet. */
void ADC_Start();
/* Start ADC conversion. */
void ADC_StartConvert();
adcSample = ADC_SAR_Seq_1_GetResult16(0x00u);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
try using this code..wait for the conversion of ADC is done
ADC_Start();
CyDelay(50);
ADC_StartConvert();
CyDelay(50);
if(ADC_IsEndConversion(ADC_WAIT_FOR_RESULT))
{
adcSample =ADC_SAR_Seq_1_GetResult16(0);
from here u can continue the code snippet of yours
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can you please post your actual complete project, so that we all can have a look at all of your settings. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The line
adcSample = ADC_SAR_Seq_1_GetResult16(0x00u);
is only executed once, it is outside of your main loop. So adcSample will never change.
Again: You did not check whether a conversion result is already available. Use ADC_SAR_Seq_1_IsEndConversion(), see datasheet.
Project compiles without warnings, only 5 notes.
Bob