Designed by: Vassilis Stergiopoulos

Published by: Vassilis Serasidis at 13.Dec.2008

 

 

 

 

Introduction

You can experiment with Atmega8515 economically and easily. You can construct the following board, buy an AVRISP unit, download from Atmel AVRstudio and you are ready. The circuit is easy and I believe is very useful. Instead of paying a lot of money for evaluation boards or development systems, you can start with this board I have made and the help of an AVR In System Programmer (AVR ISP). This is the way I work. Firstly, I wrote the software and then I burnt the AVR with an ISP. With this board I studied the chaos of timers on ATmega8515 for just a few PWM (Pulse Width Modulation) applications.

If I want another one board, I build it in less than a half an hour.

I think these boards and source codes I give you, will be very useful for people who start their journey to the magic world of AVR microcontrollers.

 

 

 

The circuit

I have placed an electronic stabilization unit with 7805 IC1.

D1 is for protection against wrong connection. C2, C3 are always present for proper operation of IC1.

C4 is for better filtering. The unit is powered with a rectified AC wave of 9Volts.

There are 6 pins for ISP (In Circuit Programming) where you can connect the AVRISP. For simplicity the connector is split in two. You can easily build an adaptor for ISP connector as shown below.

You can write a test program and directly test it on this board. I have placed pins at every pin, so I can connect any additional components with an additional board, like the test leds shown.

 

I have also two test programs where we can see some interesting simple uses of the timer TC0 of the unit.

In the examples I give an example of interrupt. You can see a way of varying the intensity of a LED.

 

 

Components list

IC1: 7805

IC2: ATmega8515

C1: 1μF

C2=C3: 10 nF

C4: 1000='MSO-ANSI-LANGUAGE:EL'>μF/25V

D1: 1N4001

The back side of the board, showing the connections.

 

 

Below the ISP adapter is shown. This way the final pcb is significantly simplified that using a 2x3 pins array.

Also a simple LEDs array that can be plagued easily to the pins. The common is connected to ground with separate pin (white wire)

 

 

 

 

; ==================== Example no1 (in Assembly) ====================

; Test timers in ATmega8515

; every time that tc0 produces a match interrupt the counter cnt

; is incremented and output to portA.

; The square wave is present at pin no1 (B0)

.NOLIST

.INCLUDE "m8515def.inc"

.LIST

.def='MSO-TAB-COUNT:1'>      poA                 = r17   ; out buffer

.def='MSO-TAB-COUNT:1'>      poB                 = r18

.def='MSO-TAB-COUNT:1'>      poC                 = r19

.def='MSO-TAB-COUNT:1'>      poD                 = r20

.def='MSO-TAB-COUNT:1'>      poE                  = r21

.def='MSO-TAB-COUNT:1'>      cnt                   = r24   ; counter

 

; Code starts here

.CSEG

.ORG $0000

; Reset- and Interrupt-vectors

rjmp='MSO-TAB-COUNT:1'>    main    ='MSO-TAB-COUNT:1'>            ; 1 Reset-vector

rjmp='MSO-TAB-COUNT:1'>    IInt0                ; 2 External Interrupt Request 0

rjmp='MSO-TAB-COUNT:1'>    IInt1                ; 3 External Interrupt Request 1

rjmp='MSO-TAB-COUNT:1'>    TCpt1              ; 4 Timer/Counter1 Capture event

rjmp='MSO-TAB-COUNT:1'>    TCmp1            ; 5 Timer/Counter1 Compare matchA

rjmp='MSO-TAB-COUNT:1'>    TCmp2            ; 6 Timer/Counter1 Compare matchB

rjmp='MSO-TAB-COUNT:1'>    TOvf1             ; 7 Timer/Counter1 Overflow

rjmp='MSO-TAB-COUNT:1'>    TOvf0             ; 8 Timer/Counter0 Overflow

rjmp='MSO-TAB-COUNT:1'>    SrTrC  ='MSO-TAB-COUNT:1'>            ; 9 SPI/Serial transfer complete

rjmp='MSO-TAB-COUNT:1'>    URxCp            ;10 USART Rx complete

rjmp='MSO-TAB-COUNT:1'>    UTxDe            ;11Uart tx data register empty

rjmp='MSO-TAB-COUNT:1'>    UTxCp            ;12 Uart Tx complete

rjmp='MSO-TAB-COUNT:1'>    AnaCp             ;13 Analog comparator

rjmp='MSO-TAB-COUNT:1'>    XINT2 ='MSO-TAB-COUNT:1'>            ;14 External Interrupt2

