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.

Stupid code problem

Status
Not open for further replies.
That's excatly the problem. Like Pommie said, you must turn segments off before switching digits.

Imagine it, old segment info is active, you switch digit, the second digit gets this old data, then you change segment data and only now second digit gets this new data.

Oh you're right! I had switched the order of when the segments are turned on, but that doesn't even matter, because the old data is still in the register. I do have to turn off the segment completely.

Thanks guys!
 
Unfortunately I'm back.

Segments are being turned off before the transistors are switched, yet the ghosting is still appearing.

I tried coding it two different ways:

Code:
	btfss	flag, 0	;check which LED was last
		goto	Do_tens
		movlw	b'00000000'	;	Turn off the previous segment, keep from ghosting
		movwf	SEG_PORT
		movlw	b'00000001'
		movwf	GRD_PORT
		movf	ones,w
		;andlw	0x0F		;make sure in range of table
		call	LED_Table
		movwf	SEG_PORT
		bcf		flag,0
		goto	INTX

Do_tens		
		movlw	b'00000000'	;	Turn off the previous segment, keep from ghosting
		movwf	SEG_PORT
		movlw	b'00000010'
		movwf	GRD_PORT
		movf	tens,w
		andlw	0x0F		;make sure in range of table
		call	LED_Table
		movwf	SEG_PORT
		bsf		flag,0

and

Code:
	clrf	SEG_PORT	

		btfss	flag, 0	;check which LED was last
		goto	Do_tens
		movlw	b'00000001'
		movwf	GRD_PORT
		movf	ones,w
		;andlw	0x0F		;make sure in range of table
		call	LED_Table
		movwf	SEG_PORT
		bcf		flag,0
		goto	INTX

Do_tens		
		movlw	b'00000010'
		movwf	GRD_PORT
		movf	tens,w
		andlw	0x0F		;make sure in range of table
		call	LED_Table
		movwf	SEG_PORT
		bsf		flag,0

neither of which solves the ghosting problem
 
The only thing I can think is that you have some stray capacitance somewhere.

What happens if you switch it around like this,
Code:
		clrf	SEG_PORT
		clrf	GRD_PORT	;turn off both transistors
		btfss	flag,0		;check which LED was last
		goto	Do_tens
		movf	ones,w
		andlw	0x0F		;make sure in range of table 
		call	LED_Table
		movwf	SEG_PORT
		bcf	flag,0
		movlw	b'00000001'
		movwf	GRD_PORT	;moved
		goto	INTX

Do_tens
		movf	tens,w
		andlw	0x0F		;make sure in range of table
		call	LED_Table
		movwf	SEG_PORT
		bsf	flag,0
		movlw	b'00000010'
		movwf	GRD_PORT	;moved

Also, how often is your interrupt triggered?

Mike.
 
Should be ever 16ms, but I didn't design the interrupt myself.

The above code does not solve the problem.

I've noticed before that when only one segment is being grounded by the MCU through the transistors, it lights up brightly, but the other one also lights up dimmly.

I actually just wrote a piece into my Initialize segment, before the timers are setup or anything, just to diagnose the problem and noticed something strange:
Code:
		movlw	.3
		movwf	ones
		call	LED_Table
		movwf	SEG_PORT
		movlw	b'00000001'
		movfw	GRD_PORT
		call	Delay255
		call	Delay255
		call	Delay255
		call	Delay255
		movlw	b'00000010'
		movfw	GRD_PORT
		call	Delay255
		call	Delay255
		call	Delay255
		call	Delay255

		clrf	GRD_PORT
		clrf	SEG_PORT

I was expecting one ti light up then the other, while the other one is lit dimly, but when I apply power, only one lights up, the other dimly, nothing changes for 2 seconds, and the program continues. Strange?

So I am pretty sure it's not a coding problem, at least not in that loop.
 
It looks like the transistors are not being fully turned off. Can you try adding a 10K resistor from the base of the transistors to ground.

<edit> I'm assuming you have the 4K base resistors, if not, that could be your problem.</edit>

Mike.
 
Last edited:
I don't actually have a 10K resistor laying around. I tied a 33K, but it seems a bit much, and won't pull it down, so I went all the way down to a 500, and that works perfectly.

Great to know. How come the pins don't pull the transistors down themselves?

EDIT: Not using any resistors between the base and pins right now actually.
 
Last edited:
EDIT: Not using any resistors between the base and pins right now actually.

That is your problem then. Low on a pic pin is around 0.6V and this will partly switch on the transistors if no base resistor is present. You can use the 500Ω resistors as base resistors.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top