; PROGRAM NAME : Switched Capacitor Sinewave generator ; FILE NAME : Sw_cap.asm ; SOFTWARE BY : SIMON BRAMBLE ; simon_bramble@maximhq.com ; DATE : 30th August 2001 ; DEVELOPMENT TIME 5 Grolsch ; PROCESSOR : AT90S2323 ; CLOCK SPEED : 10MHz external XTAL ; DESCRIPTION ; This code gives 2 clock outputs, CLK1 and CLK2. CLK1 clocks a switched capacitor filter. ; CLK2 = CLK1/100, which is the 3dB point of the filter, thus turning CLK2 into a sinewave ; With this, we can develop a digitally programmable sinewave oscillator. .device AT90S2323 ;*************************************************************************** ; PORT DEFINITIONS ;*************************************************************************** .equ SREG =$3f .equ SPL =$3d .equ GIMSK =$3b .equ GIFR =$3a .equ TIMSK =$39 .equ TIFR =$38 .equ MCUCR =$35 .equ MCUSR =$34 .equ TCCR0 =$33 .equ TCNT0 =$32 .equ WDTCR =$21 .equ EEAR =$1e .equ EEARL =$1e .equ EEDR =$1d .equ EECR =$1c .equ PORTB =$18 .equ DDRB =$17 .equ PINB =$16 .equ RAMEND =$DF ;Last On-Chip SRAM Location .equ XRAMEND =$DF .equ E2END =$7F .equ FLASHEND=$3FF ;*************************************************************************** ; REGISTER DEFINITIONS ;*************************************************************************** .def junk =r16 ; junk register .def junk1 =r17 ; another junk reg (!) .def count =r18 ;*************************************************************************** ; MAIN CODE ;*************************************************************************** .cseg .org 0 rjmp reset ; executed on RESET .org 2 rjmp Int_T0 ; executed on Timer 0 overflow start: ldi junk, 0xD6 ; preload counter with 206d out TCNT0, junk ; to give overflow after 5us count_loop: cpi count, 0x64 ; count to 100 brne count_loop ldi junk1, 0b00000001 in junk, PORTB ; read in Port B eor junk, junk1 out PORTB, junk ; flip bit 0 (CLK2 output) clr count rjmp start ;*************************************************************************** ; SUBROUTINES ;*************************************************************************** ;********************** MICRO INITIALISATION ROUTINE *********************** reset: ; port definitions and reset ; initialise Stack: ldi junk, low(RAMEND) ; out SPL, junk ; define top of Stack ; initialise Timer 0 ldi junk, 0b00000000 ; stop counter out TCCR0, junk ; initialise ports: ser junk out DDRB,junk ; set all ports to outputs clr junk out PORTB, junk ; clear outputs ; initialise Interrupts: ldi junk, 0b10000000 ; enable Timer 0 out SREG, junk ; set Global Interrupt bit ldi junk, 0b00000010 out TIMSK, junk ; overflow Interrupt clr count ldi junk, 0b00000001 ; Start Counter, Prescaler = 1 out TCCR0, junk rjmp start ;*************** TIMER/COUNTER OVERFLOW INTERRUPT ROUTINE **************** Int_T0: ; arrive here on Interrupt ldi junk, 0xD6 ; reset clock out TCNT0, junk ; to give overflow after 5us ldi junk1, 0b00000010 in junk, PORTB ; read in Port B eor junk, junk1 out PORTB, junk ; flip bit 1 (CLK1 output) inc count reti ;*************************************************************************** end: rjmp end ;*************************************************************************** ; END OF FILE ;***************************************************************************