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

3.219 doesn't recognize INT_COMP2

 
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

3.219 doesn't recognize INT_COMP2
PostPosted: Thu Feb 24, 2005 1:24 pm     Reply with quote

Hi,
V 3.219 doesn't recognize enable_interrupts(INT_COMP2).
I try C2IE bit
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 24, 2005 1:39 pm     Reply with quote

Look at the 16C781.H file. It's not complete. It looks like they
were working on it, but didn't enter the comparator interrupts.
(Actually, I suspect that the .H files are automatically generated
by a program). You should email CCS support about this.
When they fix the comparators in a new version, they will extend
your download rights long enough for you to get the new version.
Code:
// Constants used in ENABLE/DISABLE_INTERRUPTS() are:
#define GLOBAL                    0x0B80
#define INT_RTCC                  0x0B20
#define INT_RB                    0x0B08
#define INT_EXT                   0x0B10
#define INT_AD                    0x0B40
#define INT_TIMER1                0x8C01
#define INT_LOWVOLT               0x8D80
#define INT_TIMER0                0x0B20
#define INT_                      0x0001
#define INT_                      0x0001
Guard



Joined: 20 Jan 2005
Posts: 43

View user's profile Send private message

PostPosted: Thu Feb 24, 2005 1:43 pm     Reply with quote

Can I use COMP2_isr() and C2IE bit ??
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 24, 2005 1:48 pm     Reply with quote

You would have to use #INT_DEFAULT, but you're having difficulty
in writing that code, so I think it's better if you ask CCS to make
the comparator interrupts work on the 16C781. Email them.
Guard



Joined: 20 Jan 2005
Posts: 43

View user's profile Send private message

PostPosted: Thu Feb 24, 2005 2:23 pm     Reply with quote

This is my code for #int default
The PC jump always to interrupt vector !
C2IF is cleared.
I configured all registers for the PSMC , and it works .
C2 and C1 are input for PSMC

Code:



#include <16C781.h>
#use delay(clock=10000000)
#fuses NOWDT,HS, PUT,NOPROTECT,MCLR, BROWNOUT, BORV42,

#define ON            =1;
#define OFF            =0;

static short int Camp;   


/////////////////////////////////////////////////////////////


#byte Port_b = 0x06
#byte  portA=5

#byte TRISB =0x86
#byte TRISA =0x85

#byte OPTION=0x81
#bit    RBPU=OPTION.7

#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


#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
#bit LVDIE=0x8c.7

//////////////////////////////////////// PSMC
// Registro di controllo 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
// Registro di controllo 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
#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


#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
#bit    MC2OUT = 0x11b.6

#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

#bit C2IF=0xc.5


////////////////////////////////////// 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 ?
     {

         DAC=80;  // for debug only
         


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


void main()
{

            Config_mcu();                        //
                

   do
    {
      Camp = calibrate_opamp_internal();           //  opAMP

    }
    while ( !Camp);




         setup_dac();                         
         setup_comparators ();
         setup_psmc();
         delay_ms(100);
   
         Dac   =51;
         PEIE=1;
          C2IE_BIT =1;          
          enable_interrupts(GLOBAL);

do {

   delay_ms(1);

} while (1);



}

   void Config_mcu(void)
    {

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


        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);

        C2IE_BIT =0;                               
         C1IE_BIT =0;                               
         LVDIE=0;
         PEIE=0;   
         disable_interrupts(INT_AD);
         disable_interrupts(INT_RB);
         disable_interrupts(INT_EXT);
         disable_interrupts(INT_RTCC);
         disable_interrupts(GLOBAL);

         


     }


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

   }

   void setup_comparators (void)
   {
   
   // Configura comparator 1      
      C1CHH =1;   // AN6
      C1CHL =0;
      C1R  =0;
      C1POL=0;
      C1SP =1;
      C1OE =1;
      C1ON =1;   


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

   }


   void setup_psmc(void)
    {

      SMCON  =0 ;    
      DCH = 0;          
      DCL = 0;          
               MAXDCH = 0;      
       MAXDCL = 0;
      MINDCH = 0;      
      MINDCL = 0;
      SMCCLH = 0;
      SMCCLL = 0;


      SMCCS  =1 ;       
      PWMPSM =1 ;       
      SMCOM  =0 ;      
      SCEN =0;
      S1APOL =0;      
      S1BPOL =0;
      SMCON  =1 ;    


   }

   boolean calibrate_opamp_internal(void)
   {


      CMPEN =0;               
      OPAON =1;                  
      GBWP =0;                  
      CALREF=0;               
      delay_ms(20);
      CAL=1;                  
      

     while( bit_test(CALCON, 7) );

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

PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 24, 2005 2:45 pm     Reply with quote

Quote:
The PC jump always to interrupt vector !
C2IF is cleared.

If you don't want the PIC to jump to the interrupt vector, then
you need to disable comparator interrupts. For comparator #2,
this is controlled by the C2IE bit. (Not C2IF).

The reason why the comparator #2 interrupt keeps happening
is because the "change" condition has not been cleared. As long
as the "change" condition is set, the PIC will keep setting the C2IF bit,
and if C2IE is also set, then the PIC will jump to your isr.

To clear the "change" condition, you need to read the CM2CON0 register.
You need to add two lines to your default_isr() function, as shown below:
Code:
#int_default
void default_isr(void)
{
char c;             // ADD THIS LINE.

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

       DAC=80;  // for debug only

      c = CM2CON0;   // Clear "change" condition.  ADD THIS LINE.
      C2IF_BIT = 0;    // Clear the interrupt flag
     }
  }
}


Also, in your main() program, you should read CM2CON0 before you
enable comparator #2 interrupts. Example:

Code:
main()
{

c = CM2CON0;   //  Clear "change" condition.  ADD THIS LINE.
C2IE_BIT =1;           
enable_interrupts(GLOBAL);

}
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