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

Can open ADC port full time?

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



Joined: 07 May 2007
Posts: 69

View user's profile Send private message

Can open ADC port full time?
PostPosted: Tue Mar 17, 2009 5:45 pm     Reply with quote

Hi!
In 16F886, I use ANO & AN4 for capture 2 voltages( 0.2Volts & 1.5 Volts ). Can I turn on ANO & AN4 full time or every time I read ADC I must turn on and turn off. My project read as dynamic data. What way is correct? Now I destroy this port in 2-4 hours.
Code:

#include <16F886.h>
#device  ADC=10                   
#define  CLOCK_SP   4000000
#fuses   hs,NOLVP,WDT,NOPROTECT,NOPUT,NOBROWNOUT,NOCPD,NOWRT,NODEBUG
#use     delay (clock=CLOCK_SP)   
#use     fast_io(A)
#use     fast_io(B)
#use     fast_io(C)             
#byte    port_b=6                 
#byte    OSCCON = 0x08F
#ROM 0x2100 = {0x00}
.
#define  Vbat    PIN_A0            // Input Analog AN0 Leg2,check Battery Voltages.
#define  OverMo  PIN_A5            // Input Analog AN4 Leg7,check motor drive current
#define  Bz      PIN_A3            // Output Buzzer Leg5
#define  Fl      PIN_C4            // Output Flash Leg15
.
#define  Vbe    0.0048875855327468230694037145650049  // Vcc/ADC10 = (5/1023)
.
float    Vreadch,Vm_ref
.

Void     main()
{
 OSCCON=0x60;                                         
 while ((OSCCON&0x4)!=0x4);                           
 setup_ccp1(CCP_CAPTURE_FE);                          // Configure CCP1 to capturerise
 setup_ccp2(CCP_OFF);
 enable_interrupts(INT_CCP1);                         // Enable interrupt CCP1
 enable_interrupts(GLOBAL);                           // All interrupts ON
 setup_adc_ports(sAN0 | sAN4);                        // Fix Port AN0 & AN4 for ADC
 setup_adc(adc_clock_internal);
 setup_spi(FALSE);
 enable_interrupts(INT_TIMER0);                       // enable interrupt timer0
 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);             // setup timer0 enabled
 set_timer0(0);                                       // set timer0
 setup_timer_1(T1_DISABLED);                          // setup timer1 disabled
 setup_timer_2(T2_DISABLED,0,1);                      // setup timer2 disabled
 set_tris_a(0b00110001);                             
 set_tris_b(0xF8);                                   
 set_tris_c(0b11101101);                             
 setup_wdt(WDT_2304MS);
 output_low(Bz);output_low(Fl);
 while(1)
      {
       .
       .
       set_adc_channel(0);delay_us(10);               // Read Analog input AN0 (channel=0)
       Vreadch=read_adc();delay_us(10);
       Vreadch =Vreadch*Vbe;
       if (Vreadch < 1.5 ) output_high(Bz);
       Out7seg(Vreadch);                              // LED 7 Segment 3 digits.
       delay_ms(1000);output_low(Bz);restart_wdt();     
       .
       set_adc_channel(4);delay_us(10);               // Read Analog input AN4 (channel=4)
       Vreadch=read_adc();delay_us(10);
       Vreadch =Vreadch*Vbe;
       if (Vreadch > 0.2 ) output_high(Fl);
       Out7seg(Vreadch);delay_ms(1000);output_low(Fl);restart_wdt();
       .
       .
      }
}
[/quote]

OR

[quote]
Void     main()
{
 .
 .
 setup_adc_ports(NO_ANALOGS);                         // Don't fix port for ADC
 setup_adc(ADC_OFF);                                  // Analog to digital off
 .
 while(1)
      {
       .
       .
       setup_adc_ports(sAN0);setup_adc(adc_clock_internal); // Turn on ADC AN0
       set_adc_channel(0);delay_us(10);                // Read Analog input AN0 (channel=0)
       Vreadch=read_adc();delay_us(10);
       setup_adc_ports(no_analogs);setup_adc(adc_Off); // Don't fix ADC port, ADC off
       Vreadch =Vreadch*Vbe;
       if (Vreadch < 1.5 ) output_high(Bz);
       Out7seg(Vreadch);                               // LED 7 Segment 3 digits.
       delay_ms(1000);output_low(Bz);restart_wdt();     
       .
       setup_adc_ports(sAN4);setup_adc(adc_clock_internal); // Turn on ADC AN4
       set_adc_channel(4);delay_us(10);                // Read Analog input AN4 (channel=4)
       Vreadch=read_adc();delay_us(10);
       setup_adc_ports(no_analogs);setup_adc(adc_Off); // Don't fix ADC port, ADC off
       Vreadch =Vreadch*Vbe;
       if (Vreadch > 0.2 ) output_high(Fl);
       Out7seg(Vreadch);delay_ms(1000);output_low(Fl);restart_wdt();
       .
       .
      }
}


Regards


Last edited by sorasit46 on Tue Mar 17, 2009 6:03 pm; edited 1 time in total
sorasit46



Joined: 07 May 2007
Posts: 69

View user's profile Send private message

PostPosted: Tue Mar 17, 2009 5:59 pm     Reply with quote

Why I can reprogram this destroy chip (verify after programming pass). I use EPIC Version 2.46 Beta. In fact this chip can not use ADC port.
regards
Sydney



Joined: 13 Feb 2009
Posts: 71

View user's profile Send private message

PostPosted: Wed Mar 18, 2009 4:51 pm     Reply with quote

You dont need to turn it off, but you need to read the datasheet as you are using adc_clock_internal, which you shouldnt be.
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