ADC SAR in BLE

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

cross mob
Anonymous
Not applicable

I'm trying to use the ADC SAR UDB in my PSoC BLE, i think theres something wrong in my code because there's no response on the Serial Communication (I only see my first message). This is my code:

   

#include "project.h"
#include <stdio.h>
int main(void)
{
    CyGlobalIntEnable; /* Enable global interrupts. */

   


    char str[12]={'\0'};
    uint16 conversion=0;
    uint16 voltage=0;
    
    ADC_Start();
    IDAC_Start();
    UART_Start();
    UART_UartPutString("Hi everyone");
    for(;;)
    {
        ADC_StartConvert();
        ADC_IsEndConversion(ADC_WAIT_FOR_RESULT);
        conversion=ADC_GetResult16(0);
        voltage=ADC_CountsTo_mVolts(0,conversion);
        ADC_StopConvert();
        sprintf(str,"%d",conversion);
        UART_UartPutString(str);
        CyDelay(500);
    }
}

   

When I use the debbuger I see that my data is lost in the transformation with the line "voltage=ADC_CountsTo_mVolts(0,conversion);". But, the "ADC_GetResult16(0);" does give me the data (Example 1675, out of 2047), but the it doesn't convert it to mili volts. Does anyone know what is happening?

   

Pd. In my TopDesign I only have IDAC, ADC SAR Seq, SCB (as UART) and I am using Arduino Monitor Serie where I only see the first message: "Hi everyone".

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Here is your program. I also added a die temp device so you can read two channels of the ADC.  Jumper P3.2 to 3.3 Volts on J1. The reason you where not seeing a reading on the voltage was you where not printing it out.

View solution in original post

0 Likes
5 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Welcome in the forum, Arturo!

   

There are some settings I would suggest:

   

Use "Hi everyone\n\r" so that the output lines get separated. same with other output.

   

Project->Build settings -> compiler -Optimization set to "none"

   

                                      -> Linker set Use newlib nano to true

   

                                                      set User newlib nano float formatting to true

   

Workspace explorer - > System set Heap size to 0x0200

   

You do not need to use StartConvert and StopConvert() within the main-loopm use StartConvert() outside the loop.

   

Your missing data may result from some optimization which now is switched off.

   

Next time (it is far more easier for us to check) please post your 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

Anonymous
Not applicable

Thank you very much Bob. I made this change and the transfer data got done.

0 Likes
lock attach
Attachments are accessible only for community members.
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Here is your program. I also added a die temp device so you can read two channels of the ADC.  Jumper P3.2 to 3.3 Volts on J1. The reason you where not seeing a reading on the voltage was you where not printing it out.

0 Likes
Anonymous
Not applicable

Thank you very much bobgoar, this will also help me. There is really good people in this forum 😄

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Always at your service, Arturo!

   

 

   

Bob & Bob    ;-))

0 Likes