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

COMPARATOR INTERRUPT!!!!!

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



Joined: 20 Jan 2005
Posts: 43

View user's profile Send private message

COMPARATOR INTERRUPT!!!!!
PostPosted: Mon Feb 07, 2005 8:52 am     Reply with quote

hI,
I am using the comparator 2 of the PIC16c781.
In the wizard interrupt comparator dosn't exist.
then I used device editor , but in the list of the interrupts there are six or more "comp" options:

COMP 0C.7/8C.7
COMP 0C.6/8C.6
COMP 0C.3/8C.3
COMP2 0C.4/8C.4
COMP 0D.5/8D.5
COMP2 0D.6/8D.6

8ch is the register address for PIE1 and 0Ch is the PIR1
8c.5 enable interrupt Comparator 2
0c.5 is the flag for interrupt
Can you tell me which option I have to check for ???
Thank
PCW 3.218 - Mplab 7.01
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 07, 2005 11:14 pm     Reply with quote

Quote:

I used device editor , but in the list of the interrupts there are six or
more "comp" options. Can you tell me which option I have to check for ?

You would like to see this choice, but you don't have it:

COMP2 0C.5/8C.5

This means you can't add the Comp2 interrupt with the Device Editor.

Here is post in which I show how to add support for an interrupt
which you can't add with the Device Editor.
http://www.ccsinfo.com/forum/viewtopic.php?p=6680
Let's modify that code to work with the 16C781 comparator #2.

Code:
#include <16C781.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT 
#use delay(clock = 4000000)

#bit C2IF_BIT = 0x0C.5
#bit C2IE_BIT = 0x8C.5

#int_default
void default_isr(void)
{
if(C2IE_BIT)     // Is the interrupt enabled ?
  {
   if(C2IF_BIT)  // If so, is the interrupt flag set ?
     {

// Put your own code here, to service the interrupt.


      C2IF_BIT = 0;    // Clear the interrupt flag
     }
  }
}

//===================================
void main()
{
// Put code here to setup the comparators.

// Put code here to enable the Comp2 interrupt
// and also enable Global interrupts.

while(1);
}
Guard



Joined: 20 Jan 2005
Posts: 43

View user's profile Send private message

PostPosted: Tue Feb 08, 2005 10:20 am     Reply with quote

Hi,
This is my main().
I used C2IE_bit for enable interrupt, but it doesn't function.
Note:
I am using both comparators for PSMC

Code:

      TRISA=255;
      TRISB=37;
      WPUB=0;      

        setup_adc_ports( sAN4|VSS_VDD);
        setup_adc(ADC_CLOCK_DIV_32);
               setup_timer_0(RTCC_INTERNAL|RTCC_DIV_128);
         setup_timer_1(T1_DISABLED);
       setup_timer_2(T2_DIV_BY_1,2,1);
         disable_interrupts(INT_RB);
         disable_interrupts(INT_RTCC);

         C2IE_BIT =1;          // Interrupt Comparator

         enable_interrupts(GLOBAL)
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 08, 2005 11:37 am     Reply with quote

I don't see any code that sets up the comparators.

Since your version of the compiler apparently doesn't support
those comparators, you need to setup them up by yourself, with code.

You need to read the data sheet section on comparators, in detail.
You need to use #byte and #bit statements to define the comparator
registers and important bits.

You need to decide what mode you want to put to the comparators in.

You need to study the ASM code examples in the data sheet, which
show how to setup the comparators. You need to learn how to
translate that code into simple C statements.

You need to do this.
Guard



Joined: 20 Jan 2005
Posts: 43

View user's profile Send private message

PostPosted: Tue Feb 08, 2005 12:02 pm     Reply with quote

Hi,
My post is part of my code...
The PSMC is ok, I am studying the asm example code for interrupt
Guard



Joined: 20 Jan 2005
Posts: 43

View user's profile Send private message

PostPosted: Tue Feb 08, 2005 12:25 pm     Reply with quote

Code:

#include "C:\TEST\PSMC.h"

