Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: [AVR-Chat] hrm...why for I am not getting PWM output from this?

2007-07-04 by enkitec@gmail.com

I think you should set one of the COM1 bits on TCCR1A register.

On 3 Jul 2007 at 18:35, Thomas Keller wrote:

> The code seems to be stepping through the tabel correctly, and 
> outputting the control value to the timer/counter0, which is the PWM 
> unit.  Why am I not getting any PWM output from the output pin?
> 
> -----   cut here  -----
> 
> ;
> ;    FILE NAME:    SantaFe.asm
> ;
> ;    PROJECT:    ***  REDACTED  ***
> ;
> ;    DATE:        2007/06/28
> ;
> ;    PLATFORM:    Atmel AT90S8515, assemly language
> ;
> ;    COPYRIGHT:    Copyright (C) 2007, Thomas J Keller
> ;                All Rights Reserved
> ;
> ;    DESCRIPTION:   ****  REDACTED  ***
> ;    HISTORY:
> ; ======================================================================
> ; | who |    date    |  Description                                |    
>               |
> ; 
> +-----+------------+------------------------------------------------------------------------------------------------+
> ; | tjk | 2007/06/28 | initialize file                                
>         |
> ; 
> +-----+------------+------------------------------------------------------------------------------------------------+
> ; | tjk | 2007/06/29 | add teble definition, develop initialization 
> code                                          |
> ; 
> +-----+------------+-------------------------------------------------------------------------------------------------+
> ;  =====================================================================
> ;
> 
> ;
> ;    .include files
> ;
> 
> .include    "m8515def.inc"
> 
> ;
> ;    define registers
> ;
> 
> .def    TEMP        =    R16    ; temp register
> .def    ANGLE        =    R17    ; angle counter
> .def    DIRECTION     =    R18    ; counter direction flag
> .def    TABLETOP    =    R19    ; max table index + 1
> .def    ZERO        =    R20    ; a register with a guaranteed zero value
> .def    CNTRLOW    =    R21    ; low byte of 16 bit counter
> .def    CNTRHIGH    =    R22    ; high byte of 16 bit counter
> 
> ;
> ;    equates
> ;
> 
> .equ    UP        =    0x00    ; up direction flag
> .equ    DOWN        =    0xff    ; down direction flag
> 
> ;
> ;    declare profile table. 
> ;
> 
> .eseg                    ; set this to EEPROM segment
> 
> .org    0x00
> 
> TABLE:        .db 0, 0, 0, 1, 1, 2, 3, 4, 5, 6, 8, 9, 11, 13, 15, 17
>        .db 19, 22, 24, 27, 30, 33, 36, 39, 42, 46, 49, 53
>        .db 56, 60, 64, 68, 72, 76, 80, 84, 88, 92, 97, 101
>        .db 105, 110, 114, 119, 123, 128, 132, 136, 141, 145
>        .db 150, 154, 158, 163, 167, 171, 175, 179, 183, 187
>        .db 191, 195, 199, 202, 206, 209, 213, 216, 219, 222
>        .db 225, 228, 231, 233, 236, 238, 240, 242, 244, 246
>        .db 247, 249, 250, 251, 252, 253, 254, 255, 255, 255
> 
> .cseg                    ; back to code segment
> 
> ;
> ;    end of table declaration
> ;
> 
> 
> ; Define Reset and interrupt vectors table
> ;
> 
> RESET:
>     rjmp     START            ; reset interrupt
>        reti                ; external interrupt 0
>        reti                ; pin change interrupt 0
>        reti                ; timer/counter1 compare match A
>        rjmp    LOOP0            ; timer/counter1 overflow
>        reti                ; timer/counter 0 overflow interrupt
>        reti                ; EEPROM ready
>        reti                ; analog cvomparator match
>        reti                ; ADC conversion complete
>        reti                ; timer/counter1 compare match B
>     reti                ; timer/counter0  compare match A interrupt
>        reti                ; timer/counter0 compare match B
>       reti                ; watchdog timeout
>        reti                ; USI start
>        reti                ; initialization code
> ;
> 
> START:
> 
>     ldi TEMP,    0xDF               ; Init stack pointer
>        out 0x3D,    TEMP               ; and output it to the register
> 
>     ldi    TABLETOP,    0x5a    ; end of table
> 
> ;
> ;    initialize counters, etc.
> ;
> 
>     ldi    r26,    0x03        ; enable timer and compare match register
>     out    TIMSK,    r26        ; and store ti appropriate register
> 
> ;
> ;    set up timer maximum count
> ;
> 
>     in    TEMP,    SREG        ; save status register value
>     cli                ; disable global interupt flag
> 
>     ldi    CNTRHIGH,    0x00    ; set high
>     ldi    CNTRLOW,    0x05    ; and low bytes of 16 bit timer control 
> variable
>     out    OCR1AH,        CNTRHIGH  ; and output to appropriate
>     out    OCR1AL,        CNTRLOW  ; counter registers
> 
> ;
> ;    set up timer configuration registers for interrupt
> ;
>    
>     ldi    TEMP,    0x04        ; bit mask for CTC mode counting
> `    out    TCCR1A,    TEMP        ; and write to appropriate register
>     ldi    TEMP,    0x1c        ; set up divide by 1024 clocking for counter
>     out    TCCR1B,    TEMP        ; and output to register in question
>     ldi    TEMP,    0x40        ; set compare match A interrupt flag
>     out    TIMSK,    TEMP        ; and store to appropriate register
> 
>     out    SREG,    temp        ; restore status register value
>     sei                ; re-enable interrupt flag
> 
> ;
> ;    main program begins here
> ;
> 
> MAIN:
>    
>     sei                ; enable global interrupts   
> 
>     ldi    DIRECTION,    UP    ; set direction to "up"
>     ldi    ANGLE,    0x00        ; preset angle counter to zero
> 
> 
> MAINLOOP:
> 
>     rjmp    MAINLOOP        ; do this all day until interrupted
> 
> LOOP0:
>     tst    DIRECTION        ; check to see which way we're going   
> 
>     breq    STEPUP            ; go do an UP step
>                                     ; else do a DOWN step
>     dec    ANGLE            ; step DOWN
>     breq    DOWNFIX        ; go fix down to up
> 
> FINIS:
> 
>     rcall    PWM_Handler        ; go update the PWM module
>     reti                ; go wait some more
> 
> STEPUP:
>     inc    ANGLE            ; step up one degree
>     cp    ANGLE,    TABLETOP    ; are we past end of table?
>     breq    UPFIX            ; yep, so go fix to step down again
>    
>     rjmp    FINIS            ; and do it all over again
> 
> DOWNFIX:
>     ldi    DIRECTION,    UP    ; point the table back toward the beginning
>     rjmp    FINIS
> 
> UPFIX:
> 
>     ldi    DIRECTION, DOWN    ; we're going the other way again
>     rjmp    FINIS
> 
> ;
> ;    EEPROM read routine
> ;
> 
> EERead:
> 
>     cli                ;disable interrupts during EEPROM operation   
>     sbic    EECR,     EEWE        ; check to see if previous write is done
>     rjmp    EERead            ; nope, try again
>     out    EEARH,    ZERO        ; output the high and
>     out    EEARL,     ANGLE        ; the low bytes of the addrress to read
>     sbi    EECR,    EERE        ; set up the EEProm read
>     in    TEMP,    EEDR        ; and read the byte
>     sei                ; re-enable interrupts when done
> 
>     ret                ; all done, return to caller
> 
> ;
> ;    end EEPROM read routine
> ;
> 
> ;
> ;    PWM interrupt handler
> ;
> 
> PWM_Handler:
> 
>     rcall    EERead            ; go read the EEPROM location
> 
>     out    OCR0,    TEMP        ; output to PWM controller
> 
>     ret                                ; all done, go home
> 
> ;
> ;    end of PWM_Handler               
> ;
> 
> 
> ;
> ;    end of code
> ;
> 
> 
> 
>  
> Yahoo! Groups Links
> 
> 
>

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.