rjmp='MSO-TAB-COUNT:1'>    TCMch            ;15 Timer / Counter0 Compare match

rjmp='MSO-TAB-COUNT:1'>    EERdy ='MSO-TAB-COUNT:1'>            ;16 EEPROM ready

rjmp='MSO-TAB-COUNT:1'>    SPRdy ='MSO-TAB-COUNT:1'>            ;17 Store Program Memory Ready

; ************** Interrupt service routines ********

IInt0: ='MSO-TAB-COUNT:1'>              reti='MSO-TAB-COUNT:1'>      ; 2

IInt1:='MSO-TAB-COUNT:1'>               reti='MSO-TAB-COUNT:1'>      ; 3

TCpt1:='MSO-TAB-COUNT:1'>             reti='MSO-TAB-COUNT:1'>      ; 4

TCmp1:='MSO-TAB-COUNT:1'>           reti      ; 5

TCmp2:='MSO-TAB-COUNT:1'>           reti      ; 6

TOvf1:='MSO-TAB-COUNT:1'>            reti='MSO-TAB-COUNT:1'>      ; 7

TOvf0:='MSO-TAB-COUNT:1'>            reti='MSO-TAB-COUNT:1'>      ; 8

SrTrC:='MSO-TAB-COUNT:1'>             reti='MSO-TAB-COUNT:1'>      ; 9

URxCp:='MSO-TAB-COUNT:1'>           reti      ;10

UTxDe:='MSO-TAB-COUNT:1'>           reti      ;11

UTxCp:='MSO-TAB-COUNT:1'>           reti      ;12

AnaCp:='MSO-TAB-COUNT:1'>            reti      ;13

XINT2:='MSO-TAB-COUNT:1'>            ; external interrupt2

; In Extended MCU Interrupt Register EMCUIR

; bit0: ISC2: Interrupt Sense Control 2

; If ISC2=0 then the falling edge of INT2 generates the interrupt

; Provided that I-flag=1 in SREG and in bit5=INTF2=1 (interrupt-enable bit) in GICR.

='MSO-TAB-COUNT:2'>                        reti='MSO-TAB-COUNT:1'>                  ;14

TCMch:='MSO-TAB-COUNT:1'>          inc                   cnt

='MSO-TAB-COUNT:2'>                        ldi='MSO-TAB-COUNT:2'>                    r16,100

='MSO-TAB-COUNT:2'>                        out='MSO-TAB-COUNT:2'>                   OCR0,r16

='MSO-TAB-COUNT:2'>                        ldi='MSO-TAB-COUNT:2'>                    r16,1                ; set OCF0 flag for compare interrupt

='MSO-TAB-COUNT:2'>                        out='MSO-TAB-COUNT:2'>                   TIFR,r16

='MSO-TAB-COUNT:2'>                        reti='MSO-TAB-COUNT:1'>                  ;15

EERdy:='MSO-TAB-COUNT:1'>           reti      ='MSO-TAB-COUNT:1'>            ;16

SPRdy:='MSO-TAB-COUNT:1'>            reti      ='MSO-TAB-COUNT:1'>            ;17

; **************** End of interrupt service routines ***********

; ----------------------------------------------------------------------------------

; Timers notes

; T/C0 output OC0: pin1

; TCCR0 Timer/Counter Control register

; Bit7 = FOC0 = 0 in fast PWM mode

; Fast PWM: (bit6=WGM00, bit3=WGM01) = (1,1) = FAST pwm MODE

; clock select

; bits 2,1,0 = cs02, cs01,         cs0='MSO-TAB-COUNT:2'>                   function

;='MSO-TAB-COUNT:4'>                                               0='MSO-TAB-COUNT:2'>                      0          0                      no source (stoped)

;='MSO-TAB-COUNT:4'>                                               0='MSO-TAB-COUNT:2'>                      0          1                      clock

;='MSO-TAB-COUNT:4'>                                               0='MSO-TAB-COUNT:2'>                      1          0                      clock/8

;='MSO-TAB-COUNT:4'>                                               0='MSO-TAB-COUNT:2'>                      1          1                      clock/64

;='MSO-TAB-COUNT:4'>                                               1='MSO-TAB-COUNT:2'>                      0          0                      clock/256

;='MSO-TAB-COUNT:4'>                                               1='MSO-TAB-COUNT:2'>                      0          1                      clock/1024

; (bit5,bit4)=(com01,com00)=(1,0) non-inverting mode oc0=0 on match and oc0=1 on bottom.

; so TCCR0 = 0110 1101 = $6d

