Skip to content

Home page

Perl Programming

per I recommend to visit the this YouTube channel with 125 videos, and this website Why should we learn Per?

Perl is scripting language. A scripting language or script language is a programming language that supports the writing of scripts, programs written for a software environment that automate the execution of tasks which could alternatively be executed one-by-one by a human operator. Environments that can be automated through scripting include software applications, web pages within a web browser, the shells of operating systems (OS), and several general purpose and domain-specific languages such as those for embedded systems.

Part 1: Hello World!

First two lines of our programs

#!/usr/bin/perl print “Content-type: text/html\n\n”;

The last line of our Perl

exit;

Part 2: Variables

creating a variable x:   $x = 1;

creating list variable x,y,z: ($x,$y,$z)=(1,2,3);

Variables  can be numbers or strings

Part 3: Arrays

Creating an array x: @x = (1,2,3,4,5) @y = (“Ali”, “Alan”, “Sydney”, “Cisco”);

To get an element in an array: @x[index];

Counting elements of an array: $total = $@x +1;

By mentioning a new index we can add new element to our array

Push: Adding an element to the end of an array: push(@array, “Saberi”);

Pop: removing an element from the end of an array: pop(@array);

Shift: removing a element from left hand side: shift(@array);

Unshift: To add an element to the left hand side: unshift(@array, “string”);

Merge: To concatenate to arrays@Cisco = (@Ali, @Alan);

Reverse: @Alireverse =  reverse(@Ali);

Sort: Able to sort Numerically and Alphabetically:@sorted = sort (@numbers);

Array tips:  hundred ones @Ali = (1) x 100; Hundred hello @Ali =(“Hello”) x 100; Quick string arrays: @array = qw(Ali Alan Cisco Sydney);

Part 4) loop statements

Looping arrays: foreach $index (@array){};

Condition: If(condition1){do some thing} elsif(condition2 ){do something} else{} – or in the opposite unless(){}….else{}

While loop: while (condition){do some thing;}

Until loop: it is reverse of while loop:; until the condition happens. until(condition){}

Map function: to manipulate with elements of array for example multiply them by two, or upper case them  @array2 = map { e.g $_=$_*2}(@array)

Grep function: to filter the elements of an array @array2 = grep {S_>5} @array

Part 5) 

Operators and Precedence::

  • + – * / ++ — % 

part 6) Hash-basics

Hash is some thing like array that can hold a lot of data, but the difference is that we can not reference data by index in hash like arrays. To create a hash, we use percentage(%) sign:  Here every lement is asssotaed with a name So. loopoing through a hash is different with looing through an array. Also items are in a different order than we put then un hash. There are three methods on introducing hashes

  • %Hash();  and then in the program $Hash{Name} = John; $Hash{Age} =25 ; $Hash{City} = Montreal;
  • %Hash(){‘Name’ ,’Ali’, ‘Age’,  ’25′,  ’City’, ‘Montreal’};
  • %Hash qw{Name Ali age 25 City Montral};

Access to hash elements: print “$Hash{Age}\n”

Looping hashes:  key, value, each

  • eachwhile (($key,$value)=each(%hash)){do some thing};
  • keys:  foreach $key (keys %Hash){}
  • values:  foreach $value (values %Hash){}

Hash functions

  • exists:  this function checks the existence of a key,value : if exists($Hash{Name})…
  • defined: this function  determines if a key is defined by a value or not if defined ($Hash{City})…
  • delete: this function delete a hash item delete($Hash{City});
  • reverse: this function makes keys and value reversed reverse $Hash;
  • sort: We can sort keys and value ; sort keys %Hash;  or sort values %Hash;
  • merge: %Hash3 =  (%Hash2,%Hash1);

Will be continued….

Specific topics: [1] Metastabiliy or Quasistable

Image

In metastable states, the circuit may be unable to settle into a stable ’0′ or ’1′ logic level within the time required for proper circuit operation. As a result, the circuit can act in unpredictable ways, and may lead to a system failure, sometimes referred to as a “glitch”

Metastable states are inherent features of asynchronous digital systems, and of systems with more than one independent clock domain. In self-timed asynchronous systems, arbiters are designed to allow the system to proceed only after the metastability has resolved, so the metastability is a normal condition, not an error condition. In synchronous systems with asynchronous inputs, synchronizes are designed to make the probability of a synchronization failure acceptably small. Metastable states are avoidable in fully synchronous systems when the input setup and hold time requirements on flip-flops are satisfied.synchronous systems with asynchronous inputs, synchronizers are designed to make the probability of a synchronization failure acceptably small. Metastable states are avoidable in fully synchronous systems when the input setup and hold time requirements on flip-flops are satisfied.

