01-26-2013 05:58 PM
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
01-26-2013 08:09 PM - edited 01-26-2013 08:13 PM
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.
01-29-2013 03:50 AM
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.
01-30-2013 01:23 PM
Hi kurniawan,
What error are you seeing? And could you explain more clearly what you want to do when checking the data?
01-31-2013 08:07 AM
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.
01-31-2013 09:20 AM
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
01-31-2013 09:42 AM
can u edit my program? i don't undestand about it
01-31-2013 11:25 AM
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
01-31-2013 11:54 AM
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
01-31-2013 10:30 PM
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