Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 12th May 2008, 01:16 PM   (permalink)
New Member
Ramos is on a distinguished road
Default No success with PIC16F628 comparators

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.
Attached Files
File Type: asm CompTest2.asm (2.8 KB, 11 views)
File Type: asm CompTest21.asm (2.7 KB, 3 views)
Ramos is offline   Reply With Quote
Old 12th May 2008, 02:19 PM   (permalink)
Experienced Member
Pommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to behold
Default

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
		goto	Start
		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
			 

Start		
					;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.
Pommie is offline   Reply With Quote
Old 12th May 2008, 04:21 PM   (permalink)
New Member
Ramos is on a distinguished road
Default

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.
Ramos is offline   Reply With Quote
Old 12th May 2008, 04:37 PM   (permalink)
Super Moderator
 
Nigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to behold
Default

Quote:
Originally Posted by Ramos
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.
Well you can't remove it, it MUST be there.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline   Reply With Quote
Old 12th May 2008, 05:39 PM   (permalink)
New Member
Ramos is on a distinguished road
Default



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 by Ramos; 12th May 2008 at 05:43 PM.
Ramos is offline   Reply With Quote
Old 12th May 2008, 06:08 PM   (permalink)
Experienced Member
 
mike50 has a spectacular aura about
Default

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
mike50 is offline   Reply With Quote
Old 12th May 2008, 08:04 PM   (permalink)
Super Moderator
 
Nigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to behold
Default

Quote:
Originally Posted by Ramos


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.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
Question: Difference between comparators and op amps? speakerguy79 General Electronics Chat 12 2nd January 2008 07:35 AM
eeprom internal pic16f628 neelam29 Micro Controllers 5 17th February 2006 08:58 AM
PIC16F628 to PIC16F84 kasamiko Micro Controllers 2 5th May 2005 04:26 PM
Pic16F628 using too much power while asleep Exo Micro Controllers 1 22nd April 2004 06:17 PM



All times are GMT. The time now is 12:09 AM.


Electronic Circuits  |  Radio Controlled
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.