Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

how to convert desimal in range 0-100 into binary 8 bit.

hi everybody..

i have a questions. i want to design pwm that contollered by labview software..in pwm duty cycle..range of duty is 0-100. how to convert in the 8 bit binary?

example

duty_cycle                  binary

100                          00000000

99                            00000010

...                                .....

0                              11111111

0 Kudos
Message 1 of 11
(9,222 Views)

If your percentage is x, then your 8-bit value would be y = (100-x)/100*256 = (100-x)*2.56.

 

You can convert y into binary easily enough.

 

EDIT:  Nevermind, I just read your example again.

 

With having only 8 bits to play with, your percentage has to be in steps of 12.5.  You could take your number and divide by 12.5.  This would give how many bits are to be high.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 11
(9,217 Views)

thank u

my other problem now is i cann't to read continuosly..

i will send 5x8bit data via serial into microcontrolller. afterwards i want to ceck that data serial in serial read as first data, second..etc, but i have error.   

0 Kudos
Message 3 of 11
(9,194 Views)

Hi kurniawan,

 

What error are you seeing? And could you explain more clearly what you want to do when checking the data? 

David S.
0 Kudos
Message 4 of 11
(9,169 Views)

this programs from labview. i want to read what preveous send into uC. i send ACK and 5byte data in binary format. idealy is..

if i send data (4, 8, 4, 1) in binary format as   (0100, 1000, 0100, 0001) i will recieve back from uC equal with data that i send into uC. 

 

Download All
0 Kudos
Message 5 of 11
(9,161 Views)

You are not sending "ACK" and five bytes.

 

Place a string indicator on the wire going to write buffer on VISA Write. Set it for Hex display. With the slides set to 3,6,4,7,9 the string sent is "ACK111010001111001" in normal display and 4143 4B31 3131 3130 3130 3031 3131 3130 3031 in Hex display.  In other words you are sending 18 bytes represent the ASCII characters in the string.

 

Do you want to send 4143 4B03 6479?  That would be "A","C","K",b0011,b0100,b0110,b0111,b1001; where bxxxx represents a byte expressed in binary.

 

Also, you are not setting the termination character to carriage return. Typecasting return to I32 produces 218103808 (decimal).  I placed a Termination  Character property node after the configure VI to see what it set the termination character to and found zero.  Carraige return is x0D or d13. Wire a constant set to decimal 13 to the termination character on the Config VI.  Note that this does NOT cause it to send a carriage return on Write, only to terminate reads.

 

Lynn

0 Kudos
Message 6 of 11
(9,156 Views)

can u edit my program? i don't undestand about it

0 Kudos
Message 7 of 11
(9,152 Views)

What parts do you not understand?  Exactly what bytes should the program send? Should it send a termination character?

 

I can help but i do not want to spend time on something which is not what you need.

 

Lynn

0 Kudos
Message 8 of 11
(9,147 Views)

Consider this modification to the Slides and Write:

1. Change the representation on the slides to U8. Each should be an integer representing one byte, so let them start out that way.

2. Build an array and then use Byte Array to String.

3. Concatenate the two strings.

 

4. Not shown: If needed, append carriage return before writing.

 

The indicator inside the case structure is to allow checking of the string to be sent. If the Slides are 3,6,4,7,9, then the string is 4143 4B03 0604 0709 in hex display.

 

Lynn

 

String format.png

0 Kudos
Message 9 of 11
(9,141 Views)

hi..

thank u for your solutions....

i have any problem again. after i recieved data1-5 from uC i will send 'S' character in string format then uC will send back to PC data 0xFF and 0x0F, as long as

i send 'S' character i will always recieve that data (0xFF, 0x0F) but in labview i only recieve that data four times.. please u check my program.

thanks

0 Kudos
Message 10 of 11
(9,133 Views)