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

PIC16F1709 and Comparator

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



Joined: 24 Jun 2005
Posts: 206

View user's profile Send private message Send e-mail

PIC16F1709 and Comparator
PostPosted: Sat Mar 18, 2017 7:59 pm     Reply with quote

Hi everyone,

I am really starting to dislike this PIC.
I am trying to get Comparator2 working with the +input been on C0 and -input connected to C1. Should be easy.

This is what I have.
Code:

//CCS = 5.025
#include <16f1709.h>

#fuses INTRC_IO, PLLEN, NOFCMEN, NOIESO, NOWDT, NODEBUG, NOMCLR, PUT
#use delay(clock=32M)

#byte CM2CON1 = getenv("SFR:CM2CON1")
#byte CM2CON0 = getenv("SFR:CM2CON0") 

void main()
{
    CM2CON1=0x00;
    CM2CON0=0x84;

    //setup_comparator(CP2_C1_C0);

    while(1)
    {
        delay_us(1);
    }
}


Currently testing with a pickit3-
If I use setup_comparator(CP2_C1_C0); C2OUT will never change.
If I configure the comparator manually like above, C2OUT will behave normally.

So it looks like my hardware is OK, but setup_comparator is not setting up the comparator.
If I look at the .lst file, I can't see where CM2CON0 is been configured by setup_comparator, but this could be just me not understanding the ASM.
This is what I get;
Code:

....................     setup_comparator(CP2_C1_C0);
000F:  MOVLB  00
0010:  CLRF   1F
0011:  MOVLW  1A
0012:  MOVWF  77
0013:  DECFSZ 77,F
0014:  GOTO   013
0015:  NOP
0016:  MOVF   1F,W
0017:  BCF    12.5


Can anyone see anything I am doing wrong (it is a single line so I cant see how) or give it a quick test with a newer version of CCS?
I keep saying I need to upgrade and I think this will be the last straw.

Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Mar 18, 2017 10:14 pm     Reply with quote

Here is the .LST file for vs. 5.068:
Code:
.......     setup_comparator(CP2_C1_C0); 
0012:  CLRF   12
0013:  CLRF   11
0014:  MOVLW  01
0015:  MOVWF  14
0016:  MOVLW  80
0017:  MOVWF  13
0018:  MOVLB  01
0019:  MOVF   0E,W
001A:  IORLW  03
001B:  MOVWF  0E

Here is the same .LST file in Symbolic mode:
Code:

0012:  CLRF   CM1CON1
0013:  CLRF   CM1CON0
0014:  MOVLW  01
0015:  MOVWF  CM2CON1
0016:  MOVLW  80
0017:  MOVWF  CM2CON0
0018:  MOVLB  01
0019:  MOVF   TRISC,W
001A:  IORLW  03
001B:  MOVWF  TRISC

Here is the #define from the 16F1709.h file. You can see that it just
stuffs bytes from the #define into the CMxCONx registers. (Plus, it
sets the TRIS to inputs).
Code:
#define CP2_C1_C0       0x80010000
Ttelmah



Joined: 11 Mar 2010
Posts: 19545

View user's profile Send private message

PostPosted: Sun Mar 19, 2017 3:57 am     Reply with quote

It's a fault with his compiler version.

Current compiler:
Code:

....................     setup_comparator(CP2_C1_C0);
000F:  CLRF   CM1CON1
0010:  CLRF   CM1CON0
0011:  MOVLW  01
0012:  MOVWF  CM2CON1
0013:  MOVLW  80
0014:  MOVWF  CM2CON0
0015:  MOVLB  01
0016:  MOVF   TRISC,W
0017:  IORLW  03
0018:  MOVWF  TRISC


5.025:
Code:

....................     setup_comparator(CP2_C1_C0);
000C:  CLRF   01F
000D:  MOVLW  1A
000E:  MOVWF  @77
000F:  DECFSZ @77,F
0010:  GOTO   00F
0011:  NOP
0012:  MOVF   01F,W
0013:  BCF    PIR2.C1IF


Duh!....
Markdem



Joined: 24 Jun 2005
Posts: 206

View user's profile Send private message Send e-mail

PostPosted: Sun Mar 19, 2017 4:13 am     Reply with quote

Thanks guys, that's what I thought. Just wanted to make sure.

Thanks
temtronic



Joined: 01 Jul 2010
Posts: 9245
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Mar 19, 2017 5:10 am     Reply with quote

re:
I am really starting to dislike this PIC.

What you have to understand is that CCS has a HUGE number of PICs that their compilers support and those PICs have a dozens and dozens of registers, bits and fuses that all need to be accounted for, they don't always get it 'right' the first time. Especially when Microchip 'flips a bit' level or takes 3 months to send out an 'errata'. We see this most often with the 'latest and greatest' PIC to be brought out.
It's always best to stick with an older PIC unless you MUST use a new peripheral or feature.
The great news is that WHEN CCS knows about a 'bug' ,they do fix it.OK, NOT overnight, but they do. Nothing in life is perfect but CCS does support their products unlike others...

In your case you figured out the compiler did have a bug, as you could recode to prove it did work. As Mt T points out the updated compiler works fine, so CCS knew and eliminated the 'bug'.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 19, 2017 8:56 am     Reply with quote

Quote:
It's always best to stick with an older PIC unless you MUST use a new peripheral or feature

temtronic, he is using a 3-year old compiler version. That's the problem,
not the PIC.
Ttelmah



Joined: 11 Mar 2010
Posts: 19545

View user's profile Send private message

PostPosted: Sun Mar 19, 2017 1:22 pm     Reply with quote

and the chip itself was quite new at the date of his compiler (support was added about 5.20 for this chip). Particularly at this time (V5 was still rather young), it often took a few versions for the support for new chips to work...
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