Metastabiliy happens under these situation:

  • When the input signal is an asynchronous signal.
  • When the clock skew/slew is too much (rise and fall time are more than the tolerable values).
  • When interfacing two domains operating at two different frequencies or at the same frequency but with different phase.
  • When the combinational delay is such that flip-flop data input changes in the critical window (setup+hold window)

Arbiter:

An arbiter is a circuit designed to determine which of several signals arrive first. Arbiters are used in asynchronous circuits to order computational activities for shared resources to prevent concurrent incorrect operations. Arbiters are used on the inputs of fully synchronous systems, and also between clock domains, as synchronizers for input signals. Although they can minimize the occurrence of metastability to very low probabilities, all arbiters nevertheless have metastable states, which are unavoidable at the boundaries of regions of the input state space resulting in different outputs

For more information check out this paper

Synthesizer or a synchronization register chain and working in different clock domains:

1234

Synchronous circuit design techniques make digital circuits that are resistant to the failure modes that can be caused by metastability. A clock domain is defined as a group of flip-flops with a common clock. Such architectures can form a circuit guaranteed free of metastability (below a certain maximum clock frequency, above which first metastability, then outright failure occur), assuming a low-skew common clock. However, even then, if the system has a dependence on any continuous inputs then these are likely to be vulnerable to metastable states.

When synchronous design techniques are used, protection against metastable events causing systems failures need only be provided when transferring data between different clock domains or from an unclocked region into the synchronous system. This protection can often take the form of a series of delay flip-flops which delay the data stream long enough for the metastability to have statistically been removed.

One remedy in this case is the use of a two-stage synchronization circuit.The second flip-flop receives the output signal of the first stage one clock period later and can go into a metastable state only if its input conditions are also violated. That is, the output of the first flip-flop is still metastable during its setup and hold time

123

For more details, study this Texas Instrument document, Altera document

Testing of Digital Circuits

os

This topic is also known as timing analysis.

There three type of testing approaches in digital designs:

1-We design, without considering  a part for test inside the design, and after it we apply a test pattern to cover a large portion of the faults

2- Design for testablility. such as BIST (Built-In-Self-Test) normally come up with design i FPGA boards

3- Fault tolerant design: In this type of design, we consider a good margin to tolerate errors

Fault sources:

1- In design process: It can happen in two parts; specifications and implementation

2-Device defects

3-Manufacturing process: It happens in material

Fault types:

1- Dynamic: is more related to timing

2- Static: is more related to wiring faults, two wire close to each other and etc.

Test Models: (very simple fault model: Stuck-at faults)

1 – Stuck-at-0 (s-a-0)

2 – Stuck-at-1 (s-a-1)

Combinational Circuits- Test pattern generation

We have Fault vectors (F), and test vectors (T)

Fault Simulation: Given a test vector, by simulating the circuit with the fault, identify all the faults covered by the test vector, It the output is different this test vector can detect that fault

Test Generation:  Given a fault, identify all the test vectors which can cover that fault.

Limitations:  1-We expect one fault to occur[max] 2- Fault other than Stuck-at-fault are expected to show up as stuck-at-faults at some other location 3- these approaches are valid only for combinational circuits

Typical Circuit Enhancement:

1- Insertion of test points:  We increase  number of outputs

2-Pin amplification: We multiplex the function of the pin

3-Test modes:

4- Scan chains:  We can test all pins from a pin

Will be continued ….

MATLAB for engineers, a quick review:

matlab

You can ignore this post as, I have never asked, or heard from my gangs who got interview at Cisco hardware team, that any questions related to MATLAB were asked there.

I personally had a tutoring sessions with  my students at McGIll, and I decided to review MATLAB here for you, as you are an engineer and having knowledge of MATLAB is a MUST for you.

Desktop calculations:

1-At the end of each command line putting ; will  not echo the input

2- Arithmetic: + – * / \(left and right divisions, note that MATLAB has two operation for division) ^ :

Then 6/3 is 2 and 3\6 is 2, too.

3- Last line editing: by pressing Up/Down buttons; you can recall the last line

4- A few built-in functions: sin(x), cos(x), tan(x), sqrt(x), exp(x), log(x), log10(x), acos(x), asin(x), atan(x), atan2(x,y)

5- Naming constants and variables:   MATLAB is Case-sensitive. Therefore, Pi, Pi, PI; pi are different

7- Format: 5 digits display is default, but 15 digits display can be achieved by command: format long, for scientific nation command is format short e.

8- Cleaning the screen: clc

One-dimensional arrays

1-Define a row and column matrix: space and comma are equal [1 2 3] = [1,2,3]

