Friday, October 28, 2016

Ring Counter

A ring counter is circuit made up of N flip flops as shown in the figure below. It is used to generate N unique states from the N flip flops in a simple way. We can generate N unique states from counters too, but that would need more complex circuit than a simple ring counter.

As shown in the figure above the output of the last flip flop becomes the input to the serial input of the first flip flop. As shown in the truth table below, when we start the sequence from 1000 as the output of the flip flops, each clock pulse causes the 1 bit to shift to the next flip flop. Thus in any state the output of only one flip flop is going to be high, thus uniquely identifying the sate as highlighted in the truth table.

An N state ring counter will need N flip flops.

The video below shows the operation of a ring counter .

Jhonson Counter

A jhonson counter is a digital circuit made of flip flops as show in the figure below. It is also called a twisted ring counter as in a jhonson counter the negation of the last flip flops is connected as the serial input to the first flip flop.

A johson counter is designed with N flip flops and will hae 2N unique states. The Q' output of the last flip flop i fed as input to the first flip flop. Thus if we start with all the flip flops in the clear state, then at the first clock pulse the negation of "0" that is "1" is fed as input to the first flip flop. Thus output of first flipflop becomes 1, this operation continues for N clock pulses, making all the outputs as 1. Then again the process is repeated for N clock pulses for it to reach the initial state again as depicted in the truth table below. The highlighted cells in each row indicate the unique combination to recognize that state.
A jhonson counter can generate 2N unique states for N flip flops which is double the number generated by a ring counter.

The videos below shows the working of a jhonson counter.

The circuit and simulation was created using the software "DEEDS"

Sunday, October 9, 2016

Simulink:Creating different waveforms

In simulink, if we need to generate different waveforms,like sawtooth,square,sine etc we can make use of the signal generator block. The signal generator block is available under main simulink blocks and looks as shown below.

height="" />

To choose the type of waveform to be generated double click on the block to open the menu as shown

In the menu we can choose the

After choosing the waveform and entering the other details of the waveform, click on OK. The ffiure below shows a sawtooth waveform of 1Hz frequency and amplitude of 1.

Saturday, September 17, 2016

Matlab: Concatenating string and integer

Here is how we can concatenate an integer to a string in matlab.

Let us say we have a string "test" and we want to generate the string test1,test2,test3 so on. We can do it by using the function strcat, which concatenates two strings passed as input to it. But as the numbers 1,2,3 etc are numbers we need to convert them to strings using the function int2str.

int2str takes an integer number as returns it by converting it into a string.

y will be equal to test1 as we converted 1 to string and concatenated it with the sting 'test'.

Example program 1


Example program 2


Wednesday, September 14, 2016

Matlab: Finding the number in an array nearest to a given number

We can use the following method in matlab to find a value in an array which is nearest to a given number.

Let us say we have an array "temp" with the following numbers

Now if we want to find the number closest to 32 in the array we can do the following.

Subtract the given number from all the number in the array

find the absolute value of the difference by using absolute

Now find the minimum number in the diff array by using the function min

The variable difference will have the minimum difference and index will point to the index of the number.

temp(index) will give us the actual number closest to the given variable.

Follow by Email