![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
William Meade Guest
|
printf to LCD Problem |
Posted: Fri Apr 25, 2003 2:03 pm |
|
|
<html>
<body>
<pre>
I am reading a 16 bit result from a 16 Bit A/D chip.
I am attempting to shift the result into a variable which
is clocked in MSB first. I am not positive that the line
below with the shift_left statement is correct but it
compiles. I am having problems with the printf statement.
When I compile the project I get a "printf format type is
invalid". I should be getting a number between 0 and 32767.
The MSB is the sign bit.
I call 'read_adc_value()' from the main project file.
Any sugestions will be graatly appreciated.
Bill
-------------------------------------------------------------------
// READ CS5516 ADC WORD
long int read_adc_word() {
long data;
byte i;
for(i=1;i<=8;++i) { // CLEAR DATA READY SIGNAL
output_high(ADC_CLK);
output_low(ADC_CLK);
}
for(i=1;i<=16;++i) { // READ ADC VALUE
shift_left(&data,2,input(ADC_DI));
output_high(ADC_CLK);
output_low(ADC_CLK);
}
for(i=1;i<=8;++i) { // READ ADC ERROR FLAGS
output_high(ADC_CLK);
output_low(ADC_CLK);
}
}
// READ ADC VALUE
long int read_adc_value() { // READ CS5516 A/D VALUE
long int data;
While (!input(ADC_DRDY)); // WAIT FOR ADC_DRDY TO GO HIGH
While (input(ADC_DRDY)); // WAIT FOR ADC_DRDY TO GO LOW
value = read_adc_word();
printf(lcd_putc,"\nRaw - \%U",value);
}
</body>
</html>
___________________________
This message was ported from CCS's old forum
Original Post ID: 13999 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: printf to LCD Problem |
Posted: Fri Apr 25, 2003 2:18 pm |
|
|
:= printf(lcd_putc,"\nRaw - \%U",value);
-----------------------------------------------
Use \%lu for int16 or int32 variables. Example:
printf(lcd_putc,"\nRaw - \%lu",value);
I don't see where you declare "value". Presumably it's
declared somewhere else, as a global. It should be
declared as a "long" or (more clearly) as an "int16".
There is a chart in the manual that lists the printf
format options:
<a href="http://www.ccsinfo.com/piccmanual3.zip" TARGET="_blank">http://www.ccsinfo.com/piccmanual3.zip</a>
___________________________
This message was ported from CCS's old forum
Original Post ID: 14000 |
|
![](templates/subSilver/images/spacer.gif) |
R.J.Hamlett Guest
|
Re: printf to LCD Problem |
Posted: Fri Apr 25, 2003 2:34 pm |
|
|
:=<html>
:=<body>
:=
:=<pre>
:=
:=I am reading a 16 bit result from a 16 Bit A/D chip.
:=I am attempting to shift the result into a variable which
:=is clocked in MSB first. I am not positive that the line
:=below with the shift_left statement is correct but it
:=compiles. I am having problems with the printf statement.
:=When I compile the project I get a "printf format type is
:=invalid". I should be getting a number between 0 and 32767.
:=The MSB is the sign bit.
:=
:=I call 'read_adc_value()' from the main project file.
:=Any sugestions will be graatly appreciated.
:=
:=Bill
:=
:=-------------------------------------------------------------------
:=
:=// READ CS5516 ADC WORD
:=long int read_adc_word() {
:= long data;
:= byte i;
:=
:= for(i=1;i<=8;++i) { // CLEAR DATA READY SIGNAL
:= output_high(ADC_CLK);
:= output_low(ADC_CLK);
:= }
:=
:= for(i=1;i<=16;++i) { // READ ADC VALUE
:= shift_left(&data,2,input(ADC_DI));
:= output_high(ADC_CLK);
:= output_low(ADC_CLK);
:= }
:=
:= for(i=1;i<=8;++i) { // READ ADC ERROR FLAGS
:= output_high(ADC_CLK);
:= output_low(ADC_CLK);
:= }
:=}
:=
:=// READ ADC VALUE
:=long int read_adc_value() { // READ CS5516 A/D VALUE
:= long int data;
:=
:= While (!input(ADC_DRDY)); // WAIT FOR ADC_DRDY TO GO HIGH
:= While (input(ADC_DRDY)); // WAIT FOR ADC_DRDY TO GO LOW
:=
:= value = read_adc_word();
:= printf(lcd_putc,"\nRaw - \%U",value);
:=}
:=
:=
:=</body>
:=</html>
\%U, only handles standard integers. To deal with a long integer (anything bigger than an 8bit value), you have to use the 'L' prefix to say this is a long. So \%Lu, is the correct printf descriptor for a long.
As a general comment, check carefully on the minimum pulse width required for the clocks. At the faster clock rates (you don't say how fast your chip is running), it is common to have to insert one or more cycles of delay between raising/lowering signals.
Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 14001 |
|
![](templates/subSilver/images/spacer.gif) |
whmeade10 Guest
|
Re: printf to LCD Problem |
Posted: Fri Apr 25, 2003 7:59 pm |
|
|
:=<html>
:=<body>
:=
:=<pre>
Thanks for the replies to my question. I have the the A/D
working perfectly with the output that I was looking for on
the LCD.
I have one more minor problem that I havent figured out.
I wlll ask in a new post.
:=I am reading a 16 bit result from a 16 Bit A/D chip.
:=I am attempting to shift the result into a variable which
:=is clocked in MSB first. I am not positive that the line
:=below with the shift_left statement is correct but it
:=compiles. I am having problems with the printf statement.
:=When I compile the project I get a "printf format type is
:=invalid". I should be getting a number between 0 and 32767.
:=The MSB is the sign bit.
:=
:=I call 'read_adc_value()' from the main project file.
:=Any sugestions will be graatly appreciated.
:=
:=Bill
:=
:=-------------------------------------------------------------------
:=
:=// READ CS5516 ADC WORD
:=long int read_adc_word() {
:= long data;
:= byte i;
:=
:= for(i=1;i<=8;++i) { // CLEAR DATA READY SIGNAL
:= output_high(ADC_CLK);
:= output_low(ADC_CLK);
:= }
:=
:= for(i=1;i<=16;++i) { // READ ADC VALUE
:= shift_left(&data,2,input(ADC_DI));
:= output_high(ADC_CLK);
:= output_low(ADC_CLK);
:= }
:=
:= for(i=1;i<=8;++i) { // READ ADC ERROR FLAGS
:= output_high(ADC_CLK);
:= output_low(ADC_CLK);
:= }
:=}
:=
:=// READ ADC VALUE
:=long int read_adc_value() { // READ CS5516 A/D VALUE
:= long int data;
:=
:= While (!input(ADC_DRDY)); // WAIT FOR ADC_DRDY TO GO HIGH
:= While (input(ADC_DRDY)); // WAIT FOR ADC_DRDY TO GO LOW
:=
:= value = read_adc_word();
:= printf(lcd_putc,"\nRaw - \%U",value);
:=}
:=
:=
:=</body>
:=</html>
___________________________
This message was ported from CCS's old forum
Original Post ID: 14004 |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|