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 CCS Technical Support

where to find the ADC output of printf?

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








where to find the ADC output of printf?
PostPosted: Tue Sep 29, 2009 11:39 pm     Reply with quote

Hi, can anybody tell me where the get the output of the following code ?
I want to use the output of the ADC to program something else.
Code:

#include <18F452.h>
#device adc=10
#fuses HS,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

//=================================
void main()
{
int16 result;

setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_DIV_32);
set_adc_channel(0);
delay_us(15);

while(1)
  {
   result = read_adc();
   printf("%LX ", result);
   delay_ms(500);
  }

}

Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 29, 2009 11:52 pm     Reply with quote

Get it in a terminal window on your PC.
You can use Hyperterminal, which comes with Microsoft Windows,
or you can use TeraTerm. Instructions on how to install TeraTerm:
http://www.ccsinfo.com/forum/viewtopic.php?t=39388&start=18

This assumes you are running the program on a PIC installed on a
real hardware board (not a simulation).
fr0stb0iz



Joined: 29 Sep 2009
Posts: 13

View user's profile Send private message

PostPosted: Wed Sep 30, 2009 12:05 am     Reply with quote

Hi thanks for the reply, I am new to CCS, is it possible to just use the output directly instead of using the terminal program ?

I want to make a simple program by getting the input from a function generator (PORTA) ---> into the ADC ---> output display onto the LED display ( PORTD)

This is my current code.
Code:

#include <18F452.h>
#device adc=10
#fuses HS,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#byte PORTD = 8 // testing .
#define ALL_OUT 0x00
#define ALL_IN 0xff


//=================================
void main()
{
int16 result;

set_tris_d(ALL_OUT);
PORTD = 0;
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_DIV_32);
set_adc_channel(0);
delay_us(15);
//output_low(portd);
set_tris_d(ALL_OUT);
PORTD = 0;
while(1)
  {
   PORTD = read_adc();
//   result = PORTD;

   //printf("%LX ", portd);
   delay_ms(500);
  }

}

Thank you.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Sep 30, 2009 12:48 am     Reply with quote

You don't need to set the TRIS. You don't need to write to Port D directly,
so you don't need the #byte statement. Just use the output_d() function.
This will set the TRIS correctly and it will write to Port D. Example:
Code:

result = read_adc();
output_d(result);


Also, it's clear that you want only 8 bits from the A/D, so tell the compiler
to use 8-bit mode. Change the #device statement to this:
Code:
#device adc=8
fr0stb0iz



Joined: 29 Sep 2009
Posts: 13

View user's profile Send private message

PostPosted: Wed Sep 30, 2009 1:31 am     Reply with quote

Thank you very much, I managed to display the output onto the LED,
but can you tell me what is the difference between:
Code:
setup_adc(ADC_CLOCK_DIV_32);

&
Code:
setup_adc(ADC_CLOCK_INTERNAL);

Code:
while(1)
  {
   result = read_adc();
   output_d(result);

   //printf("%LX ", portd);
   delay_ms(50);
  }

What about the delay ? When I remove the delay, it works fine. However when I add in some delay, the output seems to be in a mess.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Sep 30, 2009 12:13 pm     Reply with quote

Quote:

Can you tell me what is the difference between:
setup_adc(ADC_CLOCK_DIV_32);
&
setup_adc(ADC_CLOCK_INTERNAL);

Look in the ADC section of your PIC's data sheet. It explains how to
choose the best clock divisor, based on the oscillator frequency of your
PIC. It also has a note on when you're allowed to use the interna A/D
clock. Look in this section, on page 188 in the Acrobat reader:
Quote:
17.2 Selecting the A/D Conversion Clock
http://ww1.microchip.com/downloads/en/DeviceDoc/39564c.pdf

Quote:

What about the delay ? When I remove the delay, it works fine. However
when I add in some delay, the output seems to be in a mess.

I don't know. Explain your hardware. Explain what your project is.
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