Frequency response of discrete system

In previous post we discussed about impulse response. Impulse response h(n) is digital system response in time domain. But there is another characterization of discrete system – frequency response H(ejω). Frequency response can be calculated form impulse response by formula: This means frequency response is systems transfer coefficient to every frequency value. Frequency response is a complex function. So this can be evaluated as:

Continue reading

Digital system equation

Back to DSP thread. Lets talk about digital system equation. Every digital system can be described using this equation. The output of digital filter generally consist of previous inputs and previous outputs. y(n-k) is considered as previous outputs; x(n-p) – previous inputs; ak and b­p – coefficients; This equation is convenient to define discrete system and extract various characteristics. Number N defines discrete filter tap (Tap – A FIR “tap” is simply a coefficient/delay pair). Lets say we have digital filter made of one tap. y(n)=a·y(n-1)+b·x(n) First we calculate filter response function – h(n): Response function is calculated from system reaction to discrete impulse ´(n). So assume that x(n)= ´(n) and y(n)=h(n). Initial conditions: y(-1)=h(-1)=0. Then: h(n)=0 when n<0; h(0)=a·h(-1)+b·´(n)=b; h(1)=a·h(0)+b·´(1)=ab; ……. h(n)= ban where n>0 Lets say we have a=0.7; b=1; Then we get discrete system characteristics: This equation in example describes IIR (Infinite Impulse Response) discrete systems, because there is a feedback element a·y(n-1). There is another type of discrete filter – FIR (Finite Impulse Response) Finite response filter equation is much simpler: As you may noticed from equation – IIR filter have infinite number of response impulses while FIR filter have a finite number of impulses. IIR…

Continue reading

AVR microcontroller interrupts using WINAVR

I can’t imagine microcontroller without interrupts. Without interrupts you would have to do loops in order to check if one or another event occurred. Polling has many disadvantages like program have do loops what takes valuable microcontroller resources. These resources may be used for other data processing tasks. This is why microcontroller comes with built in interrupt support. Instead of checking events microcontroller has ability to interrupt normal program flow on event and jump to interrupt service subroutine. During interrupt microcontroller stops the task at current point, saves necessary information to stack and gives resources to interrupt subroutine. When interrupt subroutine finishes, and then normal program flow continues. In assembler your program would start with interrupt table: After table goes the main program (RESET) and other interrupt subroutines where program jumps after interrupt occurs. C Compiler creates this table while compiling, but how about interrupt handling routines. First of all to make compiler understand interrupt macro command include desired library; #include “avr\interrupt.h” All interrupts then can be described using macro command: ISR(), for instance: ISR(ADC_vect) { //Your code here }   This routine is for ADC complete conversion handler. This macro command is convenient for handling all unexpected interrupts. Just…

Continue reading

Unprofessional review of AVR simulators

I would like to go through AVR few Atmel AVR microcontroller software simulators. You can find many AVR simulators out there like simulavr, simulavrxx, avrora VMLAB, Proteus, AVRStudio… some of them are open source or freeware other commercial. I want to go through what I have tried and what I liked best. AVRStudio My list starts with AVR studio. This is not only as simulator, but the whole IDE for writing and debugging AVR applications. AVRStudio includes assembler and simulator. From AVR Studio 4 there is also plugin supported for GCC compiler. If you have WINAVR toolset installed in you computer, AVR studio automatically detects the GCC compiler and you can start developing AVR applications using C language in AVRStudio environment. Also you get ability to simulate C code and view microcontroller peripheral performance. The only external hardware I could spot is AVR LCD Visualizer. If you want to simulate some hardware like 24Cxx memories, UART, buttons. It is pretty hard to simulate them, because the only way to do this is by changing registry values in I/O view. AVRStudio is ideal tool for Assembly program development and debugging. AVRStudio is free to use. Proteus VSM This package (https://www.labcenter.co.uk) takes…

Continue reading

ADC on AVR using on chip comparator

Not all AVR microcontrollers come with built in ADC. But there is a way of building one using on chip comparator and timer counter. The comparator compares voltages on +v (Ain0) and -v (Ain1) inputs. If voltage in Ain0 pin is greater than in Ain1 then comparator ACO is set to ‘1’ otherwise it is ‘0’. Bellow you see AVR comparator circuit. The working of this ADC is as follows. First PB0 is set to ‘0’ in order to discharge capacitor. Then PB0 is programmed as input with no pull-ups and Timer is started to count. The capacitor starts charging to 5V through 10k resistor. When voltage on capacitor becomes greater than in input Vin, the comparator state switches to ‘1’. Program detects this and stops the timer counter and accumulated count is proportional to the input voltage Vin. So if Vin is greater, then timer counts more, and if Vin is less then timer counts less. Just one thing! The voltage on capacitor rises not linearly but exponentially. But if we restrict the input to the range of like 2.5V then this voltage raise can be considered as linear. In a example RC time constant is 1ms and capacitor…

Continue reading