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

12F675 need help with configuring comparator and int vref

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



Joined: 14 Oct 2008
Posts: 103

View user's profile Send private message

12F675 need help with configuring comparator and int vref
PostPosted: Sun Aug 09, 2009 1:39 am     Reply with quote

hello,
I want to use comparator interrupt.
Currently PIC's pin are used as outputs. I just want to know:

1) Using pin 6 will affect vref? (if I use internal vref).
2) I'm hoping to use pin 7 as both input and output. I need to use pin 7 as comparator input while not using as output. While using as a output I disable comparator interrupt? Is this possible?

I already tried some but comparator works only if I ground pin 6 and pull down pin 7.

I have no idea how to setup comparator and internal vref. I read help file but I still don't understand what is different between vref_high and vref_low, and how to choose this option.

I'm new to ccs c, my compiler version is 4.084.

Here is my code:
Code:

#include "C:\Documents and Settings\Aruna\My Documents\fan project\adding timer\main.h"
#PRIORITY COMP,EXT
//A4-buzzer
//A5-count/reset
//A3-IR
//A2-zero cross
//A1-LED
//A0-optoisolator
int speed=0;
int count=0;
int timer0_on=0;
int timer_mode=0;
int16 timer0_count=0;
int timer_set=0;
int time_min=0;
int timer_det_mode = 0;
int timer_set_mode = 0;
int second=0;
int minute=0;
int quater_mili=0;
int first_INT_done=0;
int zero_cross_count=0;
int temp=0;
int A4_int_mode=1;

void set_timer();
void finalize_timer();
void chk_ir();
void beep(INT times,int length);
void led(char mode,INT times,int length);
void read_temp();
void fire(int delay);

//#INT_RA

/*void int_on_change_A4 (void)
{
if(A4_int_mode==1)
{
led('r',2,50);
}
} */


#int_COMP
void  COMP_isr(void)
{
beep(2,50);
delay_ms(500);
//led('r',3,100);


}

#INT_EXT

void  EXT_isr(VOID)
{
   chk_ir ();
   output_low (PIN_A0);
   zero_cross_count++;

   IF (speed == 0)
   {
     
      output_low (PIN_A0);
   }

   else IF (speed == 1)
   {
      IF (zero_cross_count == 5)
      {
         delay_ms (1);
         output_high (PIN_A0);
         zero_cross_count = 0;
         delay_ms (1);
         output_low (PIN_A0);
      }
   }
   

   else IF (speed == 2)
   {
      fire(6);
      //delay_ms (6);
      //output_high (PIN_A0);
   }

   else IF (speed == 3)
   {
   fire(4);
      //delay_ms (4);
      //output_high (PIN_A0);
   }

   else IF (speed == 4)
   {
      fire(2);
      //delay_ms (2);
      //output_high (PIN_A0);
   }

   else IF (speed == 5)
   {
     
      {
         read_temp();
         if(temp>=60 && temp<=62)//for testing
         {
         led('r',1,10);
         }
         delay_ms (1);
         output_high (PIN_A0);
         zero_cross_count = 0;
         delay_ms (1);
         output_low (PIN_A0);
      }
   }
}

#INT_TIMER1

void  TIMER1_isr(VOID)
{
   quater_mili++;
   led ('r', 0, 0) ;

   IF (quater_mili == 4)
   {
      quater_mili = 0;
      second++;

      IF (second == 60)
      {
         second = 0;
         minute++;
         
         /*IF (minute == 1)//for testing
         {
            disable_interrupts (INT_EXT);
            output_low (PIN_A0);
           
            beep (1, 1000) ;
            led ('o', 0, 0) ;
            reset_cpu();
            minute = 0;
            time_min = 0;
            disable_interrupts (INT_TIMER1);
         }*/

          IF (minute == time_min)//real thing
         {
            output_low (PIN_A0);
            beep (1, 1000) ;
            led ('o', 0, 0) ;
            reset_cpu();
            minute = 0;
            time_min = 0;
            disable_interrupts (INT_TIMER1);
         }
      }
   }
}

#INT_TIMER0

void  TIMER0_isr(VOID)
{
   IF (timer_det_mode == 1)
   {
      IF (timer0_count < 5000)
      {
         timer0_count++;
      }

      else IF (timer0_count >= 5000)
      {
         //timer mode on
         timer_mode = 1;
         
         disable_interrupts (INT_TIMER0);
         
         timer0_count = 0;
         first_INT_done = 1;
      }
   }

   IF (timer_set_mode == 1)
   {
      IF (timer0_count < 3000)
      {
         timer0_count++;
      }

      else IF (timer0_count >= 3000)
      {
         
         disable_interrupts (INT_TIMER0);
         timer0_count = 0;
         finalize_timer ();
      }
   }
}

void count_up()
{
   output_low (PIN_A5);
   delay_ms (1);
   output_FLOAT (PIN_A5);
}

void reset()
{
   output_high (PIN_A5);
   delay_ms (1);
   output_FLOAT (PIN_A5);
}

void beep(INT8 times,int length)
{
int i = 0;
//disable_interrupts(INT_RA4); // today
   
   FOR (i = 1; i <= times; i++)
   {
      output_high (PIN_A4);
      delay_ms (length);
      //output_low (PIN_A5);
      output_float(PIN_A4);

      IF (i != times)
      {
         delay_ms (length);
      }
   }
  // enable_interrupts(INT_RA4);// today
}

void led(char mode,INT times,int length)
{
   IF (length == 0)//default
   {
      length = 50;
   }

   IF (mode == 'o') //turn off
   {
      output_FLOAT (PIN_A1);
   }

   else IF (mode == 'r') //red
   {
      INT i = 0;
      output_FLOAT (PIN_A1);

      IF (times == 0)
      {
         output_high (PIN_A1);
      }

      ELSE
      {
         FOR (i = 1; i <= times; i++)
         {
            output_high (PIN_A1);
            delay_ms (length);
            output_FLOAT (PIN_A1);
            delay_ms (length);
         }
      }
   }

   else IF (mode == 'g') //green
   {
      INT i = 0;
      output_FLOAT (PIN_A1);

      IF (times == 0)
      {
         output_low (PIN_A1);
      }

      ELSE
      {
         FOR (i = 1; i <= times; i++)
         {
            output_low (PIN_A1);
            delay_ms (length);
            output_FLOAT (PIN_A1);
            delay_ms (length);
         }
      }
   }
}

void finalize_timer() // this code does not run
{
   led ('r', 0, 0) ;
   beep (3, 50) ;
   reset () ;
   speed = 0;
   timer_mode = 0;
   timer_set = 1;
   timer_set_mode = 0;
   enable_interrupts (INT_TIMER1);
   enable_interrupts (INT_EXT);
}

void set_timer() // this code runs
{
   disable_interrupts (INT_EXT);
   timer_det_mode = 0;
   
   beep (2, 50) ;
   reset();
   led ('r', 2, 50) ;
   led ('g', 0, 0) ;
   timer0_count = 0;
   timer_set_mode = 1;
   //x = 1;
   enable_interrupts (INT_TIMER0); // eneabling for second time
   time_min = 0;
   
   WHILE ( ! timer_set)
   {

      IF (! input (PIN_A3) &&time_min <= 270) //time_min should be < 270----- need to add
      {
         delay_ms (1000);
         beep (1, 100) ;
         led ('r', 0, 0) ;
         delay_ms (50);
         led ('g', 0, 0) ;
         timer0_count = 0;
         time_min = time_min + 30;
         count_up ();
      }
   }
}

VOID chk_ir  ()
{
   IF ( ! input (PIN_A3))
   {
      count++;
      delay_ms (500);
      beep (1, 50) ;
     
     
      IF (speed == 0)
      {
      }

     
      IF (speed != 5 &&count <= 5)
      {
         count_up ();
         speed++;
      }

     
      else IF (count == 6)
      {
         speed = 0;
         
         timer_det_mode = 1;
         enable_interrupts (INT_TIMER0); //eneabling for first time;
         count_up();
         
         timer0_on = 1;
         led ('g', 0, 0); //green
      }

      else IF (count >= 7)
      {
         count = 0;

         IF (timer_mode == 0)
         {
            led ('o', 0, 0) ;
            disable_interrupts (INT_TIMER0);
            first_INT_done = 0;
            reset ();
            speed = 0;
         }
      }

      delay_ms (500);
   }
}

void read_temp()
{
   //disable_interrupts(INT_RA4);// today
   output_float(PIN_A4);
   setup_adc_ports (sAN3|VSS_VDD);
   setup_adc (ADC_CLOCK_INTERNAL);
   set_adc_channel(3);
   delay_us(10);
   temp=read_adc();
   delay_us(10);
   setup_adc_ports (NO_ANALOGS|VSS_VDD);
   setup_adc (ADC_OFF);
  // enable_interrupts(INT_RA4);// today
   
}

void fire(int delay)
{
disable_interrupts(INT_COMP);
delay_ms(delay);
output_high(PIN_A0);
delay_ms(1);
output_float(PIN_A0);
enable_interrupts(INT_COMP);
}

void main()
{
   setup_adc_ports (NO_ANALOGS|VSS_VDD);
   setup_adc (ADC_OFF);
   setup_timer_0 (RTCC_INTERNAL|RTCC_DIV_4);
   setup_timer_1 (T1_INTERNAL|T1_DIV_BY_4);
   //setup_comparator (NC_NC);
   //setup_vref (FALSE);
   
   setup_comparator(A1_VR);//today
   setup_vref(VREF_HIGH|9);//today
   enable_interrupts(INT_COMP);//today
   
   output_FLOAT (PIN_A4);
   output_FLOAT (PIN_A1);
   output_FLOAT (PIN_A5);
   
   
   reset ();
   delay_ms (1000);
   
   enable_interrupts (INT_EXT);
   //enable_interrupts(INT_RA4);// today
   disable_interrupts (INT_TIMER1);
   disable_interrupts (INT_TIMER0);
   enable_interrupts (GLOBAL);
   
   // TODO: USER CODE!!
   
   
   WHILE (1)
   {
      chk_ir ();

      if (first_INT_done == 1)
      {
         first_INT_done = 0;
         set_timer ();
      }
   }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Aug 09, 2009 3:27 pm     Reply with quote

Quote:
I have no idea how to setup comparator and internal vref.

Write a little test program which only uses the Comparator and the
Vref. Get rid of 95% of your existing code. Test it and post it.
Post the results of the test.

The parameters used in the setup_comparator() and setup_vref()
functions are given in the 12F675.h file.
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