value conversion

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

cross mob
Communication
Level 5
Level 5
100 replies posted First solution authored 250 sign-ins

Tôi đang sử dụng ADC để đọc giá trị của cảm biến độ ẩm đất. Tôi đã đọc ADC với giá trị đầu ra là giá trị điện áp, bây giờ tôi muốn chuyển đổi giá trị điện áp hiện tại thành giá trị phần trăm khi hiển thị trên ứng dụng di động, tôi phải làm như thế nào? Tôi sử dụng Modus Toolbox và PSoC 063 BLE prototyping kit.
Cảm ơn!

0 Likes
1 Solution

The code example uses the hal driver. You can change it in the code.

You don't need to configure in the GUI.

View solution in original post

0 Likes
14 Replies
Owen_Zhang123
Moderator
Moderator
Moderator
5 questions asked 500 solutions authored 250 sign-ins

Do you mean you need to transfer the ADC value to a percentage?

You can define a full range of the value and calculate the percentage by yourself.

0 Likes
Communication
Level 5
Level 5
100 replies posted First solution authored 250 sign-ins

How can I do that?

0 Likes
Owen_Zhang123
Moderator
Moderator
Moderator
5 questions asked 500 solutions authored 250 sign-ins

What's the range of the value?

You may calculate it like this:  Percentage = 100*ADC_Value/Full_Range

0 Likes

Communication_0-1678701312003.png

This is the range of values that I have read from the ADC.

The description reads my ADC using: Read the value from ADC pin, represented as a 32-bit signed, right-aligned value.

This is a 'resolution'-bit value, sign-extended to 32 bits. If the vplus signal is below the vminus signal, the result will be negative. If the vplus signal is above the vminus signal, the result will be positive. If continous scanning is disabled, this will block while a conversion is performed on the selected channel, then return the result. Depending on the ADC speed this function may block for some time. If continuous scanning is enabled, this will return the value from the most recent conversion of the specified channel (if called shortly after enabling continuous scanning it may block until at least one conversion has been performed on this channel).

0 Likes

You don't know how to transfer the digital value to actual voltage?

0 Likes

Looks like you misunderstood me

0 Likes
Owen_Zhang123
Moderator
Moderator
Moderator
5 questions asked 500 solutions authored 250 sign-ins

Could you be more specific about your problem?

0 Likes

I want to convert the readings like the image above into percentages

0 Likes

Can you transfer the ADC value to real voltage?

What's the voltage range for your input?

0 Likes

I have read adc value and I am converting to percentage value, min=0 and max=3298 range

0 Likes

So you already get the sample voltage. You already know the max value. What is the difficult to get a percentage value?

Percentage_value = 100*sample_voltage/3298.

0 Likes

It is exactly what I needed, I tried using the formula of int map() function in arduino but no success.
And I have 1 question to ask you, I use ADC_basic program: https://github.com/Infineon/mtb-example-hal-adc-basic to execute my sensor reading program, do I need configure the SAR ADC in the picture below or not?

Thanks!

 

Communication_0-1680408239142.png

0 Likes

The code example uses the hal driver. You can change it in the code.

You don't need to configure in the GUI.

0 Likes

Thank you for the information!

0 Likes