static short int Camp;      
static  int Answer;      
                                                            
////////////////////////////////////////// Ports
#byte Port_b = 0x06
#byte TRISB =0x86
#byte TRISA =0x85

#byte wpub =0x95
#byte Ansel =0x9d

#bit   Fan         =            Port_B.7
#bit  Gate         =            Port_B.6
#bit    pin_datain     =         Port_B.5
#bit    pin_dataout     =         Port_B.4

///////////////////////////////// A/D
#byte REFCON=0X9B

#byte ADCON0 =0X1F
#bit ADCSL= ADCON0.6
#bit ADCSH= ADCON0.7
#bit CHSH= ADCON0.5
#bit CHSM= ADCON0.4
#bit CHSL= ADCON0.3
#bit GODONE= ADCON0.2
#bit CHS3= ADCON0.1
#bit ADON= ADCON0.0

#byte ADCON1=0X9F
#bit  VCFGH= ADCON1.5
#bit  VCFGL= ADCON1.4

//////////////////////////////////////// Comparator interrupt
#byte INTCON = 0x0b
#bit PEIE = INTCON.6

#bit C2IF_BIT = 0x0C.5
#bit C1IF_BIT = 0x0C.4

#bit C2IE_BIT = 0x8C.5
#bit C1IE_BIT = 0x8C.4

//////////////////////////////////////// PSMC
// Register control 0
#byte PSMCCON0 = 0x111
#bit SMCCLH = 0x111.7
#bit SMCCLL = 0x111.6
#bit MINDCH = 0x111.5
#bit MINDCL = 0x111.4
#bit MAXDCH = 0x111.3
#bit MAXDCL = 0x111.2
#bit DCH = 0x111.1
#bit DCL = 0x111.0

/////////////////////////////////////// PSMC
// Register control 1
#byte PSMCCON1 = 0x112
#bit SMCON   = 0x112.7
#bit S1APOL  = 0x112.6
#bit S1BPOL  = 0x112.5
#bit NOTUSED = 0x112.4
#bit SCEN    = 0x112.3
#bit SMCOM   = 0x112.2
#bit PWMPSM  = 0x112.1
#bit SMCCS   = 0x112.0

//////////////////////////////////////// OP AMP
#byte OPACON = 0x11C 
#byte CALCON = 0x110  //
#bit CMPEN=OPACON. 6 
#bit OPAON=OPACON. 7 
#bit GBWP =OPACON. 0
#bit CAL =   CALCON.7
#bit CALREF=   CALCON.5

/////////////////////////////////////// comparator 1
#byte CM1CON0 = 0x119  // comparator 1
#bit  C1ON  = 0X119.7
#bit  C1OUT = 0X119.6
#bit  C1OE  = 0X119.5
#bit  C1POL = 0X119.4
#bit  C1SP  = 0X119.3
#bit  C1R   = 0X119.2
#bit  C1CHH  = 0X119.1
#bit  C1CHL  = 0X119.0

///////////////////////////////////////  comparator 2
#byte CM2CON0 = 0x11A  // comparator 2
#bit  C2ON  = 0X11A.7
#bit  C2OUT = 0X11A.6
#bit  C2OE  = 0X11A.5
#bit  C2POL = 0X11A.4
#bit  C2SP  = 0X11A.3
#bit  C2R   = 0X11A.2
#bit  C2CHH  = 0X11A.1
#bit  C2CHL  = 0X11A.0

////////////////////////////////////// DAC
#byte DAC = 0x11E   
#byte DACON0 = 0x11F
#byte ANSEL = 0x9D 
#bit   DAON= DACON0.7
#bit   DAOE= DACON0.6
#bit   DARSH= DACON0.1
#bit   DARSL= DACON0.0

///////////////////////////////////////////////// Prototipe
   short int calibrate_opamp_internal(void) ;
   void setup_comparators (void);
   void setup_psmc(void);
    void setup_dac(void);
   void config_mcu(void);


////////////////////////////////////////////////Interrupt

#int_default
void default_isr(void)
{


   if(C2IE_BIT)     // Is the interrupt enabled ?
        {
            if(C2IF_BIT)  // If so, is the interrupt flag set ?
                 {

               C1ON=0;
               C2ON=0;
               Gate off
               Fan Off   
               SMCON  =0  ;       // PSMC OFF              
                               C2IF_BIT = 0;    // Clear the interrupt flag         
      

               do
                  {   
                     pin_dataout=1;                  
                     delay_ms(100);
                     pin_dataout=0;                  
                     delay_ms(100);
                  }
               while(1); // ERROR SIGNAL



               
                 }
        }

}


#int_RTCC
void RTCC_isr()
{

}


//////////////////////////////////////////
#int_RB
void RB_isr(void)
   {
        int changes;
        int last_b;

             changes = last_b ^ port_b;
             last_b = port_b;

             if (bit_test(changes,5)&& !bit_test (last_b,5))
            {
            
                    }
   }


////////////////////////////////////
void main()
{
              Config_mcu();                        
      Gate      Off
      pin_dataOut   Off
      FAN       Off
      Answer = 0;
      delay_ms(500);


   do
    {
      Camp = calibrate_opamp_internal();           

    }
    while ( !Camp);


      Dac   =51;

        C2IE_BIT =1;    // Interrupt Comparator 2 Enabled                        
         PEIE=1;   

         enable_interrupts(GLOBAL);
      while(1);



}


   void Config_mcu(void)
    {

      TRISA=255;
      TRISB=37;
      WPUB=0;      


        setup_adc_ports( sAN2| sAN3|sAN4| sAN6|VSS_VDD);      
        setup_adc(ADC_CLOCK_DIV_32);

                setup_timer_0(RTCC_INTERNAL|RTCC_DIV_128);          
         setup_timer_1(T1_DISABLED);
       setup_timer_2(T2_DIV_BY_1,2,1);

         disable_interrupts(INT_RB);
         disable_interrupts(INT_RTCC);
         disable_interrupts(GLOBAL);

        C2IE_BIT =0;                                  
         C1IE_BIT =0;                                  
         PEIE=0;   

         setup_dac();                         
         setup_comparators ();
         setup_psmc();


   

     }


   void setup_dac()
   {
   
      DARSL=0;
      DARSH=0;
      DAOE =1;
      DAC =0;
      DAON =1;

   }

   void setup_comparators (void)
   {
   

      C1CHH =1;   // AN6
      C1CHL =0;
      C1R  =0;
      C1POL=0;
      C1SP =1;

      C1OE =1;

      C1ON =1;   

      C2CHH =1;   // AN6
      C2CHL =0;
      C2R  =0;
      C2SP =1;
      C2POL=0;
      C2OE =0;
      C2ON =1;  //
            

   }


   void setup_psmc(void)
    {

      SMCON  =0 ;    
      DCH = 0;          // no  PSM
      DCL = 0;          // no used
               MAXDCH = 0;      //50% D.C.
       MAXDCL = 0;
      MINDCH = 0;      // 0% D.C.
      MINDCL = 0;
      SMCCLH = 0;
      SMCCLL = 0;


      SMCCS  =1 ;       
      PWMPSM =1 ;       //  PWM MODE
      SMCOM  =0 ;       //  SINGLE OUT
      SCEN =0;
      S1APOL =0;      
      S1BPOL =0;
      SMCON  =1 ;    


   }

   boolean calibrate_opamp_internal(void)
   {


      CMPEN =0;               //
      OPAON =1;                  //  OP AMP
      GBWP =0;                  // 70kHz
      CALREF=0;               
      delay_ms(20);
      CAL=1;                  // Start

     while( bit_test(CALCON, 7) );

     if (bit_test(CALCON, 6))             
       return(false);
     else
       return(true);
   
   }



Guard



Joined: 20 Jan 2005
Posts: 43

View user's profile Send private message

PostPosted: Wed Feb 09, 2005 2:29 am     Reply with quote

HI
To fix the problem I used MC2OUT
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