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

Multi printf(lcd_putc )

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








Multi printf(lcd_putc )
PostPosted: Tue Jun 15, 2004 6:54 am     Reply with quote

Iam making a display that needs to sample 4 inputs and display the results.
The problem iam having is in the display.

printf(lcd_putc,"\f");

printf(lcd_putc,"CH1:%01.0fmW CH2: mw\n", voltage);

printf(lcd_putc,"CH3: mW CH4: mW");

what i need is the CH1: to display the results
CH2: to display its results, etc.

Like :
----------------------------
: CH1: 22 V CH2: 34V :
: CH3: 00 V CH4: 10V :
----------------------------

The words CH1 - CH4 need to be fixed and the values variable.
right now as the number of digits increase the words move back and forth.

Thanks for any help
SteveS



Joined: 27 Oct 2003
Posts: 126

View user's profile Send private message

PostPosted: Tue Jun 15, 2004 8:36 am     Reply with quote

Couple things:

The example display you show doesn't match the code - just makes it a bit confusing to see what you want to do...

To keep everthing in its place you need to use format specifiers. Your code is trying to do this, but the values seem incorrect to me. Read up on format specifiers and experiment.

Your example shows no decimal part of the value. If you don't need that, then you will simplify the code if you round the voltage to an integer value and print that. In that case use a format specifier like "%2d" which will maintain two places for the value even if it's one digit (if two digits is enough).

Even with that you may get bothersome flicker as the screen gets repainted each time. You should be able to paint the screen once, then as you get each new value, use the LCD's gotoxy command to place the cursor at the right spot on the LCD and print just the new value. You still need formatted output so a single digit value completely overwrites a past double digit value. That will look much cleaner.

Does that help?

- SteveS
Guest








copy of the code
PostPosted: Tue Jun 15, 2004 9:29 am     Reply with quote

Here is a copy of the code.
Iam still having problems getting it to read the incoming voltage.

Thanks for any help


#include <16F876.h>
#fuses XT,NOWDT,NOPROTECT,PUT,NOBROWNOUT
#use delay(clock=4000000)
#include <stdio.h>
#include <lcd1.c>
#include<math.h>

//#byte PORT_A=5
//#byte PORT_B=6

void main() {
char k;
const long NUM_DATA_POINTS=3000;
long i;
long value;
float ch1;
float ch2;
setup_port_a(ALL_ANALOG);
setup_adc( ADC_CLOCK_INTERNAL );
lcd_init();
delay_ms( 4555 );

while(TRUE)
///////////////////////////////////////////////////////////
{

for(i=0;i<NUM_DATA_POINTS;++i)

///////////////////////////////////////////////////////////
ch1=0;
set_adc_channel(0);
delay_us(10);
{
value=read_adc();
ch1+=(float)value*(float)value;
}
ch1/=2601.0;
ch1=sqrt(ch1/(NUM_DATA_POINTS));
////////////////////////////////////////////////////////////

if (ch1 < 1.336)
{
ch1 = 0;
}
else{
ch1=((ch1-1.336)/.00064);
}
/////////////////////////////////////////////////////////////
ch2=0;
set_adc_channel(1);
delay_us(10);
{
value=read_adc();
ch2+=(float)value*(float)value;
}
ch2/=2601.0;
ch2=sqrt(ch2/(NUM_DATA_POINTS));
//////////////////////////////////////////////////////////////
if (ch2 <1.336)
{
ch2 = 0;
}
else
{
ch2 = ((ch2-1.336)/.00064);
}

///////////////////////////////////////////////////////////////
printf(lcd_putc,"\f");

printf(lcd_putc,"CH1:%01.0fmW CH2:%01.0fmw \n", ch1, ch2);

printf(lcd_putc,"CH3: mW CH4: mW");
}
}
SteveS



Joined: 27 Oct 2003
Posts: 126

View user's profile Send private message

PostPosted: Tue Jun 15, 2004 3:16 pm     Reply with quote

You say you are having trouble reading the incoming voltage? Do you mean your ADC routines are not working correctly or you have trouble displaying the data correctly? I assume you still mean display problems.

Did you try the ideas I suggested? Your code has not really changed. Explain what you think this format statement should do:

%01.0f

Can you use integer values? If so it makes things a bit easier, smaller, and faster.

- SteveS
languer



Joined: 09 Jan 2004
Posts: 144
Location: USA

View user's profile Send private message

Watch for acquisition time
PostPosted: Wed Jun 16, 2004 2:00 am     Reply with quote

Note that if your display is now ok, but the numbers you display are not stable you may be violating the required acquisition time for the ADC module.

