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

PIC16F628A comparator annoyance

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



Joined: 02 Jul 2007
Posts: 3
Location: New Zealand

View user's profile Send private message

PIC16F628A comparator annoyance
PostPosted: Mon Jul 02, 2007 9:43 pm     Reply with quote

My program includes the command "setup_comparator(A0_VR_A1_VR)". When I look at the .lst file it has been translated into...
MOVLW 02
BSF 03.5
MOVWF 30
MOVF 05,W
IORLW 03
MOVWF 05
MOVLW 03
MOVWF 77
01A:DECFSZ 77,F
GOTO 01A
BCF 03.5
MOVF 63,W
BCF 0C.6

I would have thought that this command would have set CMCON (at 1F) to 2, ie enabling the comparators for operation with vref. Instead, the comparators are not enabled and the circuit does not function. I have to manually set CMCON for the comparators to work. Why does the compiler work like this? What am I missing here??
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 02, 2007 10:25 pm     Reply with quote

On a question like this, you need to post your compiler version.
Marko



Joined: 02 Jul 2007
Posts: 3
Location: New Zealand

View user's profile Send private message

PostPosted: Mon Jul 02, 2007 10:50 pm     Reply with quote

Version 4.027
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 02, 2007 11:45 pm     Reply with quote

Your version is buggy. It's using the wrong address for CMCON.
This is what is it looks like in 3.249. This is correct code:
Code:

.................... void main() 
.................... { 
0004:  CLRF   04
0005:  MOVLW  1F
0006:  ANDWF  03,F
0007:  MOVLW  07
0008:  MOVWF  1F    // CMCON = 0x07

.................... setup_comparator(A0_VR_A1_VR);
0009:  MOVLW  02
000A:  MOVWF  1F     // CMCON = 0x02
000B:  BSF    03.5   // Bank 1
000C:  MOVF   05,W
000D:  IORLW  03     // Set Pins A0 and A1 = inputs
000E:  MOVWF  05
000F:  MOVLW  03     // Delay 10 us
0010:  MOVWF  77
0011:  DECFSZ 77,F
0012:  GOTO   011
0013:  BCF    03.5   // Bank 0
0014:  MOVF   1F,W   // Read CMCON
0015:  BCF    0C.6   // Clear CMIF bit in PIR1
....................


Here's the code with vs. 4.042. It's also correct. They added one
thing -- they're clearing the IRP bit in the start-up code.
Code:

.................... void main() 
.................... { 
0004:  CLRF   04
0005:  BCF    03.7
0006:  MOVLW  1F
0007:  ANDWF  03,F
0008:  MOVLW  07
0009:  MOVWF  1F
.................... setup_comparator(A0_VR_A1_VR);
000A:  MOVLW  02
000B:  MOVWF  1F
000C:  BSF    03.5
000D:  MOVF   05,W
000E:  IORLW  03
000F:  MOVWF  05
0010:  MOVLW  03
0011:  MOVWF  77
0012:  DECFSZ 77,F
0013:  GOTO   012
0014:  BCF    03.5
0015:  MOVF   1F,W
0016:  BCF    0C.6


So, it's clear that in going to vs. 4, the code generator or the Device Data
got broken for the setup_comparator() function for the 16F628A.
Sometime after vs. 4.027, they fixed it. You can contact CCS support
and ask them (politely) what they will do about it. Maybe they will
upgrade you to a working version. You'll have to ask them.
Marko



Joined: 02 Jul 2007
Posts: 3
Location: New Zealand

View user's profile Send private message

PostPosted: Tue Jul 03, 2007 1:29 am     Reply with quote

I had spent umpteen hours trying to find the problem in hardware, thinking that there could never be a compiler issue. I'm too used to programming in other environments where compiler issues are as rare as hen's teeth. Hopefully CCS will listen to my plea/whining for an upgrade.

Thanks for that PCM-P. You seem to be a hard working person, answering everyone's questions! Have a pat on the back from me.
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