Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Comparator on PIC16F628A

Status
Not open for further replies.

speedEC

Full Member level 6
Joined
Apr 1, 2011
Messages
337
Helped
23
Reputation
46
Reaction score
21
Trophy points
1,298
Activity points
4,324
Dear All,

I need some help on solving comparator issue on PIC16F628A. I have used Hi-Tech C compiler. I have not enabled GIE and since I have not used interrupt isr. This is the code that works fine.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
main(){
  . // setting interrupts
  .
  .
  .
  while{
      if (RBIF){
      .
      .
      .
      }
      if (INTF){
      .
      .
      .
 
      }
      BATT_LOW_LED = !BATT_STATUS_HIGH; // If C2OUT Low then Lit LED
            
      CMCON; // read CMCON 
      CMIF = 0; // clear Comparator Flag
      CMIE = 1; // Enable Comparator Interrupt
      delay_ms(1000);
    
    SLEEP();
  }
}



But, The following code not works. I don't know why?

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
main(){
  . // setting interrupts
  .
  .
  .
  while{
      if (RBIF){
      .
      .
      .
      }
      if (INTF){
      .
      .
      .
 
      }
     
      if (CMIF != 0){
          BATT_LOW_LED = !BATT_STATUS_HIGH; // If C2OUT Low then Lit LED
            
          CMCON; // read CMCON 
          CMIF = 0; // clear Comparator Flag
          CMIE = 1; // Enable Comparator Interrupt
          delay_ms(1000);
      }
    SLEEP();
  }
}



Thanks
 

Is your compiler optimizing the "CMCCON;" statement away? Create a dummy variable and assign CMCON to it to be sure.
 

Hi upand_at_them,

Thank you for response. I have tried as you suggested but till not works.
 

I have introduced ISR and enable GIE. Now everything works fine. thanks
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top