32Bit Binary2DecimalBCD with (n) Digits Conversion

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
Huib Koppers
Posts: 63
Joined: Fri Oct 12, 2007 5:13 pm
Location: Netherlands
Been thanked: 1 time

32Bit Binary2DecimalBCD with (n) Digits Conversion

Post by Huib Koppers »

Hello,

FlowCode makes binary to BCD conversions for Byte (0...255) and Integers (-32768....+32767).

Is there a way that FlowCode can make a 32bit to decimal-BCD conversion with (n) digits wih a maximum for n=10 ?

Is this possible to do that by a macro in flowcode with asm ?

I need it for my DDS (DirectDigitalSynthesizer) with AD9910 driven by SPI for AVR or ARM controller.

Kind Regards

Huib

Huib Koppers
Posts: 63
Joined: Fri Oct 12, 2007 5:13 pm
Location: Netherlands
Been thanked: 1 time

Re: 32Bit Binary2DecimalBCD with (n) Digits Conversion

Post by Huib Koppers »

Hello,

Maybe i must formulate my question about 32bit binary to BCD conversion in another way.

What are the posibillities within FlowCode to put 32bit (4Byte) binary words converted into decimal digits on LCD ?
(where the number of digits depends on the weight of de binary word with a maximum of 10 digits, 2^32 = 4.294.967.296 )

And is this also possible within Flowcode to do it in a reverse way example; 10 digit BCD to 32Bit Binary ?

Please let my know what is possible in FlowCode for ARM and AVR.

Kind Regards

Huib

User avatar
Steve
Matrix Staff
Posts: 3433
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times

Re: 32Bit Binary2DecimalBCD with (n) Digits Conversion

Post by Steve »

It is possible, but you will need to use C (because Flowcode does not currently support 32-bit integer types) and so you will not be able to simulate it.

To do it, you will need to integer-divide the 32-bit number by 1.000.000.000 to get the first digit. Then "remove" this digit from the real number. Then find the second digit, etc.

Here's a quick example for converting a 3-digit number (562) to BCD:
  • 562 / 100 = 5 (so the first digit is 5)
  • 562 - (5 * 100) = 62
  • 62 / 10 = 6 (so 2nd digit is 6)
  • 62 - (6 * 10) = 2
  • 2 / 1 = 2 (so 3rd digit is 2)

Huib Koppers
Posts: 63
Joined: Fri Oct 12, 2007 5:13 pm
Location: Netherlands
Been thanked: 1 time

Re: 32Bit Binary2DecimalBCD with (n) Digits Conversion

Post by Huib Koppers »

Steve,

Thanks for the answer on my question.

But I am afraid that it's a way wich need to much clock cycle's of the calculation work on the 4byte tuning word to do it in a fast way.

Let me explain; By your example it is possible but only if the result can calculated in non-realtime way

But I will use it for calculate the tuning word in realtime for my DDS circuit, each time the Increment or decrement action (by Rotary_Encoder interrupt) a register value wil be incremented/decremented with a binary frequency step wich wil change the 4byte tuning word in realtime and send by SPI to the DDS and directly after the DDS update de 32bit binary to BCD conversion on the tuning word must take place and then update the LCD display.

I have seen some examples for the AVR in asm, but not yet for the ARM.

If there is no other solution, can the asm example 32bit2BCD conversion for AVR imported into my flowcode program ?
And how can i do this ?

Kind Regards

Huib

User avatar
Steve
Matrix Staff
Posts: 3433
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times

Re: 32Bit Binary2DecimalBCD with (n) Digits Conversion

Post by Steve »

The asm code for the AVR will probably need to be changed to get it to compile correctly on the ARM, but it should be possible.

I did a quick search on the web and came across this page:
http://www.sxlist.com/techref/microchip ... ath-ph.htm

The "GETTING IT IN AND OUT" section has some code for an optimised binary->bcd routine in assembly. This may help you.

Huib Koppers
Posts: 63
Joined: Fri Oct 12, 2007 5:13 pm
Location: Netherlands
Been thanked: 1 time

Re: 32Bit Binary2DecimalBCD with (n) Digits Conversion

Post by Huib Koppers »

Steve,

Thanks, but is it also possible to import asm examples into FlowCode ?

kind regards

User avatar
Steve
Matrix Staff
Posts: 3433
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times

Re: 32Bit Binary2DecimalBCD with (n) Digits Conversion

Post by Steve »

Yes - you can embed C and ASM code into the C icons (and implement functions, etc, in the "supplementary code" window).

Post Reply