2-Indexing for a matrix(x,y)

3- Size of a matrix: size(Matrix), Length of vector: length(Matrix)

4- Clearing variables: clear

5- Add/subtract to matrix A+B. A-B, array multiplication A.*B, array division A./B. Array power A.^n

6- Defining equally distance elements, A=[1:1:10];

7-Simple plots: plot(x,y,’color’), grid on/off, xlabel(‘’), ylabel(‘’), figure, hold on/off, hist(Y,X)

Matrices

1- Defining a matrix: A=[1 2 3;4 5 6]

2- Juxtaposition and sub matrix C= [A B], C=[A;B], C=A(:,1), A(:,1), A(1:2,1:2’]

3- Elementary operations with matrices A+B, A-B, A.*B and A*B, A./B

4-ones(m,n), zeros(m,n),

Complex numbers

1-imaginary unit is i or j but j is preferred professionally, since, ‘i’ is as current unit in electrical engineering , note that there is no need to write * before i,j

2- real part: real(Z), imaginary part: imag(Z), magnitude abs(Z), angle by angle(Z)

3- Arrays of complex numbers

System of linear equations: AX=B

1- Determinant: det(A)

2- Crammer’s rule:  X=[det(D1);det(D2);det(D3)]/det(A), D1=A, D1(:,1)=B, D2=A, D2(:,2)=B, …..

3- Matrix inversion inv(A)

4-Solving systems of linear equations in MATLAB

Polynomials

1-Polynomial representation: by its coefficients

2- Getting roots: roots(coeff)

3- Multiplication is achieved by convolving conv(c1,c2)

4-Division is achieved by deconvolving deconv(c1,c2)

Programming in MATLAB

1- Programming a function: function y=Alan(x1, x2)

2- Repetitive control structure- FOR LOOPS:  e.g.

for K=1:1:10

 P(1,k) =sqrt(k);

 End

3- Conditional control structure:

If condition

                Expression

Else if condition

                Expression

                Expression

Else

                Expression

end

4- Repetitive control structure- WHILE LOOP

External files and programs:

1-Saving data: save filename.mat variable / save(filename, variables)

2- Loading data X=load(filename.)

Differential and integral

1- Calculating differential: diff(x)/interval : consider that length of diff(x) is less that length of x

2- Calculating Integral: sum(x)*interval

Best

Ali

post no  12

ps:

I found this video channel for you. unfortunately, it has no voice.

pps:

More tutorials:

Introduction to MATLAB by D.F. Griffiths

Embedded system review

Embedded system is a computer system designed for specific control functions, normally for real-time purposes and it’s part of a complete system with a hardware and mechanical parts. Physically, embedded systems range from portable devices such as digital watches and MP3 players, to large stationary installations like traffic lights, factory controllers. Complexity varies from low, with a single microcontroller chip, to very high with multiple units, peripherals and networks mounted inside a large chassis or enclosure, Prices vary from under dollar to hundred dollars.

The core of an embedded system can be a microcontroller,DSP, CPLD or FPGA . The difference between these cores and CPU is lack of having MMU(memory management unit) and their application in real-time functions.

The best tutorial that, I found on the web on embedded system programming so far is in the following link by Arvind Singh from Bangalore

The following chapters are covered:

  1. Chapter-1: Introduction to Embedded Systems
  2.  Chapter-2: Instruction Sets
  3.  Chapter-3: Keil C Programming Tutorial (Part-1)
  4.  Chapter-4: Keil C Programming Tutorial: Pointers
  5.  Chapter-5: Keil C Programming Tutorial: Functions
  6.  Chapter-6:  Keil C Programming Tutorial: Writing simple C program in Keil
  7.  Chapter-7: Keil C Programming Tutorial: C and Assembly together
  8.  Chapter-8: Keili C Programming Tutorial: Interfacing C programs to assembeler
  9.  Chapter-9: How to use Keil Microvision IDE
  10.  Chapter-10: Interrupts Programming 8051
  11. Chapter-11: Timers in 8051 &Timer Programming
  12.  Chapter-12: USART Programming
  13.  Chapter-13: I2C or TWI(Two Wire Interface)

You can download Keil C from from this site and instantly start programming! ;)

Check out these videos by Dr. Santanu Chaudhury, Department of Electrical Engineering,  if you need to learn more.

SystemVerilog

systemVerilog

I  am uploading a series of videos on my YouTube channel , but it’s matter of  time. Please subscribe. and get the latest updates

Meanwhile, I introduce the following:

Verilog review

verilog2I am uploading a series of videos on my YouTube channel , but it’s matter of  time. Please subscribe. and get the latest updates.

Follow

Get every new post delivered to your Inbox.