|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
where to find the ADC output of printf? |
Posted: Tue Sep 29, 2009 11:39 pm |
|
|
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
|
|
Posted: Tue Sep 29, 2009 11:52 pm |
|
|
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
|
|
Posted: Wed Sep 30, 2009 12:05 am |
|
|
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
|
|
Posted: Wed Sep 30, 2009 12:48 am |
|
|
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:
|
|
|
fr0stb0iz
Joined: 29 Sep 2009 Posts: 13
|
|
Posted: Wed Sep 30, 2009 1:31 am |
|
|
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
|
|
Posted: Wed Sep 30, 2009 12:13 pm |
|
|
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. |
|
|
|
|
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
|