|
|
View previous topic :: View next topic |
Author |
Message |
waheed
Joined: 19 May 2012 Posts: 26 Location: Pakistan
|
12f675 Adc |
Posted: Thu Jul 12, 2012 5:27 am |
|
|
I have a simple program to test the ADC. But when i do the simulation on proteus, it show the following msgs:
1: Effect of writing OSCAL register not modelled.
2: ADC conversion started before "wait" time has expired following previous conversion or channel change.
Here is the code:
Code: |
#include<12f675.h>
#fuses NOWDT,HS,NOPROTECT,BROWNOUT,NOPUT,NOCPD,INTRC_IO
#device ADC=10
#use delay(clock=20000000)
#INCLUDE <stdlib.h>
void main()
{
int16 adc_value,value;
setup_ADC(ADC_CLOCK_DIV_64);
setup_ADC_ports(AN0_ANALOG);
set_adc_channel(0);
while (1)
{
output_toggle(PIN_A5);
adc_value=read_adc();
value=5*adc_value/1024;
if (adc_value>3){output_low(PIN_A2);}
if (adc_value<3){output_low(PIN_A4);}
delay_ms(500);
}
}
|
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Thu Jul 12, 2012 5:45 am |
|
|
Doesn't surprise me at all.
Proteus is KNOWN to be FULL of errors,bugs, and faulty DRCs !!
You are best to get rid of it ! remove from PC !!
Unless you want to spend 1000s of hours hacking and rewriting the Proteus 'simulator', move on, get real chips and do real world 'simulation'.
It is well known that Proteus DOES NOT WORK CORRECTLY !!
hth
jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Thu Jul 12, 2012 8:35 am |
|
|
The second error is 'correct' though, on the first time through the loop.
Whenever you select an ADC channel, you _must_ wait for Tacq, _before_ reading. Your code, selects the adc channel, enters the loop, toggles pin A5, and immediately read the adc. Tacq, depends on a number of factors, but from the data sheet for your chip, is just under 10uSec. The instructions you execute at 20MHz, will only take perhaps 1uSec....
Solution is to move the delay, so it gets executed the first time through the loop:
Code: |
void main(void) {
int16 adc_value,value;
setup_ADC(ADC_CLOCK_DIV_64);
setup_ADC_ports(AN0_ANALOG);
set_adc_channel(0);
while (1) {
output_toggle(PIN_A5);
delay_ms(500);
adc_value=read_adc();
value=5*adc_value/1024;
if (adc_value>3){output_low(PIN_A2);}
if (adc_value<3){output_low(PIN_A4);}
}
}
|
Best Wishes |
|
|
waheed
Joined: 19 May 2012 Posts: 26 Location: Pakistan
|
|
Posted: Fri Jul 13, 2012 5:15 am |
|
|
Thnx.
This did it. |
|
|
|
|
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
|