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.

Shifting PWM Outputs

Status
Not open for further replies.

Suraj143

Active Member
Hi Guys

I have a code for dim 3 LEDs with 3 different brightness levels.I use timer interrupt to generate a steady PWM frequency.

What I want to do is I need to move these 3 brightness levels on PORTB Like original knight rider effect.

These are the brightness variables

Code:
State1	movlw	.10
	movwf	LED0		;very dim
	movlw	.100
	movwf	LED1		;medium bright
	movlw	.250
	movwf	LED2		;full bright

The above is state1 in state 2 it must come like this

Code:
State2	movlw	.00
	movwf	LED0		;off
	movlw	.10
	movwf	LED1		;very  Dim
	movlw	.100
	movwf	LED2		;medium bright
	movlw	.250
	movwf	LED3		;full bright

No need code just give me an idea.
 
Last edited:
You just need to keep the position of the dullest LED and the direction it is moving.

I.E. if the dullest is currently LED6 and it's going left then you would write the brightnesses as follows,
LED6=10
LED7=100
LED6=250

Mike.
 
Hi mike one thing to note those a LED variables are not PORTB bits.They are brightness variables.
 
Last edited:
In the main menu I'm doing like this
Code:
State1		movf	Temp,W		;b'00000111' --keep posision
		movwf	PORTB
		call	PWM_Speed	;do PWM for a moment
		btfss	STATUS,Z	;//
		goto	State1
		;

State2		rlf	Temp,W		;b'00001110'--keep posision
		movwf	PORTB
		call	PWM_Speed	;do PWM for a moment
		btfss	STATUS,Z
		goto	State2

State3		movf	Temp,W		;b'00011100'--keep posision
		movwf	Temp1
		rlf	Temp1,F
		rlf	Temp1,F
		movwf	PORTB
		call	PWM_Speed	;do PWM for a moment
		btfss	STATUS,Z
		goto	State3

You can see now LEDs brightness levels suddenly decrease from 100 to 10 in the state 2 & decrease brightness level from 250 to 100 in the state 2.Likewise when every state changing there is a big gap.This is a big gap when the circuit is running speed you can see that as a flickering.

This is my only problem.
 
Last edited:
Hi,
I would like to see your PWM_Speed routine. Also, in State3 the second rlf Temp1, F should be rlf Temp1, w.
 
Hi,
I would like to see your PWM_Speed routine.

Hi bananasiong here it is.

Code:
PWM_Speed	movf	PWM_Count,W	;speed of shifting
		xorlw	.10
		btfss	STATUS,Z
		goto	$+4
		clrf	PWM_Count	;reset PWM Count
		bsf	STATUS,Z	;mark Z
		return
		bcf	STATUS,Z	;clear Z
		return
Also, in State3 the second rlf Temp1, F should be rlf Temp1, w.

Oh ya thanks.

When changing the state it must change in a linear way.Thats what I have to do.In the above codees it has a big gap between each state changing.Thats why it looks like flickering.
 
Last edited:
Hi,
What's the interrupt rate?
Here's my idea:
In ISR rotate Shadow register and send to PORTB. You can use another register to determine the number of rotation. So you can have other jobs in the main loop.

The clue: the shifting speed should not be the same as the PWM speed. Shifting speed should be slower. That's why you see it flickering.
 
Hi bananasiong my interrupt rate is 40uS

For 256 steps 256 X 40 = 10240uS = 97.6 Hz

My code uses 3 LED variables.When shifting I can see 3 steps.

That means first I can see full bright,
After shifting one left I can see medium brightness
After again shifting one left I can see dim brightness

So when looking at a single LED you can see its only fading three steps per bulb.That looks like flickering.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top