View previous topic :: View next topic |
Author |
Message |
bungee-
Joined: 27 Jun 2007 Posts: 206
|
|
Posted: Thu May 07, 2009 11:28 am |
|
|
First thing I noticed is, that you read adc on port that you use for RS232.
Try to use this code, and report if it is working.
Code: | #include <12F683.h>
#device adc=10
#FUSES NOWDT, INTRC_IO, NOCPD, NOPROTECT, NOMCLR, PUT, NOBROWNOUT, NOIESO, NOFCMEN
#use delay(clock=8000000)
#define ADC1 PIN_A0
#define ADC1 PIN_A1
#define TX PIN_A2
#define RX PIN_A3
#use rs232(baud=9600,parity=N,xmit=PIN_A2,rcv=PIN_A3,bits=8)
void setup()
{
setup_adc_ports(sAN0|sAN1|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC);
setup_vref(FALSE);
setup_oscillator(OSC_8MHZ);
}
void main()
{
int16 AdValue;
int8 Channel;
setup();
while(1)
{
for (Channel=0;channel>=1;channel++);
{
set_adc_channel(Channel);
delay_us(50);
AdValue=read_adc();
printf("Chan: %d=%Lu",Channel,AdValue);
delay_ms(500);
}
}
} |
|
|
|
PICman
Joined: 02 Nov 2007 Posts: 26
|
|
Posted: Thu May 07, 2009 4:15 pm |
|
|
Thanks a lot Bungee !!!! Your code worked !!!
Now, it's time for me to study your code to know what was my error !
Again, thanks a lot ! (I don't know why, i got a lot of problems dealing with ADC, but with the help of this group, i wil get through it !) |
|
|
bungee-
Joined: 27 Jun 2007 Posts: 206
|
|
Posted: Thu May 07, 2009 4:19 pm |
|
|
I went through your code again ... Look at the marked spot....
Code: | setup_adc_ports(all_analog|VSS_VDD); // ADC entre Vdd et Vss // I
setup_adc(ADC_CLOCK_DIV_16); // I
// III
//
setup_comparator(NC_NC); // N N
setup_vref(FALSE); // NN N
setup_ccp1(ccp_off); // N NN
setup_adc(ADC_OFF); // N N <-------- HERE
setup_timer_0(RTCC_INTERNAL); //
setup_timer_1(T1_DISABLED); // III
setup_timer_2(T2_DISABLED,0,1); // I
output_A(0x04); // I
set_tris_A(0b11111011); // III
disable_interrupts(int_timer0); // |
|
|
|
grace
Joined: 09 Feb 2016 Posts: 1 Location: Banned - spammer
|
|
Posted: Tue Feb 09, 2016 3:13 am |
|
|
Sir,
Please can someone tell me the program compiler was used for this program? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19509
|
|
Posted: Tue Feb 09, 2016 3:20 am |
|
|
The CCS C compiler.
Any version for about the last seven years.
Since this is a forum _for_ CCS C. I wonder what compiler you expect to be being used..... |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Tue Feb 09, 2016 6:10 am |
|
|
just a comment...
Your ASCII ART shows a 47K resistor for _MCLR. That's very high. You should use a 4K7r.
If it really is a 47Kr the PIC _might_ randomly reset.
If it is a 4K7r just change your ASCII ART to agree with what you built.
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19509
|
|
Posted: Tue Feb 09, 2016 8:13 am |
|
|
The original thread, was 2009.
'Grace' has just come in asking what compiler it is for.
I doubt if anyone will change art that old!... |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Tue Feb 09, 2016 2:02 pm |
|
|
temtronic wrote: | just a comment...
Your ASCII ART shows a 47K resistor for _MCLR. That's very high. You should use a 4K7r.
If it really is a 47Kr the PIC _might_ randomly reset.
|
Hi Jay,
A 47K pull-up resistor on MCLR with no capacitor is what CCS recommends for use with their ICD-U40 and ICD-U64 Programmer/Debuggers. If this value is 'too high', and might cause the PIC to 'randomly reset', I'd sure appreciate it if you didn't mention that to any of my customers who otherwise seem quite happy!
I've used that same MCLR setup in all my PIC designs over the years, and have got literally thousands of units in the field with no issues! _________________ John
If it's worth doing, it's worth doing in real hardware! |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Tue Feb 09, 2016 2:42 pm |
|
|
OK, I'll keep quiet....
it was a 'gut' response to the ASCII ART..it just 'seemed' wrong, probably a leftover from my 7400 dayze.....
Jay |
|
|
|