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

PSoC™ 5, 3 & 1

AlVa_264671
Level 5
Level 5

Hi  there

I always used ADC Delta sigma. This is my firs time  with Sar ADC.

I have attached a simple project  where the  minus Sar's input is  hooked up to  Vref/2

From a pot I change the + input volatge between  Vssa and Vdda.

I don't know what I am missing but I expect get negative values when V+ - V-   is negative  and positive values when the diference is positive.

I just got values from  0 couts  to 4095 counts  when the positive input  is from 0v to 3.3v ,in this case.

Please see attached project.

Thank you in advance

0 Likes
1 Solution
Vasanth
Moderator
Moderator 500 solutions authored First question asked 1000 replies posted
Moderator

Hi Alejandro,

The problem with your code is that ADC_SAR_1_SAR_WRK0_PTR register is not sign extended; the result is always unsigned. You can use ADC_SAR_1_GetResult16(); API inside the ISR which will return a signed result .

Best Regards,

VRS

View solution in original post

0 Likes
4 Replies
Vasanth
Moderator
Moderator 500 solutions authored First question asked 1000 replies posted
Moderator

Hi Alejandro,

The problem with your code is that ADC_SAR_1_SAR_WRK0_PTR register is not sign extended; the result is always unsigned. You can use ADC_SAR_1_GetResult16(); API inside the ISR which will return a signed result .

Best Regards,

VRS

0 Likes
AlVa_264671
Level 5
Level 5

Hi vsrs

Thank you for your answer.

I missed the  int16 ADC_GetResult16(void) API side effect.

0 Likes
Anonymous
Not applicable

Hi,

The result format from the SAR block is unsigned. Firmware manipulation is required to get it in 2's complement format.

If you look into the component API function- ADC_SAR_1_GetResult16(), it reads the result from a register pointed by ADC_SAR_1_SAR_WRK_PTR and subtracts (ADC_SAR_1_shift) from the result. This is to get the 2's complement form.

In your code, you can either subtract 0x800 from the result or use the component API function.

-Rajiv

0 Likes
AlVa_264671
Level 5
Level 5

Hi rajiv

You help me again

I missed the  int16 ADC_GetResult16(void) API side effect.

Up today I did like you suggested :

In your code, you can either subtract 0x800 from the result or use the component API function.

Thank you again.

0 Likes