Yahoo Groups archive

AVR-Chat

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

Thread

Re: [AVR-Chat] *sigh*

Re: [AVR-Chat] *sigh*

2007-07-05 by BobGardner@aol.com

In a message dated 7/5/2007 7:38:07 P.M. Eastern Daylight Time,  
tjkeller1@alltel.net writes:

BobGardner@aol.com wrote:
>
> I think you need to stick a  0x49 into TCCR0 to get timer0 into fast pwm
> mode, prescaler of 1. Then  just put whatever you want in OCR0 to adj 
> duty.. I use
> the  iccavr appbuilder.
>

Well, I tried 0x49, same  symptoms.  LED lights at 100% and stays 
there  )-:.

This is making me nuts.
==============================================
Did you ever post the whole program? It only takes 1 instruction to init  the 
timer for pwm, and 1 instruction to change it. The rest of the program is  
something like  
read-a-pot-and-stick-the-8-bit-result-in-the-ocr0-reg-to-control-the-pwm  right?
 



************************************** See what's free at http://www.aol.com.


[Non-text portions of this message have been removed]

Re: [AVR-Chat] *sigh*

2007-07-06 by Thomas Keller

BobGardner@aol.com wrote:
>
> Did you ever post the whole program? It only takes 1 instruction to 
> init the
> timer for pwm, and 1 instruction to change it. The rest of the program is
> something like
> read-a-pot-and- stick-the- 8-bit-result- in-the-ocr0- reg-to-control- 
> the-pwm right?
>

   I think John Samperi may have hit the nail onthe head, there *IS* no 
PWM on the AT90S8515.  The dopwnfalls of using obsolete chips, eh?


tom

Here is the code as it exists now: 

---- cut here ----

;
;    FILE NAME:    SantaFe.asm
;
;    PROJECT:    REDACTED
;
;    DATE:        2007/06/28
;
;    PLATFORM:    Atmel AT90S8515, assemly language
;                [NOTE:  finished product will rin on ATtiny15 processor]
;
;    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.  This table contains the 90 values computed for
;    angles from 0 to 89 degrees, with the following formula: 
;    (sin(x)^2) * 255   This normalizes the sin squared value to an 8 bit
;    integer approximation, which is more than good enough for this
;    application.
;

.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

TABLE:    .db 255, 255, 255, 254, 254, 253, 252, 251, 250, 249, 247, 246
    .db 244, 242, 240, 238, 236, 233, 231, 228, 225, 222, 219, 216
    .db 213, 209, 206, 202, 199, 195, 191, 187, 183, 179, 175, 171
    .db 167, 163, 158, 154, 150, 145, 141, 136, 132, 127, 123, 119
    .db 114, 110, 105, 101, 97, 92, 88, 84, 80, 76, 72, 68, 64, 60
    .db 56, 53, 49, 46, 42, 39, 36, 33, 30, 27, 24, 22, 19, 15
    .db 13, 11, 9, 8, 6, 5, 4, 3, 2, 1, 1, 0, 0, 0

.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,    0x59    ; end of table (90 8 bit integers)
    ldi    ZERO,    0x00        ; make sure register holds zero value

;-----------------------------------------------------------------------------
;    initialize counters, PWM module
;

    ldi    TEMP,    0x03        ; enable timer and compare match register
    out    TIMSK,    TEMP        ; and store to appropriate register
    ldi    TEMP,    0x49        ; set up timer prescaler
    out    TCCR0,    TEMP        ; output to correct 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 ; out output to appropriate
    out    OCR1AL,        CNTRLOW ; counter registers
    ldi    TEMP,    0x01        ; set port B pin 0 to output
    out    DDRB,    TEMP        ; and output it to the appropriate register

;-----------------------------------------------------------------------------
;    set up timer configuration registers for interrupt
;
   
    ldi    TEMP,    0x24        ; 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:



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 that 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 fis to step dwon 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 data for this angle
    out    OCR0,    TEMP        ; output to PWM controller
    in    r27,    OCR0        ; take a peek at the PWM control register

    ret                                ; all done, go home

;
;    end of PWM_Handler               
;
   
;
;=============================================================================
;
;    end of code
;

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.