The post Arduino Tutorials: Beginners and Advance appeared first on BINARYUPDATES.
]]>1. How to Setup and Program Arduino
2. LED and Switches of Arduino Uno
3. Serial Communication in Arduino Uno
3. Timer Interrupt in Arduino Uno
5. brightness control of LED
6. Making sound tone using Arduino
7. Control Dimming of LED in Arduino
8. Interface 16×2 Character LCD with Arduino Uno
— 4-bit Mode
— 8-bit Mode
— Scrolling text
— Graphics on LCD Screen
9. Interface Servo Motor with Arduino Uno
10. I2C EEPROM with Arduino Uno
11. RTC DS1800 with Arduino Uno
12. ADC Analog to Digital Conversion using Arduino Uno (POT)
13. Interface LM35 with Arduino uno
14. Relay with Arduino Uno
1. Current Sensor ACS712 with Arduino Uno
2. DHT11 with Arduino Uno
3. LDR Photodiode with Arduino Uno
4. BMP180 with Arduino uno
5. IR Proximity Sensor with Arduino Uno
We believe learning microcontroller with Arduino is the best way to invest your time. On a personal note, I must say it’s never been easier without Arduino to learn programming microcontroller. I remember those old days when we used to buy expensive programmers and kits to learn microcontroller. Even with those expensive tools it’s challenging for non-technical candidates to learn microcontroller programming. But Arduino makes it so simple and easy for anybody to program their microcontroller and build some cool products. I hope you will enjoy reading these Arduino tutorials. If you have any suggestions or feedback feel free to leave a comment. Thanks.
The post Arduino Tutorials: Beginners and Advance appeared first on BINARYUPDATES.
]]>The post Bitwise Operations in Embedded Programming appeared first on BINARYUPDATES.
]]>Now let’s concentrate only on bitwise operations. We’ll learn how these bitwise operations allow’s us for Setting, Inverting, Toggling, Clearing, Extracting and Inserting bits in embedded programming. Here is a table which summarizes operations with 2-operands.
A | B | A | B | A & B | A ^ B |
0 | 0 | 0 | 0 | 0 |
1 | 0 | 1 | 0 | 1 |
0 | 1 | 1 | 0 | 1 |
1 | 1 | 1 | 1 | 0 |
Let’s take variable A and B. We’ll perform bitwise operation on these two variables. This example will help you understand their operation. Let’s first declare these two variables:
uint8_t A = 0x3B //00111011; uint8_t B = 0x96 //10010110; |
AND compares each bit and returns 1 if the two bits are 1 (TRUE) otherwise 0 (FALSE). So: C = A & B;
00111011………………..(A=0x3B) | |
& | 10010110………………..(B=0x96) |
00010010 |
The value of C will be 0x12 or in binary 00010010. That is where there is a 1 in each bit for both values.
OR (| in C)
OR will return a 1 if there is a 1 in either value at that bit. So: C = A | B;
00111011………………..(A=0x3B) | |
| | 10010110………………..(B=0x96) |
10111111 |
The value of C will be 0xBF or in binary 10111111
XOR will return a 1 if there is a 1 at that bit for either value but not both. For example, if bit position 5 for both values has a 1 then XOr returns a 0. But if only one has a 1 and the other has a 0 XOR returns a 1. So: C = A^B;
00111011………………..(A=0x3B) | |
^ | 10010110………………..(B=0x96) |
10101101 |
The value of C will be 0xAD or in binary 10101101.
This returns the compliment of a value. This mean where there was a 0 there will now be a 1 and vice versa. So: C = ~(A);
! | 00111011………………..(A=0x3B) |
11000100………………..(C=0xC4) |
The value of C will be 0xC4 or in binary 11000100
And then there are two shift operators – Left shift and Right shift. These operators shift the bits by the corresponding value, in other word’s move the bits. The sign << for left shift and >> for right shift. Here is an example:
C = A << 2; // left shift A by 2 |
The value of C becomes 0xEC or in binary 11101100 after shifting 2-bits to the left.
D = B >> 4; // right shift B by 4 |
The value of D becomes 0x03 or in binary 00001001 after shifting 4-bits to right.
Let’s say we have variable called bits and we have asked to set the bit-7. This can be achieved by writing this single line of code.
bits = bits | (1 << 7) ; /* sets bit 7 */This would usually be written more succinctly as:
bits |= (1 << 7) ; /* sets bit 7 */Inverting (toggling) is accomplished with bitwise-XOR. In following, example we’ll toggle bit-6.
bits ^= (1 << 6) ; /* toggle bit 6 */
Form a mask with 1 in the bit position of interest, in this case bit-6. Then bitwise AND the mask with the operand. The result is non-zero if and only if the bit of interest was 1:
if ((bits & 64) != 0) /* check to see if bit 6 is set */Same as:
if (bits & 0x64) /* check to see if bit 6 is set */Same as:
if (bits & (1 << 6)) /* check to see if bit 6 is set */
Let’s say if we want to clear bit-7. This can be accomplished using bitwise-AND operator
Mask must be as wide as the operand! if bits is a 32-bit data type, the assignment must be 32-bit:
bits &= ~(1L << 7) ; /* clears bit 7 */
Let’s say we have given a 32-bit number and we asked to extract bits from it. Assume that 32-bit number in hex is 0xD7448EAB. In binary= 1101 0111 0100 0100 1000 1110 1010 1011. Now we have asked to extract 16-bits from bit number 10 through 25.
To extract the bits first we have to use bitwise operator in combination with a bit mask to extract bits 10 through 25. The masking value will be 0x3FFFC00. Now we have two ways we can achieve result.
Method-I
unsigned int number = 0xD7448EAB; unsigned int value = (number & 0x3FFFC00) >> 10;
Method-II
unsigned int number = 0xD7448EAB; unsigned int value = (number >> 10) & 0xFFFF;
Now if we follow Method-I and after equating. We’ve got 0x3448C00 (In binary 11010001001000110000000000). When we shift 10 bits to right, we’ll get 0xD123 i.e. in binary 1101000100100011.
Monitoring specific bit in register is very important. In Embedded programming, very often we need to read status of flag bit in hardware register. These flag bit controls or indicate hardware feature. Also they are every useful while reading, writing data to and from microchip. So we continuously monitor these bits in register to carry out desired function by microchip. Let’s say if we want to monitor 4^{th} bit for any change, we’ll write function as below:
while( bits & (1<<4) ) // monitor for 4th bit changing from 0 to 1 { ....... ....... }
The 4^{th} bit of register bits is ‘1’ the result of (bits & (1<<4)) will always be zero. When 4^{th} bit is ‘1’ then (bits & (1<<4)) will be equal to (1<<4) which is greater than 0 and so this evaluates as TRUE condition and code inside while loop get executed.
Now let’s say if we want to monitor 4^{th} bit state from 1 to 0. In this case, we only need to negate the condition inside of while statement.
while( ~(bits & (1<<4)) ) // monitor for 4th bit changing from 1 to 0 { ....... ....... }
Bitwise operators save memory and it is fast. This all leads to improve performance. I hope now you know that why bitwise operations in embedded programming used such a widely. If you have any questions or suggestions then feel free to leave a comment.
The post Bitwise Operations in Embedded Programming appeared first on BINARYUPDATES.
]]>The post Signed and Unsigned Numbers in Computer Programming appeared first on BINARYUPDATES.
]]>In Number System we’ve assumed, we have as many bits as needed to represent numbers. But in computers, we have a fix number of bits to represent value. These bit sizes are typically 8-bit, 16-bit, 32-bit, 64-bit. These sizes are usually multiple of 8, because system memories are organized on an 8-bit byte basis. When a specific number of bits being used to represent a number. This number determines the range of possible values that can be represented. For example, there are 256 possible combinations of 8-bits, therefore an 8-bit number can represent 256 distinct numeric values and the range is typically considered to be 0-255 (we have provided table in later part of this tutorial). So we can’t represent numbers larger than 255 using 8-bit number. Similarly, 16 bits allows a range of 0-65535.
Until now we have only considered positive values for binary numbers. When a fixed binary number is used to hold positive values, it is considered as unsigned. In this case, the range of positive values that can be represented is from 0 – 2^{n}-1, where n is the number of bits being used. It is also possible to represent signed (negative as well as positive) numbers in binary. In this case, some part of the total range of values is used to represent positive values, and the remaining of the range is used to represent negative values.
There are several ways we can represent signed numbers in binary, but the most common representation used is called two’s complement method. The term two’s complement is somewhat ambiguous, in that it is used in two different ways. First, as a representation, two’s complement is a way of interpreting and assigning meaning to a bit pattern contained in a fixed precision binary quantity. Second, the term two’s complement is also used to refer to an operation that can be performed on the bits of a binary quantity. As an operation, the two’s complement of a number is formed by inverting all of the bits and adding 1 to it. In a binary number being interpreted using the two’s complement representation, the high order bit of the number indicates the sign. If the sign bit is 0, the number is positive, and if the sign bit is 1, the number is negative. For positive numbers, the rest of the bits hold the true magnitude of the number. For negative numbers, the lower order bits hold the magnitude of the number. It is important to note that two’s complement representation can only be applied to fixed precision quantities, that is, quantities where there are a set number of bits.
The 2’s complement method of representation is used because it reduces the complexity of the hardware in the ALU (arithmetic-logic unit) of a computer’s CPU. Using a 2’s complement method, all of the arithmetic operations can be performed by the same hardware whether the numbers are considered to be unsigned or signed. The bit operations performed are identical; the difference comes from the interpretation of the bits. The interpretation of the value will be different depending on whether the value is considered to be unsigned or signed.
The table below shows counting sequence for an 8-bit binary number using 2’s complement:
In above table, we’re counting up from 0. When 127 reached, the next binary pattern in the sequence corresponds to -128. The values from the largest positive number to the largest negative number, but that the sequence is as expected after that. Say for example, adding 1 to –128 gives –127. When the count has progressed to FFh (or the largest unsigned magnitude possible) the count wraps around to 0. Say for example adding 1 to –1 gives 0. This is it for Signed and Unsigned Numbers in computer programming. If you have any question, then feel free to leave a comment.
The post Signed and Unsigned Numbers in Computer Programming appeared first on BINARYUPDATES.
]]>The post Number System in Embedded Programming appeared first on BINARYUPDATES.
]]>Decimal numbering system uses digits from 0 to 9 i.e. (0, 1, 2, 3, 4, 5, 6, 7, 8, and 9). The base of decimal number system is 10 because we use 10 digits to represent decimal number. When we write decimal numbers, we use a positional notation system. Each digit is multiplied by an appropriate power of 10 depending on its position in the number. Let’s take example: 5319
5319 | = 5 x 10^{3} + 3 x 10^{2} + 1 x 10^{1} + 9 x 10^{0} |
= 5 x 1000 + 3 x 100 + 1 x 10 + 9 x 1 | |
= 5000 + 300 + 10 + 9 |
For whole number, the rightmost digit is 1^{st} position (10^{0} = 1). The numeral in that position indicates how many ones are present in the number. The next position to the left is ten’s, then hundred’s, thousand’s, and goes on. Each digit position has a weight that is ten times the weight of the position to its right.
In the decimal number system, there are ten possible values that can appear in each digit position, and so there are ten numerals required to represent the quantity in each digit position. The decimal numerals are the familiar zero through nine (0, 1, 2, 3, 4, 5, 6, 7, 8 and 9).
Binary Numbers uses only 0 and 1 digit. The base of binary number system is 2. The binary number system is also a positional notation numbering system. Each digit position in a binary number represents a power of two. So, when we write a binary number, each binary digit is multiplied by an appropriate power of 2 based on the position in the number. Example: Find decimal equivalent of binary number 10101
10101 | = 1 x 2^{4} + 0 x 2^{3} + 1 x 2^{2} + 0 x 2^{1} + 1 x 2^{0} |
= 1 x 16 + 0 x 8 + 1 x 4 + 0 x 2 + 1 x 1 | |
= 16 + 4 + 1 |
The decimal equivalent of 10101 is 21. Each digit in binary number carries specific multiplication factor. By default the bit on extreme right which is also called as LSB bit or 0^{th} bit and that on the extreme left is MSB or last bit. SO technically in computing first bit will be 0^{th} index and hence the right will have an order of 2^{0}, next bit will have an order of 2^{1} and 2^{2}, 2^{3} and so on. And when we start conversion we have to consider from LSB i.e. from RIGHT we multiply each bit with increasing power of 2 so Bit 0 will be multiplied with 2^{0}, Bit 1 will be multiplied with 2^{1} and so on.
Hexadecimal Number System uses 16 digits from 0 to 9 and A to F. The alphabets A to F represent decimal numbers from 10 to 15. The base of Hexadecimal uNmber system is 16. There are sixteen numerals required. Here are the hexadecimal numerals: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
The reason for the common use of hexadecimal numbers is the relationship between the numbers 2 and 16. Sixteen is a power of 2 (16 = 2^{4}). Because of this relationship, four digits in a binary number can be represented with a single hexadecimal digit. This makes conversion between binary and hexadecimal numbers very easy, and hexadecimal can be used to write large binary numbers with much fewer digits. When working with large digital systems, such as computers, it is common to find binary numbers with 8, 16 and even 32 digits. Writing a 16 or 32 bit binary number would be quite tedious and error prone. By using hexadecimal, the numbers can be written with fewer digits and much less likelihood of error. This makes programmer life easy while writing programs.
Example: Find Hexadecimal equivalent of 10110, where 10110 is binary number.
To convert any binary number into its equivalent hexadecimal number, we first need to group the bits each group will have 4-bits. In our example we have 5 binary digits, so we will group them into 0001–0110. After grouping bits directly replace group with its equivalent hexadecimal number. Make sure we always start grouping from RIGHT i.e. LSB bit to LEFT i.e. MSB bit. Hence the hex equivalent of 10110 is 16 or (0x16).
Equivalent Numbers in Decimal, Binary, Hexadecimal Notations,
Decimal | Binary | Hexadecimal |
0 | 00000000 | 00 |
1 | 00000001 | 01 |
2 | 00000010 | 02 |
3 | 00000011 | 03 |
4 | 00000100 | 04 |
5 | 00000101 | 05 |
6 | 00000110 | 06 |
7 | 00000111 | 07 |
8 | 00001000 | 08 |
9 | 00001001 | 09 |
10 | 00001010 | 0A |
11 | 00001011 | 0B |
12 | 00001100 | 0C |
13 | 00001101 | 0D |
14 | 00001110 | 0E |
15 | 00001111 | 0F |
16 | 00010000 | 10 |
17 | 00010001 | 11 |
31 | 00011111 | 1F |
32 | 00100000 | 20 |
63 | 00111111 | 3F |
64 | 01000000 | 40 |
65 | 01000001 | 41 |
127 | 01111111 | 7F |
128 | 10000000 | 80 |
129 | 10000001 | 81 |
255 | 11111111 | FF |
256 | 0000000100000000 | 0100 |
32767 | 0111111111111111 | 7FFF |
32768 | 1000000000000000 | 8000 |
65535 | 1111111111111111 | FFFF |
BCD is Binary Coded Decimal. In BCD system, numbers are represented in decimal form. However, each decimal digit is encoded using a 4-bit binary number. Here is an example. The decimal number 568 would be represented in BCD as follows:
568 | = 0101 0110 1000 |
= 5 6 8 |
Conversion of numbers between decimal and BCD is quite simple. To convert from decimal to BCD, simply write down the 4-bit binary pattern for each decimal digit. To convert from BCD to decimal, divide the number into groups of 4 bits and write down the corresponding decimal digit for each 4-bit group.
There are a couple of variations on the BCD representation, namely packed and unpacked. An unpacked BCD number has only a single decimal digit stored in each data byte. In this case, the decimal digit will be in the low four bits and the upper 4-bits of the byte will be 0. In the packed BCD representation, two decimal digits are placed in each byte. Generally, the high order bits of the data byte contain the more significant decimal digit.
BCD numbers is not as common as binary number system because it is not space efficient. In packed BCD format, only 10 of the 16 possible bit patterns in each 4-bit unit are used. In unpacked BCD, only 10 of the 256 possible bit patterns in each byte are used. A 16-bit quantity can represent the range 0-65535 in binary, 0-9999 in packed BCD and only 0-99 in unpacked BCD.
This is it for Number system in Embedded Programming. Now we hope you’ve understood the concept of Binary, BCD and Hexadecimal Number Systems with its inter-conversion. Please do write us if you have any suggestion/comments or come across any error on this page.
The post Number System in Embedded Programming appeared first on BINARYUPDATES.
]]>The post High Power Programmable DC Power Supplies appeared first on BINARYUPDATES.
]]>B&K Precision announced three new models of high power programmable DC power supplies, the PVS10005, PVS60085, and PVS60085MR. The new PVS Series delivers output power up to 5.1 kW with excellent regulation, low noise, and fast transient response times. All models provide a unique built-in solar array simulator (SAS) function to generate photovoltaic I-V curves. Offering high power density in a compact 2U form factor, these DC power supplies are especially suitable for high voltage testing up to 1000 V, motor inverter testing, and solar array testing applications.
To maximize solar power efficiency, a solar inverter’s MPPT algorithm must be tested under various irradiance conditions. With the optional SAS software application, PVS Series users can easily simulate solar arrays under different weather conditions during a day to validate the effectiveness of the solar inverter. The SAS software allows for a variety of I-V curve input parameters (Voc/Isc/Vmp/Imp/FF/FFv/FFi) along with user-definable irradiance profiles and a custom 1024-point voltage and current table. This software can also monitor and log real-time voltage, current, power, MPPT efficiency, and average MPPT efficiency.
Users looking to replace multiple supplies on a bench or rack can benefit from model PVS60085MR, which offers multi-ranging operation up to 3 kW. This model shares the same voltage and current ranges of the PVS60085 (600 V, 8.5 A) and automatically recalculates voltage and current limits. Furthermore, users can select model PVS10005 for high voltage testing up to 1000 V at 5 A. Unlike other high power supplies that require a 3-phase AC line input, these power supplies only need a single-phase mains connection.
Front panel features for the PVS Series include a bright VFD display, protection LED indicators, and numerical keypad with rotary control knob and cursors for setting output levels quickly. Each model provides internal memory storage to save and recall up to 100 instrument settings.
For programming, the power supplies provide a list mode function, an external analog programming and monitoring interface, and standard USB, RS-232, GPIB, and LAN interfaces supporting SCPI commands. Remote control software is also available for front panel emulation, generation and execution of test sequences, and logging measurements via a PC. Users can integrate this application software with NI’s Data Dashboard app to create custom dashboards on smartphones and tablets for additional monitoring functions.
PVS Series models include comprehensive protection features: overvoltage (OVP), overcurrent (OCP), overpower (OPP), and overtemperature (OTP) protection, along with constant voltage-to-constant current (CV-to-CC) and constant current-to-constant voltage (CC-to-CV) foldback protection modes. All models are backed by a 3-year warranty.
Article Source: B&K Precision
The post High Power Programmable DC Power Supplies appeared first on BINARYUPDATES.
]]>