hi
I want to use adc on 16f877a and write a code include timer 1 and 2 and adc....
When i compile the code its compile with no error but in simulation i have many errors like this:
[PIC16 ADC] PC=0x02D4. ADC conversion started before 'wait' time has expired following previous conversion or channel change. [U1]

and its repeat every second....i dont know why....this is my code...pls help and tnx

Which 'simulator'? If 'Proteus/ISIS', please read PIC101 sticky. It is well known to NOT simulate PICs 100% properly.
Now as a general comment, you should add comments ( //what this line does...) to almost every line of code. While you may know what variables are for and how the 'math' works, we don't.
Also check the ADC section of the datasheet. Selecting setup_adc(ADC_CLOCK_INTERNAL); is usually reserved for when SOME PICs are put to sleep.

NAVID

Joined: 14 Jun 2017Posts: 18

Posted: Fri Mar 02, 2018 10:56 am

temtronic wrote:

Which 'simulator'? If 'Proteus/ISIS', please read PIC101 sticky. It is well known to NOT simulate PICs 100% properly.
Now as a general comment, you should add comments ( //what this line does...) to almost every line of code. While you may know what variables are for and how the 'math' works, we don't.
Also check the ADC section of the datasheet. Selecting setup_adc(ADC_CLOCK_INTERNAL); is usually reserved for when SOME PICs are put to sleep.

hi
yes its Proteus and I test also in real hardware and it has problem....its not simulation problem....
and what is PIC101 sticky???

temtronic

Joined: 01 Jul 2010Posts: 5878Location: Greensville,Ontario

Posted: Fri Mar 02, 2018 11:50 am

At the top of the discussion list, there are a few 'stickies'. These are postings that everyone should read. They are 'answers' to very common questions.

As for the hardware not working, does it run a '1HZ LED ' program properly ?
This program should be the first one you code/compile and run. It should flash an LED at a 1Hz rate.

PCM programmer

Joined: 06 Sep 2003Posts: 20172

Posted: Fri Mar 02, 2018 12:00 pm

Quote:

set_adc_channel(0);
delay_us(20);
a0=read_adc();

You have the correct 20 usec delay for the 16F877A. Therefore, the
most likely reason is your simulator clock is not set to the same
frequency as your #use delay(clock=xxxx).
You didn't post your main2.h file, so we don't know what your #use delay() is.

NAVID

Joined: 14 Jun 2017Posts: 18

Posted: Fri Mar 02, 2018 1:45 pm

PCM programmer wrote:

Quote:

set_adc_channel(0);
delay_us(20);
a0=read_adc();

You have the correct 20 usec delay for the 16F877A. Therefore, the
most likely reason is your simulator clock is not set to the same
frequency as your #use delay(clock=xxxx).
You didn't post your main2.h file, so we don't know what your #use delay() is.

oh sorry once i think maybe if i increase delay it should be OK but its not then i change it to 10....like ccs help

and its header:

Code:

#include <16F877A.h>
#device ADC=10
#use delay(crystal=20000000)

NAVID

Joined: 14 Jun 2017Posts: 18

Posted: Fri Mar 02, 2018 2:09 pm

temtronic wrote:

At the top of the discussion list, there are a few 'stickies'. These are postings that everyone should read.they are 'answers' to very common questions.

As for the hardware not working, does it run a '1HZ LED ' program properly ?
This program should be the first one you code/compile and run. It should flash an LED at a 1Hz rate.

aha you mean i write a code 1hz led and if it flashing so the program is correct???
i am sure program have some problem with adc....cause when i disable it everything is ok....

temtronic

Joined: 01 Jul 2010Posts: 5878Location: Greensville,Ontario

Posted: Fri Mar 02, 2018 7:58 pm

The testing using a 1Hz LED program will confirm that your PCB and PIC are operating. You should see the LED flash at a nominal 1 Hz rate. If it does, you KNOW the PIC is good and can proceed with more complicated programs. If it doesn't, you need to find the error (hardware or software) and correct as required.

ADC_CLOCK_INTERNAL is NOT a valid selection for a PIC running at 20 MHz clock speed.

Jay

NAVID

Joined: 14 Jun 2017Posts: 18

Posted: Sat Mar 03, 2018 12:57 pm

temtronic wrote:

The testing using a 1Hz LED program will confirm that your PCB and PIC are operating. You should see the LED flash at a nominal 1 Hz rate. If it does, you KNOW the PIC is good and can proceed with more complicated programs. If it doesn't, you need to find the error (hardware or software) and correct as required.

ADC_CLOCK_INTERNAL is NOT a valid selection for a PIC running at 20 MHz clock speed.

Jay

hi....i write " output_toggle(pin_a5);" in #int_rtcc so led flashing by 1 hz...and its work correctly
and also i change the "setup_adc(ADC_CLOCK_INTERNAL);" to " setup_adc(ADC_CLOCK_DIV_64);" but still i have same problem...
what is the problem??

temtronic

Joined: 01 Jul 2010Posts: 5878Location: Greensville,Ontario

Posted: Sat Mar 03, 2018 3:01 pm

please post your current program that fails...

Ttelmah

Joined: 11 Mar 2010Posts: 12736

Posted: Sun Mar 04, 2018 1:50 am

and post the main.h (which is vital), and tell us what crystal is on the actual chip.

Last edited by NAVID on Sun Mar 04, 2018 3:35 am; edited 1 time in total

NAVID

Joined: 14 Jun 2017Posts: 18

Posted: Sun Mar 04, 2018 3:32 am

Ttelmah wrote:

and post the main.h (which is vital), and tell us what crystal is on the actual chip.

#include <16F877A.h>
#device ADC=10
#use delay(crystal=20000000)

and i use 20mhz crystal

Ttelmah

Joined: 11 Mar 2010Posts: 12736

Posted: Sun Mar 04, 2018 4:41 am

OK. I'd say that the error is just a fault with Proteus.
I've seen exactly the same on another chip, where the acquisition time is hardware programmable, and was set to MicroChip's recommendations, directly from the data sheet, yet Proteus perpetually complained about inadequate acquisition time.
This is a typical example of the sort of problem that Proteus has.....

However this does assume you have set the clock in Proteus that the simulation is using to 20MHz.

PCM programmer

Joined: 06 Sep 2003Posts: 20172

Posted: Sun Mar 04, 2018 7:26 am

Right, but he's not even following the 16F877A data sheet.

Here, he's tossing numbers around and not even putting them in the
correct place:

Quote:

/* set_adc_channel(0);
delay_us(0);
a0=read_adc(20);

set_adc_channel(1);
delay_us(20);
a1=read_adc(); */

Here, he is violating the delay specification given in the 16F877A data sheet: