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 support@ccsinfo.com

hi all help in coding using ccs c

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



Joined: 14 Oct 2006
Posts: 27
Location: islamabad,pakistan

View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger

hi all help in coding using ccs c
PostPosted: Sun Aug 07, 2011 2:20 pm     Reply with quote

How can I get adc value (10BIT) using PIC18f452 mcu? Can I get desired value from sample voltages(0>>5volt) at which i decided some control action?
e.g
If adc read routine read the value 3volt dc then I want to switch ON the portc.1 and send this value to Serial port.

thank you
MiniMe



Joined: 17 Nov 2009
Posts: 50

View user's profile Send private message

PostPosted: Sun Aug 07, 2011 4:20 pm     Reply with quote

Hi ihsanbu


I believe i got just the thing your looking for.

If it a function that inputs a ADC value ( number 0 - 1023, 2^10 bit ) and output (returns) a voltage varuble that is equal* to ADC value.

This function do use ADC limits. Upper limit and lower limit: references - min and max. Look it up. Normal (without references) ADC assigned 10bit number to voltage 0-5V. This function only sees* voltage values between 1,2 - 3,4V. It is for increasing accuracy as voltages below 1,2 and 3,4 are not used.



Code:

unsigned int16 ADC2voldid(int16 adc_v22rtus)
{
   //Muutujate deklareerimine
                             
   unsigned int32 voldid;
   unsigned int16 voldid_16;
   
   //Muutujasse "adc_v22rtus" l2heb ADC registi v22rtus
   //adc_v22rtus = adc_keskmine(0);
   
   //Valem, et teisendada ADC v22ruts -- > Pingeks (V)
   //100000 on ylemise ja alumise piiri vahe, antud juhul 3,4V - 1,2V = 2.2V
   voldid = (unsigned int32) (( adc_v22rtus * 220000));       
   voldid_16 = (unsigned int16) ( (voldid >> 10) / 100);
   voldid_16 += 1200; // on alumine piir, antud juhul 1.2V;   
   //Funktsiooni tagatis (v22rtus)
   //printf("\n\rvoldid_16 %Ld",voldid_16);
   return voldid_16;     
}     
 



The ADC value in variable "int16 adc_v22rtus", you can get from read_adc( ) function. Look up "read_adc( )" from CCS help.

So your code part should look like:
You should put tease 2 function into loop. From function ADC2voldid you will get value that represent voltage something like int16 value 302. it should mean that its around 3 V.

Code:

while(1) {

   if( ADC2voldid( read_adc(0) ) > 300)  {   //0 means ADC pin 0.
   
   output_c(0b11111111); // port C all pins high

   Printf("\n\rVoltage is over 3V, exactly %Lu",ADC2voldid( read_adc(0) ); // outputs string by serial port.

   }
   else{

   output_c(0b00000000); // port C all pins low

   }

}



I hope i understood your problem. I wish you good luck with your task.
ihsanbu



Joined: 14 Oct 2006
Posts: 27
Location: islamabad,pakistan

View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger

thank you
PostPosted: Mon Aug 08, 2011 2:11 pm     Reply with quote

thank you
_________________
ihsan ullah khan
Embedded Designer Since 2003
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