|
|
View previous topic :: View next topic |
Author |
Message |
creativity Guest
|
16f877, ccs, adc, serial communication |
Posted: Wed Sep 13, 2006 12:55 am |
|
|
hi,
i want to read two analog input and after converting them to dijital, i will sent them to serial port one by one. i have writen the following code but something is wrong, do you have any idea?
//////////////////////////////////////////
// ADC and Serial Communication //
// 2 channel Analog Input //
// 1 channel serial digital RS232 output//
// Ali Özgür Argunşah //
// argunsah@su.sabanciuniv.edu //
//////////////////////////////////////////
#include <16F877.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) // Jumpers: 8 to 11, 7 to 12
void main() {
long int input1;
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(ALL_ANALOG);
//delay_ms(2000);
do {
set_adc_channel(0);
delay_cycles(60);
input1 = read_adc();
putc(input1);
set_adc_channel(1);
delay_cycles(60);
input1 = read_adc();
putc(input1);
} while(TRUE);
} |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Sep 13, 2006 1:11 am |
|
|
What do you mean by "something is wrong" ?
Tell us what you expect to see, and what you are actually seeing. |
|
|
creativity Guest
|
|
Posted: Wed Sep 13, 2006 1:43 am |
|
|
I expect to read the serial output of 16f877 with a matlab code given below. I gave a sinus signal to one input and zero to the second one. i expect to see a sinus with some zeros inside (one sin signal and one zero, and so on) but i only see some random signal. as you see more than "something" is wrong
s1 = serial('COM3', 'BaudRate', 9600,'Databits',10);
fopen(s1);
eye=zeros(512*2,1);
for i=0:1
eye(i*512+1:i*512+512) = fread(s1)
% plot(eye)
end
plot(eye);
fclose(s1); |
|
|
Ttelmah Guest
|
|
Posted: Wed Sep 13, 2006 2:46 am |
|
|
How many Databits should there be?...
Best Wishes |
|
|
creativity Guest
|
|
Posted: Wed Sep 13, 2006 3:57 am |
|
|
i changed code to the code below and it works:
//////////////////////////////////////////
// ADC and Serial Communication //
// 2 channel Analog Input //
// 1 channel serial digital RS232 output//
// Ali Özgür Argunşah //
// argunsah@su.sabanciuniv.edu //
//////////////////////////////////////////
#include <16F877.h>
#device adc=8
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, parity=N, bits=8) // Jumpers: 8 to 11, 7 to 12
void main() {
long int input1;
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(ALL_ANALOG);
//delay_ms(2000);
do {
set_adc_channel(0);
delay_cycles(60);
input1 = read_adc();
putc(input1);
set_adc_channel(1);
delay_cycles(60);
input1 = read_adc();
putc(input1);
} while(TRUE);
}
thank you for all replies. |
|
|
|
|
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
|