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.

timer driven interupt

Status
Not open for further replies.

yfx4

Member
Can someone please give me an example of the code and mental logic behind a timer-driven interrupt?? I am building a plug-in replacement for my load-based flasher on my motorcycle so I can use LEDs without load resistors.

I understand what PWM is but the concept behind the interrupt and how it will work with turn and brake lamp functions eludes me.
 
Last edited:
<deleted message>

I jumped in too soon and then realized I have no idea what a "load based flasher" is...
 
Last edited:
Assuming you are using the 4 meg internal oscillator, I would use timer2 setup with prescaler 4, postscaler 10 and PR2=249 you do this by doint,
Code:
	movlw	0b01001101
	movwf	T2CON
	movlw	.249
	bsf	STATUS,RP0
	movwf	PR2
	bsf	PIE1,TMR2IE
	bcf	STATUS,RP0
	movlw	0xc0
	movwf	INTCON
This will then rollover every 10mS (100Hz) and generate an interrupt.

A typical interrupt would be,
Code:
interrupt	movwf	int_work
		swapf	STATUS,W
		movwf	int_status
		bcf	STATUS,RP0
		bcf	STATUS,RP1

		bcf	PIR1,TMR2IF

		swapf	int_status,W
		movwf	STATUS
		swapf	int_work,F;	swap to file
		swapf	int_work,W;	swap to work
		retfie

In this interrupt you would use a counter and if you needed 0.5 seconds between events you would count to (or from) 50.

Mike.
 
<deleted message>

I jumped in too soon and then realized I have no idea what a "load based flasher" is...

A turn signal flasher that the rate of flash is dependent on a certain load. In cars the flash rate typically increases when a bulb burns out b/c the load goes down. If you replace the bulbs with LEDs you get the same effect--usually referrred to a hyperflashing. I want to replace my stock unit with a flasher that has a set rate so that the turn signals flash at a given rate (about 1 hz) independent of the load. On my bike the unit also allows the front lamps to function as running lights but when the TS is on the running light power to the TS lamp is cut for On-Off flashing, not On-Dim. I want the same function on the rear for increased visibility. I also plan to have the PWM from the running light part of the unit go to the brake/tail lamp so they are all the same brightness.

I have breadboarded a circuit and code for the turn function, I don't know how to make it so the non-signaling lamps stay at the same 'running light' level while having the right flash rate on the turn side AND being sure that the brake function is displayed on all the back-end lights ecxept for the turn signal lamp (when engaged). It was suggested that a timer-based interrupt would work.

I looked all over (apparently in the wrong places) for info on this but can't find anything that applies to what I'm trying to do. Or perhaps the info DID apply and I just know too little to see how. I made a 'truth table' for the lamps and inputs but don't have it here at work with me.
 
Assuming you are using the 4 meg internal oscillator, I would use timer2 setup with prescaler 4, postscaler 10 and PR2=249 you do this by doint,
Code:
	movlw	0b01001101
	movwf	T2CON
	movlw	.249
	bsf	STATUS,RP0
	movwf	PR2
	bsf	PIE1,TMR2IE
	bcf	STATUS,RP0
	movlw	0xc0
	movwf	INTCON
This will then rollover every 10mS (100Hz) and generate an interrupt.

A typical interrupt would be,
Code:
interrupt	movwf	int_work
		swapf	STATUS,W
		movwf	int_status
		bcf	STATUS,RP0
		bcf	STATUS,RP1

		bcf	PIR1,TMR2IF

		swapf	int_status,W
		movwf	STATUS
		swapf	int_work,F;	swap to file
		swapf	int_work,W;	swap to work
		retfie

In this interrupt you would use a counter and if you needed 0.5 seconds between events you would count to (or from) 50.

Mike.

Thank you. I will print this out and digest it with my foreign language dictionary.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top