|
|
View previous topic :: View next topic |
Author |
Message |
No_Fear Guest
|
877 adc weird behaviour - 877 Newbie Part2 |
Posted: Tue Jun 03, 2003 5:18 am |
|
|
Hi there,
Finally i blinked my led with a 877 and i ran a lot of way.I connected pic to pc via max232 and i configured my adc ports to read signal.I have 2 questions now :)
1.Pic can send data to pc correctly but i can't send data to pic.For example :
main() {
printf("start");
while(TRUE)
putc( getc());
}
This code does not echo my characters but this works :
main() {
while(TRUE)
printf("start");
}
Why does it behave like this?
2. I built my circuit RA0,RA1,RA5,RE0,RE1,RE2 as adc ports and i connected zenner diodes like this schematic :
<a href="http://www.hobby-elec.org/e_pic6_91.htm" TARGET="_blank">http://www.hobby-elec.org/e_pic6_91.htm</a>
Look behind at RA0 you'll see zenner diode and a cap.I didnt connect capacitor due to hard-discharging and it gives wrong voltage to ports.My RA1,RA5,RE0,RE1 works fine but RA0 gives 60-6F when no voltage on it and RE2 gives 10-19 when no voltage on it.They should be around zero, shouldn't they? My code is shown below.What is wrong?
#include <16F877A.h>
#device adc=8
#use delay(clock=4000000)
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
void main() {
int v1,v2,v3,v4,v5,v6;
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
printf("HANDSHAKE");
while (1)
{
delay_ms(500);
set_adc_channel( 0 );delay_us(50);v1 = Read_ADC();delay_us(50);
set_adc_channel( 1 );delay_us(50);v2 = Read_ADC();delay_us(50);
set_adc_channel( 4 );delay_us(50);v3 = Read_ADC();delay_us(50);
set_adc_channel( 5 );delay_us(50);v4 = Read_ADC();delay_us(50);
set_adc_channel( 6 );delay_us(50);v5 = Read_ADC();delay_us(50);
set_adc_channel( 7 );delay_us(50);v6 = Read_ADC();delay_us(50);
printf("Value: \%2X/\%2X/\%2X/\%2X/\%2X/\%2X\r\n",v1,v2,v3,v4,v5,v6);
v1=0;v2=0;v3=0;v4=0;v5=0;v6=0;
}
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515000 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: 877 adc weird behaviour - 877 Newbie Part2 |
Posted: Tue Jun 03, 2003 12:03 pm |
|
|
:=1.Pic can send data to pc correctly but i can't send data to pic.For example :
:=
:=main() {
:= printf("start");
:= while(TRUE)
:= putc( getc());
:=}
Check the hardware. Your code should work. You can
strip your program down to something very simple, like
the program below, while you're debugging this problem.
If you're not sure if your PC is sending characters,
then look at the transmit line with an oscilloscope.
If you don't have a scope, you could try doing a loop-back
at various points. Initially, you could do a loop-back
right at the DB-9 connector on the PC. Take a separate
DB-9 connector, and just put a jumper across pins 2 and 3.
See if your terminal will echo chars. (Be sure to turn off
any internal setting for "local echo" in your terminal
program -- to make it less confusing).
If that loopback works, then loop it back on the PIC side of
the MAX232. For example, in the following diagram (see link),
you would break the connections between the MAX232 and the
PIC, and then connect pin 11 to pin 12. (Your circuit may
use different sections of the MAX232, since it has two transmit
and two receive buffers). If the circuit is wired correctly,
you should be able to press a key and see it echo'ed back to
the PC. <a href="http://www.ccsinfo.com/faq/?6" TARGET="_blank">http://www.ccsinfo.com/faq/?6</a>
If that works, then remove the loopback connection and
connect the MAX232 to the PIC again. It should work.
Make sure you have a ground wire going from pin 5 on the
DB-9 to the MAX232's and the PIC's ground.
#include <16F877A.h>
#use delay(clock=4000000)
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7, ERRORS)
void main()
{
printf("start");
while(TRUE)
putc( getc());
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515008 |
|
|
No_Fear Guest
|
Re: 877 adc weird behaviour - 877 Newbie Part2 |
Posted: Tue Jun 03, 2003 6:02 pm |
|
|
Thank you for your kind reply.I think my max232 is partially blewn.Because receiving from pic is ok but sending to pic fails.I made loop-back test but no response from max232.I will change it tomorrow.
My second question is, when there is no voltage on RE3 it gives wrong adc results.Also i think it effects to RA0 because when i connect RE0 input to GND, it gives zero value.Also RA0 decreases to zero.(When no voltage on RA0 it gives 10-15 now).When i leave it RE3 adc result is 40-45.All rest ports are working perfectly.What is wrong? If you want to see my code please refer my first message.
Thanks again.
P.S. I apologize from every user because of duplicate message, i tried to delete it but it gave server error.If Admin can delete it, please delete my unreplied message.
No_Fear.
:=:=1.Pic can send data to pc correctly but i can't send data to pic.For example :
:=:=
:=:=main() {
:=:= printf("start");
:=:= while(TRUE)
:=:= putc( getc());
:=:=}
:=
:=Check the hardware. Your code should work. You can
:=strip your program down to something very simple, like
:=the program below, while you're debugging this problem.
:=
:=If you're not sure if your PC is sending characters,
:=then look at the transmit line with an oscilloscope.
:=If you don't have a scope, you could try doing a loop-back
:=at various points. Initially, you could do a loop-back
:=right at the DB-9 connector on the PC. Take a separate
:=DB-9 connector, and just put a jumper across pins 2 and 3.
:=See if your terminal will echo chars. (Be sure to turn off
:=any internal setting for "local echo" in your terminal
:=program -- to make it less confusing).
:=
:=If that loopback works, then loop it back on the PIC side of
:=the MAX232. For example, in the following diagram (see link),
:=you would break the connections between the MAX232 and the
:=PIC, and then connect pin 11 to pin 12. (Your circuit may
:=use different sections of the MAX232, since it has two transmit
:=and two receive buffers). If the circuit is wired correctly,
:=you should be able to press a key and see it echo'ed back to
:=the PC. <a href="http://www.ccsinfo.com/faq/?6" TARGET="_blank"> <a href="http://www.ccsinfo.com/faq/?6" TARGET="_blank">http://www.ccsinfo.com/faq/?6</a></a>
:=
:=If that works, then remove the loopback connection and
:=connect the MAX232 to the PIC again. It should work.
:=Make sure you have a ground wire going from pin 5 on the
:=DB-9 to the MAX232's and the PIC's ground.
:=
:=
:=#include <16F877A.h>
:=#use delay(clock=4000000)
:=#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
:=#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7, ERRORS)
:=
:=void main()
:={
:=printf("start");
:=
:=while(TRUE)
:= putc( getc());
:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515021 |
|
|
|
|
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
|