; TIMSK Timer Interrupt Mask Register: set bit0 = Output Compare Match Interrupt Enable = OCIE0

; TIFR Timer Interrupt Flag Register: bit0 = ocf0 = Output Compare Flag 0 goes 1 when match occurs

;

; ******************** Main program ********************************

main:='MSO-TAB-COUNT:1'>               ldi='MSO-TAB-COUNT:2'>                    r16,LOW(RAMEND)='MSO-TAB-COUNT:1'> ;Initiate Stackpointer.

='MSO-TAB-COUNT:2'>                        out='MSO-TAB-COUNT:2'>                   SPL,r16

='MSO-TAB-COUNT:2'>                        ldi='MSO-TAB-COUNT:2'>                    r16,HIGH(RAMEND)

='MSO-TAB-COUNT:2'>                        out='MSO-TAB-COUNT:2'>                   SPH,r16

='MSO-TAB-COUNT:2'>                        ldi='MSO-TAB-COUNT:2'>                    r16,$ff

='MSO-TAB-COUNT:2'>                        out='MSO-TAB-COUNT:2'>                   ddrA,r16

='MSO-TAB-COUNT:2'>                        out='MSO-TAB-COUNT:2'>                   ddrB,r16

='MSO-TAB-COUNT:1'>                        out='MSO-TAB-COUNT:2'>                   ddrC,r16

='MSO-TAB-COUNT:2'>                        out='MSO-TAB-COUNT:2'>                   ddrD,r16

='MSO-TAB-COUNT:2'>                        out                   ddrE,r16

='MSO-TAB-COUNT:2'>                        com='MSO-TAB-COUNT:2'>                 r16

='MSO-TAB-COUNT:2'>                        out='MSO-TAB-COUNT:2'>                   portA,r16

='MSO-TAB-COUNT:2'>                        out                   portB,r16

='MSO-TAB-COUNT:2'>                        out='MSO-TAB-COUNT:2'>                   portC,r16

='MSO-TAB-COUNT:2'>                        out='MSO-TAB-COUNT:2'>                   portD,r16

='MSO-TAB-COUNT:2'>                        out='MSO-TAB-COUNT:2'>                   portE,r16

='MSO-TAB-COUNT:2'>                        clr='MSO-TAB-COUNT:2'>                    cnt

                        ldi='MSO-TAB-COUNT:2'>                    r16,$6d='MSO-TAB-COUNT:1'>            ; TCCR0 set. clock/1024, fast PWM mode

='MSO-TAB-COUNT:2'>                        out='MSO-TAB-COUNT:2'>                   TCCR0,r16

='MSO-TAB-COUNT:2'>                        ldi='MSO-TAB-COUNT:2'>                    r16,1                ; set OCF0 flag for compare interrupt

='MSO-TAB-COUNT:2'>                        out='MSO-TAB-COUNT:2'>                   TIMSK,r16

='MSO-TAB-COUNT:2'>                        sei

loop:='MSO-TAB-COUNT:1'>                out='MSO-TAB-COUNT:2'>                   portA,cnt

='MSO-TAB-COUNT:2'>                        rjmp='MSO-TAB-COUNT:1'>                loop

 

; ==================== Example2: (in Assembly) ====================

; Test timers in ATmega8515

; The pwm is changing it's duty cycle between 0 anf 255 and output to pin1 (B0)

; The duty cycle value is stored in register "pwm".

; The pwm is counting increasing and when it reaches 255 it

.NOLIST

.INCLUDE "m8515def.inc"

.LIST

.def='MSO-TAB-COUNT:1'>      cnt                   = r17   ; counter

.def='MSO-TAB-COUNT:1'>      pwm                = r18

; Code starts here

.CSEG

.ORG $0000

; Reset- and Interrupt-vectors

rjmp='MSO-TAB-COUNT:1'>    main    ; 1 Reset-vector

rjmp='MSO-TAB-COUNT:1'>    IInt0    ; 2 External Interrupt Request 0

rjmp='MSO-TAB-COUNT:1'>    IInt1    ; 3 External Interrupt Request 1

rjmp='MSO-TAB-COUNT:1'>    TCpt1              ; 4 Timer/Counter1 Capture event

rjmp='MSO-TAB-COUNT:1'>    TCmp1            ; 5 Timer/Counter1 Compare matchA

rjmp='MSO-TAB-COUNT:1'>    TCmp2            ; 6 Timer/Counter1 Compare matchB

rjmp='MSO-TAB-COUNT:1'>    TOvf1             ; 7 Timer/Counter1 Overflow

