applied electronics engineering

#### Learning electronics design

A place where you can find free electronics design tutorials, tips and tricks

#### Search -

for analog, digital circuit tutorials, Microcontroller, C programming, antenna tutorials, FPGA chip programming with VHDL/Verilog, free ebooks, software and much more...

## How to write data to Microcontroller port? Video tutorial

This is part of the video tutorial series- writing byte of data to microcontroller port, a subsection of the main tutorial Microcontroller programming in C.

The objective of this video is to teach how to write byte of data to a microcontroller port with typical example usage. The first part of this section of the tutorial showed you how to send or write specific 8 bit of data to the port. Here we show other examples of usage of sending byte of data to a port. For example sending ASCII character, sending numbers, sending and toggling port bits and inserting time delay.

Notes for this video:

To send ASCII character to the microcontroller port, we store the characters that we want to send in an array. Then using a for loop we send each of them one by one to the port. Similarly for numbers we do the same.

A delay in microcontroller programming in C can be implemented in two ways. The first method is to use simple loop directly in the line of code where we want the program to halt for a while. The second method is to create a delay function and use it in the main program.

## Sending specific bits to microcontroller port in C video tutorial

In the following video, we show how to write C program to send specific bits or specific byte to a microcontroller port. In the earlier video tutorial it was shown how to send single bit to a single port pin. Here we are concerned with sending one byte of data to an entire port pin. Thus here we learn how to control an entire microcontroller port.

This is part of the video tutorial series on Microcontroller programming in C. The rest of the video can be found in the Microcontroller programming in C tutorial page.

Understanding the fundamental of writing bit and byte to a microcontroller in C language is crucial in understanding how to write any kind of C program for a microcontroller. Later chapters depends on this.

Here we have used Keil C51 compiler. The syntax for reading and writing and accessing port and port pin varies slightly with vendor compiler. Knowing how to do these things with Keil c51 will help you in write C program for any other vendor microcontroller. It is easy to start learning microcontroller programming in C with Keil C51 and 8051 microcontroller. Once you have good foundation here you can write C program easily for other microcontrollers.

For the C codes and other tutorials see C programming for microcontroller page.

## How to write demultiplexer VHDL code?

In this vhdl tutorial we show you four ways of writing VHDL code for demultiplexer. Two are concurrent and two are sequential vhdl coding method. There are is also a fifth one called structural code which is not described here. The structural code is obtained by solving the truth equation to obtain Boolean equation and then implementing the equation using the logical operators in VHDL.

The first method is to use the when else statement. This is concurrent vhdl construct. If din, sel, dout1 and dout2 are the data input, selector input and the two output for a one to two demultiplexer then we can implement the demultiplexer using the when else statement as follows,

architecture model1 of demux is

begin
dout1 <= din when sel = '1' else '0';
dout2 <= din when sel = '0' else '0';
end model1;

The second way is to use another concurrent vhdl construct called the select statement. For this the vhdl code is below,

architecture model2 of demux is
signal z : std_logic_vector(1 downto 0);
begin
with sel select
z <= din&'0' when '1',
'0'&din when others;

dout1 <= z(1);
dout2 <= z(0);
end model2;

The third way is to use the IF statement. This is sequential vhdl statement. For this the vhdl code is below,

architecture model3 of demux is
begin
process(sel)
begin
if sel='1' then
dout1 <= din;
else
dout2 <= din;
end if;
end process;
end model3;

The last fourth one is to use CASE statement. This is another sequential vhdl statement. The vhdl code for this is,

architecture model4 of demux is
begin
process(sel)
begin
case sel is
when '1' => dout1 <= din;
when others => dout2 <= din;
end case;
end process;
end model4;

Now below is the complete VHDL code tested in Xilinx.

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity demux is
Port ( din : in  STD_LOGIC;
sel : in  STD_LOGIC;
dout1 : out  STD_LOGIC;
dout2 : out  STD_LOGIC);
end demux;

-- when else
architecture model1 of demux is

begin
dout1 <= din when sel = '1' else '0';
dout2 <= din when sel = '0' else '0';
end model1;

-- with select when
architecture model2 of demux is
signal z : std_logic_vector(1 downto 0);
begin
with sel select
z <= din&'0' when '1',
'0'&din when others;

dout1 <= z(1);
dout2 <= z(0);
end model2;

-- if statement

architecture model3 of demux is
begin
process(sel)
begin
if sel='1' then
dout1 <= din;
else
dout2 <= din;
end if;
end process;
end model3;

-- case statement

architecture model4 of demux is
begin
process(sel)
begin
case sel is
when '1' => dout1 <= din;
when others => dout2 <= din;
end case;
end process;
end model4;



Now see the following video that shows you how to write these codes in Xilinx VHDL software.

## video on designing multiplexer in VHDL

In the following video, we illustrate 5 different ways in which you can use to model a multiplexer in VHDL language. The first method is structural coding method and the rest is behavioral. Within behavioral modeling we can use either concurrent statements or sequential statements. The second and third method is concurrent statement method in implementing multiplexer and the fifth and sixth are sequential method.

As shown by simulation in Xilinx VHDL software, they are equivalent. The VHDL codes can be obtained from the blog post- different methods of modeling multiplexer in VHDL. For rest of the tutorials see FPGA tutorial page.

## C programming for microcontroller video to turn on and off LED

The following video illustrate how to write C program for 8051 based microcontrollers to turn on a LED, turn ON and OFF the led using tilde operator and time delay. The time delay is created using simple for loop. It is explained the different method of creating delay using inline for loop and a delay function.

For more tutorials see Microcontroller programming in C webpage.

## AM wave generation using 741 op amp

Amplitude modulation can be achieved by varying the amplitude of the carrier signal by the modulating signal. Operational amplifier such as 741 op amp can be used to design AM modulator and generate AM wave. The basic principle of operation is to make the op amp gain variable by using a JFET at the input of the modulating signal. However, such AM circuit designed with op-amp is not of high quality.

The circuit diagram of AM modulator using op amp is shown below.

The above circuit consist of two parts. One part of the circuit uses op amp 741 to generate a sine wave at 1KHz. The other part is the modulator with modulating signal fed via a JFET into the inverting terminal of the second 741 op-amp. The carrier signal signal generated by the Wien Bridge oscillator enters into the non-inverting terminal. Potentiometer is used in both circuit to adjust gain for the amplifier.

So this is a simple circuit to generate AM wave. Only two op-amps, capacitors and resistors are required for this circuit realization.