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.

50% From TMR0 Interrupt

Status
Not open for further replies.

Suraj143

Active Member
Hi this coding I have inside the ISR.
For every 10ms it’s giving an TMR0 interrupt. So I count 100 times to get 1 second.
After I checking whether it has reaches 60 seconds to get 1 minute.

What I need is the output must stay ON 50% & other 50% must be OFF.

The coding done for 2 minutes on & 2 minutes off from 4 minutes.

I want to verify is this ok or not.

Code:
ISR	decfsz	COUNT,F
	goto	Output
	movlw	.100
	movwf	COUNT			
	decfsz	Second,F
	goto	Output
	movlw	.60
	movwf	Second			
	decfsz	Minute,F
	goto	Output
	movlw	.4
	movwf	Minute
			
Output	movf	Minute,W
	sublw	.2
	btfsc	STATUS,C
	bsf	PORTB,0		;turn ON 
	btfss	STATUS,C
	bcf	PORTB,0		;turn OFF
 
Last edited:
Hi,
Do you want to toggle RB0 every 2 minutes? Or you need to use the Second and Minute GPRs in the main routine?
Try this:
Code:
ISR	decfsz	COUNT,F
	retfie
	movlw	.100
	movwf	COUNT
	decfsz	Second,F
	retfie
	movlw	.120
	movwf	Second
	comf	PORTB,	w
	andlw	0x01
	iorwf	PORTB,	f
	retfie


*EDIT: This routine will not work, RB0 will always be high. Because it is inclusive OR. When one input is already high, the output is high for sure. Check the latest reply :)
 
Last edited:
Hi bananasiong in my main routine nothing is there.

Yes I want to toggle RB0 every 2 mins. But I haven't use COMF command :confused: Thanks for your very useful codings.

BTW Is my coding ok? Will it effect to the accuracy?
 
Suraj143 said:
Hi this coding I have inside the ISR.
For every 10ms it’s giving an TMR0 interrupt. So I count 100 times to get 1 second.

TMR0 is the worst possible choice, it's only really included to maintain backwards compatibility with ancient PIC's - use TMR2 which is far more useful and easy to use.

If you do use TMR0 I suggest you check the PICList and Application notes, where you can find suggestions on how to work round some of it's limitations. Basically, unlike TMR2, you can't just set it to 10mS and go.
 
Suraj143 said:
Oh LOL my small 8 pin PIC doesn't have TMR2 it has only TMR0 & TMR1 its an 675.:D
The PIC12F683 has TMR2. Great small microcontroller. It can be used as replacement/substitute for the 629/675.
 
Last edited:
Hi Suraj143,
I haven't used comf either :D
It is complement, means toggle all the bits in PORTB. And yes, your code works too, but you can avoid using another GPR.

Timer 1 is really a better solution. 10 ms interrupt can be done without any prescaler since it is 16 bits timer.
 
Oops, just figure out when I woke up :p Sorry for giving wrong info. My previous routine will not work.
These are the changes:
Code:
ISR	decfsz	COUNT,F
	retfie
	movlw	.100
	movwf	COUNT
	decfsz	Second,F
	retfie
	movlw	.120
	movwf	Second
	[b]movf	PORTB,	w
	xorlw	0x01
	xorlw	0x00
	movwf	PORTB,	f[/b]
	retfie
 
COMF Coding help

Hi I applied bananas COMF coding to toggle the output from minute variable. After I replaced the iorwf PORTB, W with movwf PORTB & it worked well. But it didn’t work with that iorwf instruction.

Code:
	comf	PORTB,W
	andlw	0x01
	movwf	PORTB


Now the problem is the PORTB, 0 bit will toggle but its effecting to the other 7 bits from the above coding.

Is there any method or instruction to toggle only the PORTB zero bit but without damaging other bits?
 
Suraj143 said:
Hi mike you mean to add like this after comf command

Code:
	comf	PORTB,W
	movlw	0x01
	xorwf	PORTB,F

No, you just need the two instructions I posted above to toggle bit zero of Port B. You should try and work out why this works and you will get a better understanding.

Mike.
 
Yes, Pommie's is shorter.
XOR 0 with x, you will get back x
XOR 1 with x, you will get x toggled.
Check the truth table of 2 input XOR.

Still wonder why I did XOR for twice ;)
 
Hi guys I replaced mikes codings & it worked perfectly.It didn't come to my mind & I worried about that.:D

Thanks a lot for the support.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top