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

PIC10f220 adc not working

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



Joined: 16 Aug 2010
Posts: 19

View user's profile Send private message

PIC10f220 adc not working
PostPosted: Mon Aug 16, 2010 7:47 am     Reply with quote

Hi,

This code is working great on the PIC16F506-ICD on the debug mode.

But when it programmed and running from the PIC10F220, it seems the ADC isn't working.

I tried any value from 0 to 255, with voltage between VCC to GND.

Attached the compliation and code, is there something bad in the ADC set up ?
Code:

#include <10F220.h>

#FUSES NOWDT                      //No Watch Dog Timer
#FUSES NOMCLR                     //Master Clear pin: disable
#FUSES NOPROTECT                  //Code protected from reads
//#FUSES IOSC4
//#use delay(Clock=4MHZ,OSC)
#use delay(clock=4000000)         // Only for Debug Mode
// #bit OSCCAL_0 = 0x05.0           // Disable OSC on GP2, Enable as I/O


// Voltage Table:
// 0.9v=48 ; 0.8v=45 ; 0.7v=38
// 1v=54 ; 1.1v=59 ; 1.2v=66 ; 1.3v=69/70 ; 1.4v=76 ; 1.5v=81 ; 1.6v=85
// 1.7v=90 ; 1.8v=95 ; 1.9v=101 ;
#define DELAY 1

//========================================================================

      
 void main()
{
   int flag = 0;
   long value = 0;
   int step;   
   unsigned char cnt0 = 0; // counter
    unsigned char cnt1 = 0; // counter
   unsigned char cnt2 = 0; // counter
   unsigned char sGPIO = 0;
   
   setup_adc_ports(sAN1);
   setup_adc(ADC_CLOCK_DIV_4);
        
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_counters(RTCC_INTERNAL,RTCC_DIV_1|DISABLE_PULLUPS); //|DISABLE_PULLUPS
   setup_wdt(WDT_2304MS);
 // setup_adc( ALL_ANALOG );   
 // setup_adc_ports( ALL_ANALOG );
 //   setup_adc( ADC_OFF );
   
   set_adc_channel(1); //PIN4
//   set_adc_channel(0);

     SET_TRIS_B(0b11111010); //GP0,1,2 as Output; GP3 as Input(default)
//   OSCCAL_0 = 0;
//        output_b(0);
//      sGPIO = 0;

// Start ADC


   while (1)  {      // ADC Port

        read_adc(ADC_START_ONLY);

       value = read_adc();

       delay_us( 10 );

       value=read_adc(ADC_READ_ONLY);

    if (value  > 10 ){  //&& cnt0 >= 4){
         cnt0 = 0;
       //   beeper_on ();
      
      for(step = 0;step < 5000 ;step++ ){  //  Loop control
              
               //cnt0 = 0;
          output_low(PIN_B0); // Sound sequence
         restart_wdt();
           delay_us(168);            // 168 = 5khz for DSP
           output_high(PIN_B0);
         restart_wdt();
           delay_us(168);
      }     
          }
       

    else
   
      
   //      beeper_off ();
   
    for(step = 0;step < 5000 ;step++ ){ //  Loop control
              
         
           output_low(PIN_B0); // Sound sequence
           restart_wdt();
            delay_us(168);            // 0 = 0khz for DSP
            output_low(PIN_B0);
           restart_wdt();
           delay_us(168);
         
           }            
 
  }
}

This is the compliation capture:

Code:
Clean: Deleting intermediary and output files.
Clean: Deleted file "C:\PIC\ADC.ESYM".
Clean Warning: File "C:\PIC\ADC.o" doesn't exist.
Clean: Deleted file "C:\PIC\ADC.HEX".
Clean: Deleted file "C:\PIC\ADC.LST".
Clean: Deleted file "C:\PIC\ADC.PJT".
Clean: Deleted file "C:\PIC\ADC.ERR".
Clean: Deleted file "C:\PIC\ADC.COF".
Clean: Done.
Executing: "C:\Program files\Picc\CCSC.exe" +FB "ADC.c" +DF +LN  +T +A +M -Z +Y=9 +EA #__10F220=TRUE
>>> Warning 203 "ADC.c" Line 52(1,1): Condition always TRUE
>>> Warning 203 "ADC.c" Line 66(1,1): Condition always TRUE
>>> Warning 203 "ADC.c" Line 84(1,1): Condition always TRUE
>>> Warning 202 "ADC.c" Line 23(10,14): Variable never used:   flag
>>> Warning 202 "ADC.c" Line 27(24,28): Variable never used:   cnt1
>>> Warning 202 "ADC.c" Line 28(20,24): Variable never used:   cnt2
>>> Warning 202 "ADC.c" Line 29(21,26): Variable never used:   sGPIO
      Memory usage:   ROM=45%      RAM=81% - 81%
      0 Errors,  7 Warnings.
Loaded C:\PIC\ADC.cof.
BUILD SUCCEEDED: Mon Aug 16 16:30:42 2010
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Mon Aug 16, 2010 8:26 am     Reply with quote

Code:

int step
...
...
for(step = 0;step < 5000 ;step++ )

you define step as an 8 bit int but expect it to reach 5000. This will never happen.
Once in the loop it will never leave.

Change to

int16 step

*edit*
Code:

read_adc(ADC_START_ONLY);

value = read_adc();

delay_us( 10 );

value=read_adc(ADC_READ_ONLY);


You set adc to start only but imediately do a read_adc which will override your start. You wait 10 us and then try to read the ADC BUT your previous read will have killed the START_ONLY.

Just use value = read_adc and remove the other stuff.

*edit again*

Code:

SET_TRIS_B(0b11111010); //GP0,1,2 as Output; GP3 as Input(default)

This is redundant as you are not using fast_io, you can remove it.
eabir



Joined: 16 Aug 2010
Posts: 19

View user's profile Send private message

Well now it works
PostPosted: Mon Aug 16, 2010 9:47 am     Reply with quote

Thanks!
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