- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a custom hardware setup that is reading a current sensor and a pressure sensor. If I read the ADC input with a multimeter I see 2.5V from both sensors but in code the ADC is returning 3.085V and 2.984.
I've attached my code. I'm running a very simple Fake RTOS to sample the sensor and print info out to the UART.
Do you guys see anything wrong with the setup?
Joe
Solved! Go to Solution.
- Labels:
-
PSoC 4 Architecture
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I figured out the remainder of my issue.
I was treating the return of ADC_CountsTo_MVotls() as an uint16 and then attempting to translate that value to a mV value. ADC_CountsTo_MVotls() returns a int16 and the compiler treats int16 values a two's complement numbers. So (int16)2500 mv = (2'sComp) 0x94C
All I had to do was change my variable type be a int16, remove my math that was not needed and BAM! it works!
Thank you Bob and Evgeniy for your help!
Joe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Which voltage is your PSoC running on?
Another point might be: the writing to UART may take longer than the 1/200 second, so it may be disturbed by the interrupt. Give the ADC highest prio and the UART more time: you are sending about 80 chars at 9600 chars/s which would take about 8ms whie the window is set to 5ms
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Bob,
Thank you for taking a look at my stuff.
The PSoC 4 is running on 5V and I've set the internal voltages to 5V.
I set the priority of the ADC task to the highest and my sensor sampling interrupt to one step lower. I've set the print priority to the lowest priority and the ADC reading is still off.
I double checked the settings on my UART. The baud rate is set to 115200 so the message should be really quick. If you look at the code I also set it up so that the UART only gets written to every 10 times the DEBUG_PRINT_INFO is called. I was worried about exactly what you are hypothesising.
Joe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Baud rate of 115200 is a bit rate. Divide by 12 gives 9600 chars/s. Calculate for yourself how long it takes to transmit your 80 chars.
There are APIs to calculate counts to mv adjustable for each channel which you use. Are the values of v_water_ticks and v_current_ticks wrong?
Keep in mind that debugging (stop) will give wrong ADC results when resuming without a complete conversion cycle.
Found one more: Avoid multiple calls to ADC_StartConvert(). ADC is configured as free running.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Bob,
I've removed the multiple calls to ADC_StartConvert(). I've also changed the prints to be:
sprintf(msg,"W:0x%x\r\n",v_water_ticks );
and
sprintf(msg,"C:0x%x\r\n",v_current_ticks );
To minimize the time needed in printing.
The ticks are the values that are off. I'm still seeing 0x980ish and 0x9D0ish. They should both be sitting at 0x800ish ticks which is equates to 2.5V. Thank you again for taking a look at this.
Do you see anything else I'm doing wrong?
Joe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can you please provide us with an actual workspace archive.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Bob,
Here is the full workspace. I'm using PSoc Creator 4.2 so you may have to upgrade to view the stuff. There is a second project in the workspace that is a modified version of the ADC_SAR_Seq_DieTemp_PSoc4 project. I'm currently attempting to modify that project to use 5V and my sensor pins.
Joe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is not a complete workspace archive, please 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
For what you divide by 0.819 in line 73
2.5/0.819 = 3.05
I filed 1.463V and saw the v_water_ticks = 1469mV
and yet Vref select = VDDA gives an additional error
VDDA may not be exactly 5.00V
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
if Single Ended negative input = Vref
it seems there is something wrong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I figured out the remainder of my issue.
I was treating the return of ADC_CountsTo_MVotls() as an uint16 and then attempting to translate that value to a mV value. ADC_CountsTo_MVotls() returns a int16 and the compiler treats int16 values a two's complement numbers. So (int16)2500 mv = (2'sComp) 0x94C
All I had to do was change my variable type be a int16, remove my math that was not needed and BAM! it works!
Thank you Bob and Evgeniy for your help!
Joe