rjmp='MSO-TAB-COUNT:1'>    TOvf0             ; 8 Timer/Counter0 Overflow

rjmp='MSO-TAB-COUNT:1'>    SrTrC  ; 9 SPI/Serial transfer complete

rjmp='MSO-TAB-COUNT:1'>    URxCp            ;10 USART Rx complete

rjmp='MSO-TAB-COUNT:1'>    UTxDe            ;11 Uart Tx data register empty

rjmp='MSO-TAB-COUNT:1'>    UTxCp            ;12 Uart Tx complete

rjmp='MSO-TAB-COUNT:1'>    AnaCp             ;13 Analog comparator

rjmp='MSO-TAB-COUNT:1'>    XINT2 ;14 External Interrupt2

rjmp='MSO-TAB-COUNT:1'>    TCMch            ;15 Timer / Counter0 Compare match

rjmp='MSO-TAB-COUNT:1'>    EERdy ;16 EEPROM ready

rjmp='MSO-TAB-COUNT:1'>    SPRdy ;17 Store Program Memory Ready

; ************** Interrupt service routines ********

IInt0: ='MSO-TAB-COUNT:1'>              reti='MSO-TAB-COUNT:1'>      ; 2

IInt1:='MSO-TAB-COUNT:1'>               reti='MSO-TAB-COUNT:1'>      ; 3

TCpt1:='MSO-TAB-COUNT:1'>             reti='MSO-TAB-COUNT:1'>      ; 4

TCmp1:='MSO-TAB-COUNT:1'>           reti      ; 5

TCmp2:='MSO-TAB-COUNT:1'>           reti      ; 6

TOvf1:='MSO-TAB-COUNT:1'>            reti='MSO-TAB-COUNT:1'>      ; 7

TOvf0:='MSO-TAB-COUNT:1'>            reti='MSO-TAB-COUNT:1'>      ; 8

SrTrC:='MSO-TAB-COUNT:1'>             reti='MSO-TAB-COUNT:1'>      ; 9

URxCp:='MSO-TAB-COUNT:1'>           reti      ;10

UTxDe:='MSO-TAB-COUNT:1'>           reti      ;11

UTxCp:='MSO-TAB-COUNT:1'>           reti      ;12

AnaCp:='MSO-TAB-COUNT:1'>            reti      ;13

XINT2:='MSO-TAB-COUNT:1'>            ; external interrupt2

; In Extended MCU Interrupt Register EMCUIR

; bit0: ISC2: Interrupt Sense Control 2

; If ISC2=0 then the falling edge of INT2 generates the interrupt

; Provided that I-flag=1 in SREG and in bit5=INTF2=1 (interrupt-enable bit) in GICR.

='MSO-TAB-COUNT:2'>                        reti='MSO-TAB-COUNT:1'>      ;14

TCMch:='MSO-TAB-COUNT:1'>          tst        pwm

='MSO-TAB-COUNT:2'>                        brne='MSO-TAB-COUNT:1'>     tcm

='MSO-TAB-COUNT:2'>                        inc='MSO-TAB-COUNT:1'>       cnt

tcm:='MSO-TAB-COUNT:1'>                 sbrs='MSO-TAB-COUNT:1'>     cnt,0

='MSO-TAB-COUNT:2'>                        rjmp='MSO-TAB-COUNT:1'>    tcm1

='MSO-TAB-COUNT:2'>                        inc='MSO-TAB-COUNT:1'>       pwm

='MSO-TAB-COUNT:2'>                        rjmp='MSO-TAB-COUNT:1'>    tcm2

tcm1:='MSO-TAB-COUNT:1'>               dec='MSO-TAB-COUNT:1'>      pwm

tcm2:='MSO-TAB-COUNT:1'>               out='MSO-TAB-COUNT:1'>       OCR0,pwm='MSO-SPACERUN:YES'>                                                                                                                                                                    ='MSO-SPACERUN:YES'>                                                                                             

='MSO-TAB-COUNT:2'>                        ldi='MSO-TAB-COUNT:1'>        r16,1                ; set OCF0 flag for compare interrupt

='MSO-TAB-COUNT:2'>                        out='MSO-TAB-COUNT:1'>       TIFR,r16

='MSO-TAB-COUNT:2'>                        reti='MSO-TAB-COUNT:1'>      ;15

EERdy:='MSO-TAB-COUNT:1'>           reti      ;16

SPRdy:='MSO-TAB-COUNT:1'>            reti      ;17

; **************** End of interrupt service routines ***********

; ----------------------------------------------------------------------------------

; Timers notes

; T/C0 output OC0: pin1

