- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hello I am trying to meassure voltage across potentiometer how ever i get the wrong voltage (and get even negetiv Voltage ) that displayes on the LCD , here is the code and top design :
any ideas why am i getting the wrong voltage ?
Solved! Go to Solution.
- Labels:
-
PSoC 5LP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Find on the forum about sprintf and heap size for it
#include <stdlib.h>
float result;
char string[16];
..........
sprintf(string, "%f\r\n", result);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try with debugger to check if values are really negative.
Try using "%ld" format in sprintf()
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
i did not undestand what do you mean . and what do you mean ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can you 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hi bob i cant find the attach file butten
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Click on "Use advanced Editor" (upper right hand corner) and an "Attach" will come up (at lower right corner).
Which Cypress kit are you using? CY8CKIT-???
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
I cannot see where your potentiometer is connected to, but I assume beween GND and +5V.
The ADC is configured for an input range of 1 to 2V which will give unpredictable results when overflown. You cold try setting the input range to 6*Vref.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
i tried changing to 6Vref yet the voltage is still in correct
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi. I am not sure why you are using the DAC. This would cause you to get negative results, depending on the DAC output voltage and the measured voltage.
To check your setup and program, try using the ADC in single ended mode and check the measurement range as defined in the component configuration.
I use an ADC in just about with every design and have no issues, from sine wave measurement for RMS values to 9 mux inputs into the ADC for various external measurements and oversampling to get 4 additional bits of resolution for PT100 temperature measurements with wire length compensation.
Regards
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hi I tried what you said and put the ADC on single ended and wrote this code :
/*******************************************************************************
* File Name: main.c
*
* Version: 2.20
*
* Description:
* This is a source code for example project of ADC single ended mode.
*
* Variable resistor(pot) is connected to +ve input of ADC using the I/O pin.
* P0.0. When voltage to positive terminal of ADC is 0, the output displayed
* on the LCD pannel is 0x0000. As voltage on positive terminal goes on
* increasing, the converted value goes on increasing from 0x0000 and reaches
* 0xFFFF when voltage becomes 1.024V. Futher increase in voltage value,
* doesn't cause any changes to values displayed in the LCD.
*
* Hardware Connections:
* Connect analog input from Variable resistor to port P0[0] of DVK1 board.
*
********************************************************************************
* Copyright 2012-2015, Cypress Semiconductor Corporation. All rights reserved.
* This software is owned by Cypress Semiconductor Corporation and is protected
* by and subject to worldwide patent and copyright laws and treaties.
* Therefore, you may use this software only as provided in the license agreement
* accompanying the software package from which you obtained this software.
* CYPRESS AND ITS SUPPLIERS MAKE NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* WITH REGARD TO THIS SOFTWARE, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT,
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*******************************************************************************/
#include <project.h>
#include<stdio.h>
/*******************************************************************************
* Function Name: main
********************************************************************************
*
* Summary:
* main() performs following functions:
* 1: Initializes the LCD
* 2: Starts ADC
* 3: Starts ADC converstion.
* 4: Gets the converted result and displays it in LCD.
*
* Parameters:
* None.
*
* Return:
* None.
*
*******************************************************************************/
int main()
{
int32 output;
/* Start the components */
LCD_Start();
ADC_DelSig_1_Start();
/* Start the ADC conversion */
ADC_DelSig_1_StartConvert();
/* Display the value of ADC output on LCD */
LCD_Position(0u, 0u);
LCD_PrintString("ADC_Output");
for(;;)
{
if(ADC_DelSig_1_IsEndConversion(ADC_DelSig_1_RETURN_STATUS))
{
output = ADC_DelSig_1_GetResult32();
/* Saturate ADC result to positive numbers. */
if(output < 0)
{
output = 0;
// CyDelay(100u);
}
LCD_Position(1u, 0u);
LCD_PrintInt16((uint16)output);
CyDelay(500u);
// LCD_Char_PrintNumber((uint16)output);
// LCD_Char_PrintU32Number((uint32) output);
}
}
}
/* [] END OF FILE */
and the problem is that i get wrong numers again , and it is written in ASCII code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
A few questions.
- For how many bits is the ADC set up?
- What conversion rate is selected?
- What input range is selected?
- What buffer gain is selected?
- In your design wide resources, what voltages are selected?
- Please post some of the results so I can see what you mean by wrong values that you get.
Actually, please post your project, then I have all the info.
If I get a chance, I will put the code on one of my kits to see what I get.
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
As part of the CY8CKit -050 download, there is also a nice example of the DeltaSigma ADC usage, with filtering and display.
Regards
Chris
- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
You can change the measurement range to any of the allowed ranges in the component configuration. You just have to keep the input voltage within that range to get appropriate outputs.
When using the ADC in single-ended mode, also use unsigned integers for the result, otherwise you get negative values when you get to half your input voltage if you use a 16-bit variable for a 16-bit result. So just keep it in mind when selecting the number of bits resolution and variable size.
If you use the ADC in 8-bit mode, you can use LCD_PrintInt8, For 9 to 16 bits, LCD_PrintInt16 and above 16-bits, you have to use LCD_PrintInt32. Also match your result variable to the bit size required. You can always use a larger variable, although it does not serve much of a purpose.
A further note on the gain setting. Keep in mind that if you apply gain to the input, you reduce the input measurement range by the gain factor. You also add more noise to the ADC input as the input noise is amplified as well as adding the amplifier noise. For very sensitive measurements, like load cells, PT100's and other instrumentation, this can become significant.
There is a very good app note (AN2099) on IIR for use in averaging conversion results to average your results. It provides code that works as is or you can change it to suit your own application.
if you have a PSoC without the DeltaSigma ADC and need better resolution out of your SAR ADC, you can always oversample and average. I have very successfully achieved 16-bits on the SAR. AN118 provides the theory behind it.
I hope you find the above useful.
Regards
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
first of all thank you for your help and I tried your code ,i got a resolt of the output voltage how ever the output voltage was wrong for exmplae the voltage are between 0.3-4.01v ( on pin goes to the ground and the second pin goes to Vdd of the Psoc 5 ) . but i get voltages of 0.5-4.9v. do you have idea why am i I getting the wrong value again ?
- 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
hi itreid your code and still gives me the wrong answer . maeby i need to add LP filter ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I hope you used ADC_SetOffset (); and ADC_SetGain ();
For display at LCD, it is sufficient to average the result.
My old project with a Simple Moving Average: VoltageDisplayMean41.zip
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
first of all thank you very much this is the closest answer that i got !!! i will try to undestand this code. one more thing is it possible to add
Floating-point ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Find on the forum about sprintf and heap size for it
#include <stdlib.h>
float result;
char string[16];
..........
sprintf(string, "%f\r\n", result);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thank you very much evegeny you really helped me , one more thing how did you know to write this code ? is there a source of information that you could share with me ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content