Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Name: main.S
- Project: test3
- $Author: jcsilva $
- Creation Date: 2016-08-06
- Tabsize: 4
- Copyright: License: GNU GPL v2 (see License.txt)
- ;
- This Revision: $Id: main.S,v 1.3 2016/08/04 21:02:25 jcsilva Exp $
- $Log$
- */
- /*
- The code writes to the cal reg the calibration value from the last
- flash position (0x3ff), calibration error below 1%.
- Timer T1 works in PWM mode at a frequency of 12.5KHz, output OC1 has
- an LC low pass filter and the output is connected to a small speaker.
- A sine wave is programed in the eeprom by the make file, the values
- are reloaded incrementally to the pwm output.
- a sine wave of 195 Hz should be output.
- */
- #define __SFR_OFFSET 0
- #include <avr/io.h>
- #include <avr/eeprom.h>
- /*
- EEPROM
- */
- /*
- IO Definitions
- */
- #define LED PB0
- #define OUT PB1
- /*
- Constants
- */
- #define ZERO 0
- /* Time system constants */
- /*
- Register definition, use only C-style comments (avr-as is stupid)
- */
- ; from R0-R15 only direct addressing
- #define zero R0
- #define ptr R1 /* pointer to sine table */
- ; from R16-R31 ldi possible
- #define acc R16 /* working register */
- #define calib R17 /* determine if needs calibration 0=yes */
- /*
- Interrupt Routines
- */
- ;* Addresses of interrupt routines is defined in io.h (for this processor)
- ;.global INT0_vect
- ;.global IO_PINS_vect
- ;.global TIMER1_COMP_vect
- ;.global TIMER1_OVF_vect
- ;.global TIMER0_OVF_vect
- ;.global EE_RDY_vect
- ;.global ANA_COMP_vect
- ;.global ADC_vect
- .text
- ;*
- ;* Interrupt 0
- ;*
- .global INT0_vect
- INT0_vect:
- reti
- ;*
- ;* Pin change interrupt
- ;*
- .global IO_PINS_vect
- IO_PINS_vect:
- reti
- ;*
- ;* Interrupt Timer 1 Overflow
- ;*
- .global TIMER1_OVF_vect
- TIMER1_OVF_vect:
- reti
- ;*
- ;* Interrupt Timer 1 Compare
- ;*
- .global TIMER1_COMP_vect
- TIMER1_COMP_vect:
- reti
- ;*
- ;* Interrupt Timer 0 Overflow
- ;*
- .global TIMER0_OVF_vect
- TIMER0_OVF_vect:
- reti
- ;*
- ;* EEPROM ready interrupt
- ;*
- .global EE_RDY_vect
- EE_RDY_vect:
- reti
- ;.global ANA_COMP_vect
- ;*
- ;* Analog Comparator Interrupt
- ;*
- .global ANA_COMP_vect
- ANA_COMP_vect:
- reti
- ;*
- ;* ADC Converter, End of Convertion
- ;*
- .global ADC_vect
- ADC_vect:
- reti
- ;*
- ;* Main routine
- ;*
- .global main
- main:
- ldi ZH, 0x03 ; Z -> End of Program memory (pmem)
- ldi ZL, 0xff
- lpm ; get calibration byte from pmem(0x3ff)
- out OSCCAL, R0 ; set calibration byte
- ; @factory calibrated clock speed
- osc_out:
- clr zero ; register zero is always zero
- ldi acc,0x02 ; PB1 must be programmed as output to work
- out DDRB,acc
- out OCR1A,zero ; clear output
- ; maximum frequency OCR1B=0;
- ; period is OCR1B+1 * tclk
- ldi acc,0xff ; maximum length of PWM (for this clock)
- out OCR1B,acc
- ldi acc, 0x64 ; PWM1,COM1A1,CS12 CK->T1 (f=12.5Khz)
- out TCCR1,acc
- clr ptr ; pointer to first position
- loop:
- out EEAR,ptr ; set pointer to eeprom
- sbi EECR,EERE ; set read
- in acc,EEDR
- out OCR1A,acc ; OCR1A:= eeprom(ptr)
- inc ptr ; ignore extra bits
- wait:
- in acc,TIFR ; input Timer Flag register
- andi acc,0x40 ; test OC1FA
- breq wait ; wait for a valid compare
- ldi acc,0x40
- out TIFR,acc ; software clear of the flag
- rjmp loop
- rjmp loop ; wait for reset
- .section .eeprom
- .org 0x00 ; dummy space, no eeprom used
- .end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement