Counts to volt in SAR ADC

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

cross mob
user_3899081
Level 1
Level 1
First like received

Dear all,

I'm a newbie for using PSoC. I don't really understand how to use SAR ADC in PSoC. I'm trying to get the digital input from piezoelectric ceramics and also the analog input (mvolt). But I can't get the voltage result. I'm using the following code :

#include "project.h"

#include "stdio.h"

#include "stdlib.h"

char data[60];

uint16_t raw;

float32_t v;

int main(void)

{

    __enable_irq(); /* Enable global interrupts. */

    ADC_Start();

    ADC_StartConvert();

    UART_1_Start();

    for(;;)

    {

       if (ADC_IsEndConversion(CY_SAR_RETURN_STATUS)){

       raw = ADC_GetResult16(0);

       v = ADC_CountsTo_mVolts(0,raw);

       sprintf(data,"v= %f mv raw= %d \n",v,raw);

        }

       UART_1_PutString(data);

       

        CyDelay(100);

       }

}

/* [] END OF FILE */

pastedImage_9.png

pastedImage_15.png

Is there something wrong with the code?

Thank you for your help,

Tita

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

Printing floats needs some settings:

Set "use newlib nano" to true (Project butld settings -> linker)

Set "use newlib nano float formatting" to true (Project build settings -> linker)

Set "Heap Size" to (at least) 0x0200 (System view)

That should do the job

Bob

View solution in original post

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

Printing floats needs some settings:

Set "use newlib nano" to true (Project butld settings -> linker)

Set "use newlib nano float formatting" to true (Project build settings -> linker)

Set "Heap Size" to (at least) 0x0200 (System view)

That should do the job

Bob

0 Likes

Yes, it work.

Thank you for your help

Tita

0 Likes