Anonymous
Not applicable
Oct 04, 2011
12:49 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oct 04, 2011
12:49 PM
Hello All,
I would like to convert a 12 bit reading from the delta-sigma ADC (range = 1.024V single ended) into an 8 bit DAC value (range = 1.024V).
I had originally thought to typecase the int16 adc conversion into a uint8 DAC value:
sprintf(buffer,"%d, %d\n\r", adc_val, (uint8)adc_val);//Note the typecast
UART_PutString(buffer);
However, when I do this I get the following (using the sprintf function):
adc_val = 3491
(uint8)adc_val = - 23773
Can anyone suggest how I could better go about this process? Is this error a compilier thing or did I make a silly mistake?
Thanks,
Alex
Labels
- Labels:
-
PSoC 3
2 Replies
Oct 06, 2011
06:21 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oct 06, 2011
06:21 AM
Hi,
wouldn't it be better to divide the 12-bit ADC_Value by 16 to get the 8-bit DAC_Value?
Thus:
DAC_Value = ADC_Value >> 4;
Bob
Anonymous
Not applicable
Nov 02, 2011
02:10 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Nov 02, 2011
02:10 AM
- Bob's suggestion seems to be a better way of doing it. A right shift by 4 positions will produce the result that you need.
- If your intention is to view the dat out on the UART, sprintf would be the ideal way to do it beacuse you have the data already in ASCII format that can be printed.
- Since your intention is to write the data a DAC directly, you can either typecast the data as uint8 or you could right shift the 12 bit dat by 4 bits.