View previous topic :: View next topic |
Author |
Message |
Markdem
Joined: 24 Jun 2005 Posts: 206
|
PIC16F1709 and Comparator |
Posted: Sat Mar 18, 2017 7:59 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Mar 18, 2017 10:14 pm |
|
|
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 |
|
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19381
|
|
Posted: Sun Mar 19, 2017 3:57 am |
|
|
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!.... |
|
![](templates/subSilver/images/spacer.gif) |
Markdem
Joined: 24 Jun 2005 Posts: 206
|
|
Posted: Sun Mar 19, 2017 4:13 am |
|
|
Thanks guys, that's what I thought. Just wanted to make sure.
Thanks |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9177 Location: Greensville,Ontario
|
|
Posted: Sun Mar 19, 2017 5:10 am |
|
|
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'. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Mar 19, 2017 8:56 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19381
|
|
Posted: Sun Mar 19, 2017 1:22 pm |
|
|
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... |
|
![](templates/subSilver/images/spacer.gif) |
|