; TCCR0 Timer/Counter Control register

; Bit7 = FOC0 = 0 in fast PWM mode

; Fast PWM: (bit6=WGM00, bit3=WGM01) = (1,1) = FAST pwm MODE

; clock select

; bits 2,1,0 = cs02, cs01,         cs0='MSO-TAB-COUNT:2'>                   function

;='MSO-TAB-COUNT:4'>                                               0='MSO-TAB-COUNT:2'>                      0          0                      no source (stoped)

;='MSO-TAB-COUNT:4'>                                               0='MSO-TAB-COUNT:2'>                      0          1                      clock

;='MSO-TAB-COUNT:4'>                                               0='MSO-TAB-COUNT:2'>                      1          0                      clock/8

;='MSO-TAB-COUNT:4'>                                               0='MSO-TAB-COUNT:2'>                      1          1                      clock/64

;='MSO-TAB-COUNT:4'>                                               1='MSO-TAB-COUNT:2'>                      0          0                      clock/256

;='MSO-TAB-COUNT:4'>                                               1='MSO-TAB-COUNT:2'>                      0          1                      clock/1024

; (bit5,bit4)=(com01,com00)=(1,0) non-inverting mode oc0=0 on match and oc0=1 on

; bottom.

; TIMSK Timer Interrupt Mask Register: set bit0 = Output Compare Match Interrupt

; Enable = OCIE0

; TIFR Timer Interrupt Flag Register: bit0 = ocf0 = Output Compare Flag 0 goes 1

; when match occurs

;

; ******************** Main program ********************************

main:

='MSO-TAB-COUNT:1'>                        ldi                    r16,LOW(RAMEND)='MSO-TAB-COUNT:1'> ;Initiate Stackpointer.

='MSO-TAB-COUNT:2'>                        out='MSO-TAB-COUNT:2'>                   SPL,r16

='MSO-TAB-COUNT:2'>                        ldi='MSO-TAB-COUNT:2'>                    r16,HIGH(RAMEND)

='MSO-TAB-COUNT:2'>                        out='MSO-TAB-COUNT:2'>                   SPH,r16

='MSO-TAB-COUNT:2'>                        ldi='MSO-TAB-COUNT:2'>                    r16,$ff

='MSO-TAB-COUNT:2'>                        out='MSO-TAB-COUNT:2'>                   ddrA,r16

='MSO-TAB-COUNT:2'>                        out='MSO-TAB-COUNT:2'>                   ddrB,r16

='MSO-TAB-COUNT:2'>                        out='MSO-TAB-COUNT:2'>                   ddrC,r16

='MSO-TAB-COUNT:2'>                        out='MSO-TAB-COUNT:2'>                   ddrD,r16

='MSO-TAB-COUNT:2'>                        out                   ddrE,r16

='MSO-TAB-COUNT:2'>                        com='MSO-TAB-COUNT:2'>                 r16

='MSO-TAB-COUNT:2'>                        out='MSO-TAB-COUNT:2'>                   portA,r16

='MSO-TAB-COUNT:2'>                        out                   portB,r16

='MSO-TAB-COUNT:2'>                        out='MSO-TAB-COUNT:2'>                   portC,r16

='MSO-TAB-COUNT:2'>                        out='MSO-TAB-COUNT:2'>                   portD,r16

='MSO-TAB-COUNT:2'>                        out='MSO-TAB-COUNT:2'>                   portE,r16

='MSO-TAB-COUNT:2'>                        clr='MSO-TAB-COUNT:2'>                    cnt

='MSO-TAB-COUNT:2'>                        clr='MSO-TAB-COUNT:2'>                    pwm

='MSO-TAB-COUNT:2'>                        ldi='MSO-TAB-COUNT:2'>                    r16,$6a='MSO-TAB-COUNT:1'>            ; TCCR0 set. clock/256, fast PWM mode

='MSO-TAB-COUNT:2'>                        out='MSO-TAB-COUNT:2'>                   TCCR0,r16

='MSO-TAB-COUNT:2'>                        ldi='MSO-TAB-COUNT:2'>                    r16,1                ; set OCF0 flag for compare interrupt

='MSO-TAB-COUNT:2'>                        out='MSO-TAB-COUNT:2'>                   TIMSK,r16

='MSO-TAB-COUNT:2'>                        sei

loop:='MSO-TAB-COUNT:1'>                rjmp='MSO-TAB-COUNT:1'>    loop

 

Download the source code in assembly, schematic and pictures of this project

 

Created by Vassilis Stergiolpoulos and published by Vassilis Serasidis at 13.Dec.2008