avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] AVR and PWM


From: Leon Heller
Subject: Re: [avr-gcc-list] AVR and PWM
Date: Sat, 08 Jun 2002 19:46:10 +0000



From: "Brandon Tolbert" <address@hidden>
To: "AVR List" <address@hidden>
Subject: [avr-gcc-list] AVR and PWM
Date: Sat, 8 Jun 2002 12:18:55 -0500

OK guys can someone point me in the right direction to learn about PWM on my avr 2313? I am looking for a bit of code or web page that will explain how this is done. I am thinking about using it for motor control in my microbot. Thanks for any help!!!

Here's a little test program I wrote when I was using PWM with the 2313:

   .include "2313def.inc"

    .def      temp=r16

    .cseg

    ldi       temp,RAMEND    ;initialise stack pointer
    out       spl,temp
    ser       temp           ;Port B outputs
    out       ddrb,temp

;clear all registers

       clr     temp
       out     tccr1a,temp
       out     tccr1b,temp
       out     tcnt1h,temp
       out     tcnt1l,temp
       out     ocr1ah,temp
       out     ocr1al,temp


;set up PWM output via PB3 (pin 15)

       ldi     temp,0x81       ;non-inverting PWM, 8-bit
       out     TCCR1A,temp
       ldi     temp,0x02       ;CK/8
       out     tccr1b,temp


       clr     temp
loop:
       out     ocr1al,temp
       inc     temp
       rcall   dly
       rjmp      loop


dly:
    ser       r17
dly1:
    ser       r18
dly2:
    dec       r18
    brne      dly2
    dec       r17
    brne      dly1
    ret

If you drive a small bulb (incandescent) via a power transistor from the PWM output you should see it slowly increase then decrease brightness.

Leon
--
Leon Heller, G1HSM Tel: +44 1327 359058 Email:address@hidden
My web page: http://www.geocities.com/leon_heller
My low-cost Altera Flex design kit: http://www.leonheller.com


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.

avr-gcc-list at http://avr1.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]