You allocate 10uS for acquisition time,
Code:
set_adc_channel(0);
delay_us(10);
{
value=read_adc();

Microchip recommends 19.72uS on the datasheet. So you see, if your signal is changing quite a bit, the storage capacitor (sample) will not fully charge and the numbers will be 'jumpy'.

If this is the case try changing the delay from 10uS to 20uS (or more for some margin) and see if it does the trick. If your problem is the display part of it (i.e. formatting), the kindly disregard this.
Guest








Display OK, No ADC
PostPosted: Wed Jun 16, 2004 6:42 am     Reply with quote

The display works, but will no display any value from the adc.
iam using the value=read_adc, but i need to read 4 inputs.
when i did get it to work, only channel 1 would display any voltage.


Thanks
SteveS



Joined: 27 Oct 2003
Posts: 126

View user's profile Send private message

PostPosted: Wed Jun 16, 2004 9:44 am     Reply with quote

If the ADC is the problem, then step back and start simple. Have your LCD display (or RS232) the raw data you get back from the ADC, one channel at a time. Use a known good voltage source for testing. Then try two channels, etc. Then add in the calculations. You can also test the calculation part separately. Loop through the expected ADC values and run them through the calculations and display the results.

Some questions:
- Why do you say the second channel doesn't work? Is it always one value, or too jumpy, or what? (again, look at the raw data)
- What does your input circuit look like?

and languer is correct about acquisition time. Also be sure your input impedance is not too high (see the data sheet).

I don't see anything obviously wrong with the code you have for the ADC so you are on the right track.

- SteveS
Guest
Guest







Is this a bug?
PostPosted: Wed Jun 16, 2004 11:07 am     Reply with quote

Look in the loop - I think - can't tell cause you aren't using braces to enclose the steps to be iterated - hey, I'm old. Looks like you are setting "ch1" back to zero before every new acquisition.

Use parentheses, braces. They're basically free.

for(i=0;i<NUM_DATA_POINTS;++i)

///////////////////////////////////////////////////////////
ch1=0; <<<<<< This should be North of the loop
set_adc_channel(0);
delay_us(10);
{
value=read_adc();
ch1+=(float)value*(float)value;
}
ch1/=2601.0;
ch1=sqrt(ch1/(NUM_.........
Guest








Ok.. I rewrote it.
PostPosted: Wed Jun 16, 2004 11:46 am     Reply with quote

Ok i rewrote the code.
Now all inputs see data, but channel 1 (AN0) seems to have an effect with channel 4 (AN3). It almost looke like the comparitor is on. tryed to use
etup_comparator(NC_NC_NC_NC);
but it give an error when compiled.

Here is the new code:

Thanks for the help on this one..
Code:

#include <16F876.h>
#fuses XT,NOWDT,NOPROTECT,PUT,NOBROWNOUT
#DEVICE ADC=10
#use delay(clock=4000000)
#include <stdio.h>
#include <math.h>
#include <lcd1.c>

//////////////////////////////////////////////////////////
void main()
{
char k;
long number;
long number2;
long number3;
long number4;
setup_counters( RTCC_INTERNAL, RTCC_DIV_256 | RTCC_8_BIT);
setup_adc_ports( ALL_ANALOG );
setup_adc(ADC_CLOCK_INTERNAL);
set_tris_A(1);
//setup_comparator(NC_NC_NC_NC);
CCP_OFF;
lcd_init();
lcd_putc("\fWelcome");
lcd_putc("    to ");
delay_ms(4000);
lcd_putc("\f    My   \n");
lcd_putc("******> MESS <******");
delay_ms(4000);
lcd_putc("\f");

do{
//////////////////////// CHANNEL 1 /////////////////
set_adc_channel( 0 );
delay_ms(200);
number = Read_ADC();
delay_ms(200);
//////////////////////// CHANNEL 2 /////////////////
set_adc_channel( 1 );
delay_ms(200);
number2 = Read_ADC();
delay_ms(200);
//////////////////////// CHANNEL 3 ////////////////
set_adc_channel( 2 );
delay_ms(200);
number3 = Read_ADC();
delay_ms(200);
//////////////////////// CHANNEL 4 ////////////////
set_adc_channel( 3 );
delay_ms(200);
number4 = Read_ADC();
delay_ms(200);
///////////////////////////////////////////////////
printf(lcd_putc,"\f");
printf(lcd_putc,"CH1:%LdmW CH1:%LdmW\n", number, number2);
printf(lcd_putc,"CH3:%Ldmw CH4:%LdmW", number3, number4);

} while(true);

}
 

Guest








Ok.. It Works.
PostPosted: Wed Jun 16, 2004 12:38 pm     Reply with quote

Laughing
I had to put all 4 inputs to signal or gnd and they all work !!!!!!

Now i just have to convert the voltage input to a power reading.

like .51V = 0mw etc.

Thanks,
Donnie
SteveS



Joined: 27 Oct 2003
Posts: 126

View user's profile Send private message

PostPosted: Thu Jun 17, 2004 6:22 am     Reply with quote

Excellent! and thanks for letting us know the solution.
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