Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

No success with PIC16F628 comparators

Status
Not open for further replies.

Ramos

New Member
I'm trying to set and use the comparators in the PIC16F628.
I have been reading the PIC16F628 data sheet for quit a while, and I followed almost exactly all their guidelines but the code doesn't work. Things aren't as straightforward as one expects. I have the feeling one has to figure out and find implicit information though barely implied!

Unfortunatelly Nigel Goodwin's tutorials all turn off the comparators.

Is anybody experienced with them who can help me get them to function?

Here are two versions of the code, both paralysed! Please have a look at them and try to help me generously. I'd appreciate that.
 

Attachments

  • CompTest2.asm
    2.8 KB · Views: 160
  • CompTest21.asm
    2.7 KB · Views: 127
I just opened the first attachment and can't see how your code gets executed, you have org 0 and then nothing. At reset your code is going to execute your ISR and then return to some unidentified location.

Try adding,
Code:
		ORG	0x00
		[COLOR="blue"]goto	Start[/COLOR]
		ORG	0x04


		movwf	W_COPY        	;save W register
		swapf	STATUS, W         
		movwf	S_COPY    	;save STATUS register 
		MOVLW	b'11111111'
		MOVWF	PORTB
		CALL	Delay
		CLRF	PORTB
		CALL	Delay              						 
		SWAPF	S_COPY, W        
		MOVWF	STATUS    	; STATUS BACK 
		SWAPF	W_COPY, F     	;  
		SWAPF	W_COPY, W   	; W BACK
		RETFIE
			 

[COLOR="Blue"]Start[/COLOR]		
					;comparator initialisation 
		CLRF	FLAG_REG  	;initialise flag register
		CLRF	PORTA   	;initialise portA
		MOVF	CMCON,W   	;load comparator bits

See what difference that makes and post the results.

Mike.
 
Thanks for the suggestions.

I have tried this before and I removed the goto start on purpose because I get some flickering leds on portb.
 
:)

Hello Mr. Goodwin,

Firstly I do appreciate your work and the tutorials.

Secondly and as for my post, do you mean everything is OK?

Is it working? Because I push the buttons on RA0 and RA1 (from high to low CompTest2) I get no response on portb.
 
Last edited:
Ramos,

What do you expect to happen after you set TRISB? You just fall into your delay subroutine, which eventually does a return. There was never any call.

Mike
 
Ramos said:
:)

Hello Mr. Goodwin,

Firstly I do appreciate your work and the tutorials.

Secondly and as for my post, do you mean everything is OK?

Is it working? Because I push the buttons on RA0 and RA1 (from high to low CompTest2) I get no response on portb.

Sorrty, but I've not had time to study your code, but it's essential that you jump over your ISR, otherwise disaster is certain.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top