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

use pic10f222 internal absolute voltage reference

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



Joined: 09 Nov 2018
Posts: 1

View user's profile Send private message

use pic10f222 internal absolute voltage reference
PostPosted: Fri Nov 09, 2018 10:33 am     Reply with quote

Hi everybody,
I want to use pic10f222 ADC and i have no problem in it:
Code:

#include <10F222.h>

#list
  #device PIC10F222
 #device adc=8
 
 #FUSES NOWDT                    //No Watch Dog Timer
 #FUSES NOPROTECT                //Code not protected from reading
 #FUSES NOMCPU                   //Master Clear Pull-up disabled
 #FUSES NOMCLR
 #FUSES IOSC4                    //INTOSC speed 4 MHz
#device adc=8

#use delay(internal=4000000)
//------------define relay and stair pins---------
#define set_options(value){#ASM    \
                     MOVLW value   \
                       OPTION        \
                     #ENDASM}

setup_adc(true);
set_tris_b (0b111); //set as output
set_options(0xDF);  // Enable pin B2 for normal i/o

set_adc_channel(0);
adc1=read_adc();


But, when when VDD changes the ADC shows different values (and that is also OK because the reference voltage is VDD).
I looked in PIC10F222 data sheet and found "absolute voltage reference" that equals:
result = 0.6 * 256 / VDD
I thought i can get VDD from the equation above and then get the precise adc value as follows:

Code:

adc_set_channel(2);
adc1=read_adc();
vdd=0.6 * 256   / adc1  ;

adc_set_channel(0);
adc=read_adc();
//get the precise adc in proportion of VDD
....


But the adc1 (absolute voltage reference is not going to change with different VDD from 4.9 to 5.2),
How can i fix this problem?
Any help would be appreciated.
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Fri Nov 09, 2018 11:34 am     Reply with quote

First thing, you need to always have a Tacq pause between selecting a channel and reading it. About 7uSec. Otherwise the value will not be correct.

Also, Vdd needs to be declared as 'float' or it won't work (since the value needs to be in fractions of a volt).

Honestly 'better' to do this in integer in a chip this small, so (for instance) declare Vdd as int16, and use.

Vdd=15360/adc1;

This will perform an int16 division (much smaller than the float division), and give a result in tens of mV. So 200 for a 2v supply.
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