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.

10 Bit BCD Brightness Problem Coding help

Status
Not open for further replies.

Suraj143

Active Member
Hi guys I have this 10 bit BCD routine its working well.

The problem is the brightness of 4 digitis is varying. It means from the AD value 256, 512, and 768 the brightness is varying.

Ex: If the AD result is 400 it put 256 to the display & decrementing other remaining 8 bits all the time. When the remaining value gets bigger the brightness falls off.

Does anybody give me a clue to show a fix brightness level?

Code:
		clrf	D1	;One segment digit1
		clrf	D2	;Ten segment digit2
		clrf	D3	;Hundred segment digit3
		clrf	D4	;Thousand segment digit4
			
		btfss	ADH,1
		goto	__256
		btfss	ADH,0
		goto	__512
		movlw	.7	;move 768
		movwf	D3
		movlw	.6
		movwf	D2
		movlw	.8
		movwf	D1
		goto	Trans
			
__512		movlw	.5	;move 512
		movwf	D3
		movlw	.1
		movwf	D2
		movlw	.2
		movwf	D1
		goto	Trans

__256		btfss	ADH,0
		goto	Trans	;move 256		
		movlw	.2
		movwf	D3
		movlw	.5
		movwf	D2
		movlw	.6
		movwf	D1
		goto	Trans

Trans		movf	ADL,W
		xorlw	00h
		btfsc	STATUS,Z
		return
		call	Incr
		decfsz	ADL,F	;decrementing the lower8 bits
		goto	$-2
		return
 
Last edited:
The above method is speed only problem is the brightness is varying.
I tried in many ways to do a smooth display but I couldn't.:(
 
It could be either,

The binary to ascii routine is varying in length and so your SSDs aren't on as long. Solution, drive your displays on interrupt.

You are displaying your working variables D1 to D4 and so some of the time is is displaying the wrong digits. Is zero blank by any chance. Solution, use 2 sets of variables - one for working, one to display.

Mike.
 
You understood very well. Exactly I’m using the same variables used in multiplexing routine.
I’ll use AD_D1, AD_D2, AD_D3, AD_D4 inside the BCD conversion.

And I’ll move them to my D1, D2, D3, D4 segment digits when I’m showing them.

I’ll try this first & see without going to interrupt.
 
If you are not using interrupts then the problem is the first one mentioned.

Another way to solve this would be to only do the conversion now and again. You could run the display loop 50 times and then do the conversion once.

Mike.
 
Pommie said:
Another way to solve this would be to only do the conversion now and again. You could run the display loop 50 times and then do the conversion once.

Wow I'll try this one also & inform you.I'll call multiplex routine 50 times & after I'll call AD conversion.

I must reduce the delay inside the multiplex routine as well.
 
Hi Mike your idea worked very well.I'm really happy.I called the Multiplexing routine 20 times & call AD once.The display brightness is superb.

Here is the coding I made two variables also one for working & other for display.

I want to confirm is this method good for measure analog inputs? ex: voltage,temp etc.....bcuz this is the coding I'm going to use in my future projects.

Code:
;*************
;Varibles used
;*************

;ADH 			= stores first 2 bits of ADRESH
;ADL 			= stores the 8 bits of ADRESL
;AD1,AD2,AD3,AD4 	= working variables inside BCD conversion
;D1,D2,D3,D4 		= show variablesused in display


;*************************
;main program starts here
;*************************

Main			call	Multiplex
			decfsz	Count,F		;show display 20 times 
			goto	$-2
			movlw	.20
			movwf	Count			
			call	AD		;call AD convertion		
			goto	Main


;***********************************
;increment routine updating 4 digits
;***********************************

Incr			incf	AD1,F
			movf	AD1,W
			xorlw	.10
			btfss	STATUS,Z
			return
			clrf	AD1
			incf	AD2,F
			movf	AD2,W
			xorlw	.10
			btfss	STATUS,Z
			return
			clrf	AD2
			incf	AD3,F
			movf	AD3,W
			xorlw	.10
			btfss	STATUS,Z
			return
			clrf	AD3
			incf	AD4,F
			movf	AD4,W
			xorlw	.2
			btfss	STATUS,Z
			return
			clrf	AD4
			return
;**************
;AD conversion
;**************			
			
AD			bsf	ADCON0,GO
			btfsc	ADCON0,GO
			goto	$-1
			movf	ADRESH,W	;get upper 2 bits
			movwf	ADH	
			bsf	STATUS,RP0
			movf	ADRESL,W	;get lower 8 bits
			bcf	STATUS,RP0
			movwf	ADL

;**********************
;10 bit BCD conversion
;**********************
			
BCD			clrf	AD1
			clrf	AD2
			clrf	AD3
			clrf	AD4
			
			btfss	ADH,1
			goto	__256
			btfss	ADH,0
			goto	__512
			movlw	.7
			movwf	AD3
			movlw	.6
			movwf	AD2
			movlw	.8
			movwf	AD1
			goto	Trans
			
__512			movlw	.5
			movwf	AD3
			movlw	.1
			movwf	AD2
			movlw	.2
			movwf	AD1
			goto	Trans

__256			btfss	ADH,0
			goto	Trans			
			movlw	.2
			movwf	AD3
			movlw	.5
			movwf	AD2
			movlw	.6
			movwf	AD1
			goto	Trans

Trans			movf	ADL,W
			xorlw	00h
			btfsc	STATUS,Z
			goto	$+4
			call	Incr
			decfsz	ADL,F
			goto	$-2

;****************************************
;move working variables to show variables 
;****************************************

			movf	AD1,W		
			movwf	D1
			movf	AD2,W
			movwf	D2
			movf	AD3,W
			movwf	D3
			movf	AD4,W
			movwf	D4			
			return
 
Suraj143 said:
I want to confirm is this method good for measure analog inputs? ex: voltage,temp etc.....bcuz this is the coding I'm going to use in my future projects.

Not really, it's one of those occasions where using interrupts is really of great benefit - if you check my seven segment multiplexing tutorial (which is only two digit) - you will see how easy it is to use. It makes the display completely transparent, all you do is stick the values you want in the registers.

Your non-interrupt method means you have to continually consider how long things are taking, and you can't sit in a loop waiting for a button press. It's perfectly valid, but is a LOT harder to work with - and pretty pointless on a PIC with timer interrupts.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top