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

Understanding Timing diagrams of digital systems

Timing diagrams are the main key in understanding digital systems. Timing diagrams explain digital circuitry functioning during time flow. Timing diagrams help to understand how digital circuits or sub circuits should work or fit in to larger circuit system. So learning how to read Timing diagrams may increase your work with digital systems and integrate them. Bellow is a list o most commonly used timing diagram fragments: Low level to supply voltage: Transition to low or high level: Bus signals – parallel signals transitioning from one level to other: High Impedance state: Bus signal with floating impedance: Conditional change of on signal depending on another signal transition: Transition on a signal causes state changes in a BUS: More than one transition causes changes in a BUS: Sequential transition – one signal transition causes another signal transition and second signal transition causes third signal transition. As you see timing diagrams together with digital circuit can completely describe the circuits working. To understand the timing diagrams, you should follow all symbols and transitions in timing diagrams. You can find plenty of symbols in timing diagrams. It depends actually on designer or circuit manufacturer. But once you understand the whole picture, you can…

Continue reading

Control motor PWM schematic

In general there are two ways to control DC motor speed: by varying supply voltage and pulse width modulation (PWM). First control method is not convenient especially in digital systems. It requires analog circuitry and so on. Second motor speed control method is very convenient for digital systems, because all control is made using only digital signals. As you already know PWM (Pulse Width Modulation) is all about switching speed and pulse width (duty cycle). Duty cycle is ratio of signal time ON/T. T is period of signal. In above diagram you see two signals. First duty cycle is about t1/T=1/3 and another’s duty cycle would be about t2/T=2/3. And notice the period of signals are the same. If we apply these signals to switching transistor we would get control over effective voltage across motor: Vefective=(tON/T)*Vcc; Where tON-signal on time over one period T. In this way you can control motor speed using microcontrollers PWM output or if you need you may use simple control motor PWM schematic constructed using IC555 timer circuit: Without going too deep in to 555 timer’s performance analysis I can mention that duty cycle can be changed using potentiometer RV1. The period of signal won’t…

Continue reading