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

I am trying to get result from adc pin 12F675

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



Joined: 15 Dec 2016
Posts: 13
Location: delhi

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

I am trying to get result from adc pin 12F675
PostPosted: Sat Aug 21, 2021 3:24 am     Reply with quote

Code:

    #include <12f675.h>
    #device adc=10
    #fuses INTRC_IO, NOWDT, PUT, BROWNOUT, MCLR
    #use delay(clock=4000000)
   
    #define RELAY   PIN_A3       // Relay for 110 v switch
    #define LED     PIN_A5       // TRANSISTOR for chg cut for nicd battery
   
    void main()
    {
      int16 adc_value;
      float batt_volt;
      float mns_volt;
   
      set_tris_a(0b0000111);
      setup_adc(ADC_CLOCK_DIV_32);     
      setup_adc_ports(sAN0|sAN1|sAN2);
      delay_ms(100);
      while(TRUE)
         {
            set_adc_channel(0);// Battery Voltage Sense
             set_adc_channel(2);// mains  Voltage Sense
            adc_value=read_adc();
            batt_volt=adc_value/20.449;
             mns_volt=adc_value/20.449;
            //batt_volt=adc_value*(5/1023);//20.449;
            if (batt_volt >= 13.8 )//<=14.0)// && batt_volt <= 1.0 )
               {
                  delay_ms(3000);
                  output_high(LED);
               }
                if (mns_volt <= 1.0 )//<=3.0)   
              {
                delay_ms(3000);
                 output_high(RELAY);
               }
            else
               {
               output_low(RELAY);
                  delay_ms(3000);
                  output_low(LED);
                 
               }               
         }
    }

_________________
heroswap1981
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Sat Aug 21, 2021 3:31 am     Reply with quote

You have to work like this:
Code:

   set_adc_channel(0);// Battery Voltage Sense
   delay_us(10); //The channel has to be selected long enough
   //for the signal to acquire -> Tacq. Check the data sheet for what this
   //needs to be (9.55uSec min on your chip).
   adc_value=read_adc(); //This now reads the battery voltage

   set_adc_channel(2);// mains Voltage Sense
   delay_us(10);
   adc_value=read_adc(); //This now reads the main voltage sense.


Sequence is always select channel, wait for signal to acquire, then sample
this.
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