CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

printf to LCD Problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
William Meade
Guest







printf to LCD Problem
PostPosted: Fri Apr 25, 2003 2:03 pm     Reply with quote

<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
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: printf to LCD Problem
PostPosted: Fri Apr 25, 2003 2:18 pm     Reply with quote

:= 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
R.J.Hamlett
Guest







Re: printf to LCD Problem
PostPosted: Fri Apr 25, 2003 2:34 pm     Reply with quote

:=<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
whmeade10
Guest







Re: printf to LCD Problem
PostPosted: Fri Apr 25, 2003 7:59 pm     Reply with quote

:=<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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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