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

16C773 analog problems

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







16C773 analog problems
PostPosted: Tue Oct 30, 2001 11:09 am     Reply with quote

Hello,

I've just tried to port a program over from a 16F876 to a 16C773 so as to make use of the 12 bit ADC on this part (I'm using v2.734). The program seems to fall over on ADC reading, and adc_read() just keeps returning 4095. Here is a listing for the 16F876 which seems to work fine:-

#include <16f876.h>
#fuses XT, NOWDT, NOPUT, NOPROTECT, NOBROWNOUT
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

main()
{
setup_adc_ports(RA0_ANALOG);
setup_adc(ADC_CLOCK_DIV_8);
set_adc_channel(0);

while(TRUE)
{
printf("\%lu\n\r", read_adc());
delay_ms(100);
}
}

And here's the ported code for the 16C773:-

#include <16c773.h>
#fuses XT, NOWDT, NOPUT, NOPROTECT, NOBROWNOUT
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

main()
{
setup_adc_ports(ANALOG_A0);
setup_adc(ADC_CLOCK_DIV_8);
set_adc_channel(0);

while(TRUE)
{
printf("\%lu\n\r", read_adc());
delay_ms(100);
}
}

The only changes I had to make, was the first line in main() where the #define in the header file 16c773.h is different for single channel ADC conversion. As I mentioned above, this version just outputs 4095 no matter what voltage (within power rails) was applied. In the header file, I noticed that there are extra options that can be or'd with other options to set up the reference for the ADCs, however since my preferred option "VSS_VDD" is defined to be 0x00, I didn't bother to add it. I also made sure I connected the power pins correctly as they are different to the 16F876.

Any help appreciated.

Tone.
___________________________
This message was ported from CCS's old forum
Original Post ID: 891
Tomi
Guest







Re: 16C773 analog problems
PostPosted: Tue Oct 30, 2001 3:22 pm     Reply with quote

Try to separate the printf() and Read_ADC() functions:
unsigned long value;
value = read_adc();
printf("\%lu\n\r", value);

:=
:=Hello,
:=
:=I've just tried to port a program over from a 16F876 to a 16C773 so as to make use of the 12 bit ADC on this part (I'm using v2.734). The program seems to fall over on ADC reading, and adc_read() just keeps returning 4095. Here is a listing for the 16F876 which seems to work fine<img src="http://www.ccsinfo.com/pix/forum/disagree.gif" border="0">
:=
:=#include <16f876.h>
:=#fuses XT, NOWDT, NOPUT, NOPROTECT, NOBROWNOUT
:=#use delay(clock=4000000)
:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=
:=main()
:= {
:= setup_adc_ports(RA0_ANALOG);
:= setup_adc(ADC_CLOCK_DIV_8);
:= set_adc_channel(0);
:=
:= while(TRUE)
:= {
:= printf("\%lu\n\r", read_adc());
:= delay_ms(100);
:= }
:= }
:=
:=And here's the ported code for the 16C773<img src="http://www.ccsinfo.com/pix/forum/disagree.gif" border="0">
:=
:=#include <16c773.h>
:=#fuses XT, NOWDT, NOPUT, NOPROTECT, NOBROWNOUT
:=#use delay(clock=4000000)
:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=
:=main()
:= {
:= setup_adc_ports(ANALOG_A0);
:= setup_adc(ADC_CLOCK_DIV_8);
:= set_adc_channel(0);
:=
:= while(TRUE)
:= {
:= printf("\%lu\n\r", read_adc());
:= delay_ms(100);
:= }
:= }
:=
:=The only changes I had to make, was the first line in main() where the #define in the header file 16c773.h is different for single channel ADC conversion. As I mentioned above, this version just outputs 4095 no matter what voltage (within power rails) was applied. In the header file, I noticed that there are extra options that can be or'd with other options to set up the reference for the ADCs, however since my preferred option "VSS_VDD" is defined to be 0x00, I didn't bother to add it. I also made sure I connected the power pins correctly as they are different to the 16F876.
:=
:=Any help appreciated.
:=
:=Tone.
___________________________
This message was ported from CCS's old forum
Original Post ID: 894
Tone
Guest







Re: 16C773 analog problems
PostPosted: Wed Oct 31, 2001 3:53 am     Reply with quote

Thanks for the reply. I have just tried what you suggested to no effect. It still doesn't work. I just wandered if anyone knows whether the adc_read() function works with the 16C773, as my code is very simple yet still doesn't seem to work?

Regards,

Tone.

:=Try to separate the printf() and Read_ADC() functions:
:=unsigned long value;
:=value = read_adc();
:=printf("\%lu\n\r", value);
:=
___________________________
This message was ported from CCS's old forum
Original Post ID: 899
Kari Leino
Guest







Re: 16C773 analog problems
PostPosted: Wed Oct 31, 2001 7:49 am     Reply with quote

A/D result is given default left justified. Modify line "#define ANALOG_A0 0xE // RA0" to "#define ANALOG_A0 0x8E // RA0" in 16c773.C -file.

:=Hello,
:=
:=I've just tried to port a program over from a 16F876 to a 16C773 so as to make use of the 12 bit ADC on this part (I'm using v2.734). The program seems to fall over on ADC reading, and adc_read() just keeps returning 4095. Here is a listing for the 16F876 which seems to work fine<img src="http://www.ccsinfo.com/pix/forum/disagree.gif" border="0">
:=
:=#include <16f876.h>
:=#fuses XT, NOWDT, NOPUT, NOPROTECT, NOBROWNOUT
:=#use delay(clock=4000000)
:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=
:=main()
:= {
:= setup_adc_ports(RA0_ANALOG);
:= setup_adc(ADC_CLOCK_DIV_8);
:= set_adc_channel(0);
:=
:= while(TRUE)
:= {
:= printf("\%lu\n\r", read_adc());
:= delay_ms(100);
:= }
:= }
:=
:=And here's the ported code for the 16C773<img src="http://www.ccsinfo.com/pix/forum/disagree.gif" border="0">
:=
:=#include <16c773.h>
:=#fuses XT, NOWDT, NOPUT, NOPROTECT, NOBROWNOUT
:=#use delay(clock=4000000)
:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
:=
:=main()
:= {
:= setup_adc_ports(ANALOG_A0);
:= setup_adc(ADC_CLOCK_DIV_8);
:= set_adc_channel(0);
:=
:= while(TRUE)
:= {
:= printf("\%lu\n\r", read_adc());
:= delay_ms(100);
:= }
:= }
:=
:=The only changes I had to make, was the first line in main() where the #define in the header file 16c773.h is different for single channel ADC conversion. As I mentioned above, this version just outputs 4095 no matter what voltage (within power rails) was applied. In the header file, I noticed that there are extra options that can be or'd with other options to set up the reference for the ADCs, however since my preferred option "VSS_VDD" is defined to be 0x00, I didn't bother to add it. I also made sure I connected the power pins correctly as they are different to the 16F876.
:=
:=Any help appreciated.
:=
:=Tone.
___________________________
This message was ported from CCS's old forum
Original Post ID: 902
Tone
Guest







Re: 16C773 analog problems
PostPosted: Wed Oct 31, 2001 9:01 am     Reply with quote

I have just tried this out, and again no joy. Because with the orginal code I was getting no change at all in the result, I wasn't expecting a justification error to be the cause of the problem. I was (and still am) getting 4095 all the time, regardless of input voltage.

Many Thanks,

Tone.


:=A/D result is given default left justified. Modify line "#define ANALOG_A0 0xE // RA0" to "#define ANALOG_A0 0x8E // RA0" in 16c773.C -file.
:=
___________________________
This message was ported from CCS's old forum
Original Post ID: 906
Kari Leino
Guest







Re: 16C773 analog problems
PostPosted: Wed Oct 31, 2001 2:02 pm     Reply with quote

How about Tris registers? Analog inputs reads full scale or zero depending port state if ports are configured as outputs. Set_tris_a(0b00000001);

:=I have just tried this out, and again no joy. Because with the orginal code I was getting no change at all in the result, I wasn't expecting a justification error to be the cause of the problem. I was (and still am) getting 4095 all the time, regardless of input voltage.
:=
:=Many Thanks,
:=
:=Tone.
:=
:=
:=:=A/D result is given default left justified. Modify line "#define ANALOG_A0 0xE // RA0" to "#define ANALOG_A0 0x8E // RA0" in 16c773.C -file.
:=:=
___________________________
This message was ported from CCS's old forum
Original Post ID: 911
argosy



Joined: 07 Sep 2003
Posts: 5
Location: Scotland

View user's profile Send private message

Re: 16C773 analog problems
PostPosted: Wed Oct 31, 2001 3:03 pm     Reply with quote

Yes the Read_ADC() function works on the with the 16c773 because I have ported code from the 16f876 and it worked with little trouble, but the version of PCM I was using did not the support the 16c773 so I had to modify the 16f876.h file to make it work. The other problem you may encounter is that the 12 bit ADC is not 12bit but 11bit at best see the microchip errata ( unless they have fixed it). Also use an off chip voltage reference for the best result. I am sorry that I can only offer these general words of advice as my code is on my works machine and I won't have access to it until next week sometime.
Argosy

:=Thanks for the reply. I have just tried what you suggested to no effect. It still doesn't work. I just wandered if anyone knows whether the adc_read() function works with the 16C773, as my code is very simple yet still doesn't seem to work?
:=
:=Regards,
:=
:=Tone.
:=
:=:=Try to separate the printf() and Read_ADC() functions:
:=:=unsigned long value;
:=:=value = read_adc();
:=:=printf("\%lu\n\r", value);
:=:=
___________________________
This message was ported from CCS's old forum
Original Post ID: 913
Tone
Guest







Re: 16C773 analog problems
PostPosted: Fri Nov 02, 2001 9:17 am     Reply with quote

Well, I have finally got the thing working now, and I have to admit that it was down to my own stupidity. I thought I had got the power lines wired up correctly but it turns out that I hadn't. I made the correction and my ported code now runs.

Many Thanks to all who replied.

Tone.


:=
:=Hello,
:=
:=I've just tried to port a program over from a 16F876 to a 16C773 so as to make use of the 12 bit ADC on this part (I'm using v2.734).
___________________________
This message was ported from CCS's old forum
Original Post ID: 925
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