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 CCS Technical Support

12f675 Adc

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



Joined: 19 May 2012
Posts: 26
Location: Pakistan

View user's profile Send private message

12f675 Adc
PostPosted: Thu Jul 12, 2012 5:27 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jul 12, 2012 5:45 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jul 12, 2012 8:35 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jul 13, 2012 5:15 am     Reply with quote

Thnx.

This did it.
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