timer1.zip
VMLAB
is a software simulation of micro (AVR and ST62) for Windows, totally free, it relies on WinAVR (free development environment for AVR on Windows).
Its peculiarity is to have a scope, through which you can make measurements of time on the waveforms generated from micro.
VMLAB installs and runs well under Linux (thanks to Wine).
VMLAB installs and runs well under Linux (thanks to Wine). WinAVR On Linux as there is no need to compile it manually, so the link. of the various files. After a quick look on Google, I have proceeded in this way:
2.
then download and copy in your home dir. the new model for the
ATmega168B already modified for Linux (edited by ThVortex then unzip the folder VMLAB installation. For bash shell: cd
useravr ~ $ unzip-o-0.6.zip-d ~ / .wine / drive_c / VMLAB
NB Without the amendment of section 2, the simulation of Timer1 in some contexts of use, is not successful (and this applies also for Windows).
make sure you have installed on our system for developing AVR toolchain with gcc. With Debian, the command is:
# apt-get install gcc-avr binutils-avr avr-libc avrdude avr-gdbthen we create a folder in our home: vmlabproj: ~ $ mkdir
(remember that in Ubuntu's sudo)
installed the necessary, we proceed to preparation the makefile.
for generating the necessary files I relied on the excellent Makefile Winavr, I only changed a little to generate even the COFF file with the all, and to "move" all the configuration part (micro, frequency clock, files, directories) to another file (I called
config) so as not to put hands in the Makefile.
My suggestion is first to create a directory where to put their work Vmlab. Each project will therefore have its own directory in which we are all the source files, headers, libraries, etc.. necessary.
vmlabproj and a dir. where we have made our first to design, named timer1:
vmlabproj ~ ~ $ cd / $ mkdir vmlabproj timer1
In this dir. So there we copy the main source file, that is where the main (), which we call always
main.c file and
makefile and config
. The makefile should not be changed, the config, yes, according to their needs. The
main.c is our software to turn the LED every second. we had already written:
# include \u0026lt;
avr / io.h
>
# include
\u0026lt;
avr / interrupt.h
>
int
main (void
)
{DDRB =
\u0026lt;
| ; | / / Set the output pin PB1 asTCCR1B | )
| / / set Timer1 in CTC mode (on OCR1A) | OCR1A |
| = 62499 | ; |
| TIMSK1 | = (1 |
| \u0026lt; | \u0026lt; |
| ; | / / Enable CTC interrupt on OCR1A |
CS10)
; / / Enable prescaler (fc/64)
/ / From this point on, the timer is started!
)
six
(
; / / enable interrupts while
(
1)
{/ * do nothing ... waiting for the 'interrupt * /}
}
/ * Routine management interrupt (runs every second) * / ISR ( TIMER1_COMPA_vect ) { PORTB ^ =(1
\u0026lt;
\u0026lt;
PB1) ;
/ / If PB1 PB1 = 0 then = 1, if PB1 PB1 = 0 = 1 then } file config is as follows: MCU name # MCU = ATmega168# Processor frequency (in Hz)
F_CPU
= 4000000 # Target file name (without extension) TARGET = main # Object files directory # To put object files in current directory, use a dot (.), do NOT makeTIMER1.PRJ
# this an empty or blank macro! OBJDIR = . # List C source files here. (C dependencies are automatically generated.) # The first one must be TARGET above defined, the other ones
# must be separated by a space. Examples:
# SRC = $(TARGET).c lcd.c i2c.
SRC = $( TARGET ) .c # List C++ source files here. (C dependencies are automatically generated.) spaced CPPSRC = # List Assembler source files here.
# Make them always end in a capital .S. Files ending in a lowercase .s
# will not be considered source files but generated files (assembler # output from the compiler), and will be deleted upon "make clean"! # Even though the DOS/Win* filesystem matches both .s and .S the same, # it will preserve the spelling of the filenames, and gcc itself does # care about how the name is spelled on its command-line. ASRC =
# List any extra directories to look for include files here. # Each directory must be seperated by a space. # Use forward slashes for directory separators.
# For a directory that has spaces, enclose it in quotes. EXTRAINCDIRS = # List any extra directories to look for libraries here. # Each directory must be seperated by a space. # Use forward slashes for directory separators. # For a directory that has spaces, enclose it in quotes.
EXTRALIBDIRS =
In MCU si definirà il tipo di micro (atmega168, atmega328, attiny2313 ecc.), in F_CPU la frequenza di lavoro in Hz (nel nostro caso 4000000 Hz, cioè 4MHz). TARGET è il solo nome (senza estensione) del nostro file principale.
OBJDIR
lasciamo il punto (i file oggetto verranno copiati nella stessa directory).
In SRC , se abbiamo più file sorgenti (es. lcd.c, i2c.c, serial.c ecc.) li specificheremo dopo il target, separandoli con uno spazio.
Stesso discorso per
CPPSRC
, che riguarda i file C++. Le altre definizioni le useremo se i nostri file si trovano in other directories, even if we file asm etc.. With the config preparation, let us go in the dir. of our project and launch a make vmlabproj/timer1 ~ $ cd ~ / $ make vmlabproj/timer1
After this command should be in our working directory some files, including those who are interested in VMLAB :
main.cof
main.elf
If we were to remove the generated files, just the classic clean:
~ / $ make clean vmlabproj/timer1
Without this project to create the file VMLAB, with a text editor,
. MICRO "ATmega168b" CKSEL CKDIV8 = 0000 = 1 ". 4MEG CLOCK
. Toolchain" GENERIC ". TARGET main.hex" . COFF "main.cof"
. STORE 5; Time of stop
simulation; ---------------------------------------------- --------------
K D1 VDD; D1 (LED), a terminal: anode (to be on VDD) terminal 2: cathode
R1 0.62K PB1 K, R1 (620Ohm) , terminal 1: on the cathode of the LED, terminal 2: up PB1
. PLOT V (PB1)
Directives come to define the micro, the clock frequency in MHz, the files that we created and the time up to which we want to run the simulation calculations. Since our timer generates a period of 2 seconds you can stop a bit 'more than twice the period.
VMLAB provides several components (up to 8 LED, slide, keyboard etc..), Which can be invoked by the user with a particular syntax (see help).
The syntax is very similar to that of Spice.
For the LED, the syntax is:
Dx VDD nomecatodo
With x ranging from 1 to 8, depending on the LED that we want to use.
The anode of the LED (the No. 1 terminal) must always be connected to VDD. The second terminal of the LED (cathode) call it, for example, "K" and connected to the PB1, through the resistance R1 of 620 ohms. VMLAB requires you to connect +5 V on the anode and therefore our LED does not light up more when there is +5 V, but rather when there is 0V.
The scheme is therefore:
The latest directive, asked VMLAB oscilloscope displays the voltage on pin PB1. We initiate
VMLAB open the menu and wine ... the project file, the menu bar with:
Project -> Open.
show is "Control Panel" (where are all the peripheral I / O and thus the LED) and an oscilloscope with the controls, with:
View -> Scope
View ->
Control Panel and launch a build ... which is actually just a VMLAB to build, because the files have already been "build" manually with make ...
Project -> Build Project
At this point we run the Run (press F5
) and watch the PB1 signal oscilloscope. We note immediately that
simulation VMLAB not in real time: the LED is on / off for 1s, but the time counted on the oscilloscope are accurate.
Given the time involved, you should set the oscilloscope to a Time / DIV 50ms/DIV and "Full View".
There are two sliders available for the measurement of time, the first is activated by clicking on a button and has the style of a continuous line, the second is activated by clicking on the button 2 and the style of a dotted line. Below these buttons, shows the difference of time t2-t1
The measure of time will be for the time when the output is low and the time when the output is high. Obviously
need to stop the simulation at a moment when you see all the half-life, do the size and then restart it to see the full next half period.The simulation results are shown below and as you can see the times are perfectly equal to 1s.
Time "on" - LED lights (PB1 = 0V)
:
"off" time - LED off (PB1 = 5V)
Have fun!
---------------------------------
Sources and instruments used: VMLAB Forum: http:/ / www.amctools.com/cgi-bin/yabb2/YaBB.pl?board=news Tutorial VMLAB: http://www.scienceprog.com/using-vmlab-as-virtual-oscilloscope/ gEDA editor schemi: http://www.gpleda.org/index.html Generatore online di sintassi evidenziata: http://tohtml.com/
http://amctools.com/download.htm
0 comments:
Post a Comment