Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
04/18/05 16:28
Read: times


 
#91847 - 16bit by 8bit divide
Dear all members,
In my design I need to generate 3 phase sine wave with variable frequency and amplitude. The desired frequency and amplitude are entered from keypad then display on LCD. For this reason, it requires some calculation related to 16/8 bit divide. After along hours of banging my head, I came up with this routine, but it seems slow on my simulator (Ceibo Debuger). If any one have better idea, please colaborate. Any inputs, suggestions, advises are welcomed and greatly appreciated.
Here is the code:

TEST:		MOV B,#08H		; Load counter 8dec 
		MOV A,DEN		; Load Acc with Divisor (Denominator)
		CLR C			; Clear Carry
		SUBB A,NUM_H		; If NUM_H greater than DEN,
		JC EXIT			; Exit, result won't fit in 8bit reg
		CLR C			; Clear Carry

DIVIDE:		MOV A,NUM_L		; Load Acc with NUM_L
		RLC A			; x 2
		MOV NUM_L,A		; Save new value back NUM_L
		MOV A,NUM_H		; Load Acc with NUM_H
		RLC A			; x 2
		MOV NUM_H,A		; Save new value back NUM_H
		JC SUBTRACT		; Jump Carry
		MOV A,DEN		; Load Acc with DEN
		SUBB A,NUM_H		; Compare if DEN > NUM_H
		JNC NEXT		; NUM_H < than DEN 
		CLR C			; Clear Carry
 		
SUBTRACT:	MOV A,NUM_H		; Load Acc with NUM_H
		SUBB A,DEN		; Subtract DEN from NUM_H
		MOV NUM_H,A		; Save NUM_H back
		SETB C			; Set Carry (Divide one time)

NEXT:		DJNZ B,DIVIDE		; Decrease pointer 		
		MOV A,NUM_L		; Load Acc with NUM_L (quotient with C)
		RLC A			; Shift out Carry
		MOV Q,A			; Get the quotient

EXIT:           RET                     ;

Please test it and let me know. Since my calculation sometimes not a round number, therefore the accuracy is a little bit off.
For instance: (60 x 66)/ 70 = 56.57 but it display in 38H because this isn't floating point MCU

Regards,
T.L

List of 20 messages in thread
TopicAuthorDate
16bit by 8bit divide            01/01/70 00:00      
   Check This!            01/01/70 00:00      
      And This:            01/01/70 00:00      
   16bit by 8bit divide            01/01/70 00:00      
      Re:            01/01/70 00:00      
         16bit by 8bit divide            01/01/70 00:00      
            To Thelam:            01/01/70 00:00      
   well, if you look a bit to the left            01/01/70 00:00      
   16bit by 8bit divide            01/01/70 00:00      
   Its just ben done            01/01/70 00:00      
   Non-iterative Division            01/01/70 00:00      
   Accuracy            01/01/70 00:00      
   No wonder            01/01/70 00:00      
   again and again            01/01/70 00:00      
   Efficient Division            01/01/70 00:00      
   the divide may ne the tip of the iceberg            01/01/70 00:00      
      16bit by 8bit divide            01/01/70 00:00      
         the Titanic hit the iceberg            01/01/70 00:00      
            16bit by 8bit divide            01/01/70 00:00      
   Don't know if it helps.            01/01/70 00:00      

Back to Subject List