Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;******************************************************************************
- ; *
- ; Author : Nicholas Hooper *
- ; Assignment : Final *
- ; Filename : pwm_music.s *
- ; Date : 04/27/2019 *
- ; File Version : 2.0 *
- ; *
- ; Other Files Required: p30F6010.gld, p30f6010.inc *
- ; Tools Used:MPLAB GL : 7.01 *
- ; Compiler : 1.30 *
- ; Assembler: 1.30 *
- ; Linker : 1.30 *
- ; * *
- ;******************************************************************************
- .equ __24FJ64GB002, 1
- .include "p24FJ64GB002.inc"
- ;..............................................................................
- ;Configuration bits:
- ;..............................................................................
- config __CONFIG4,(DSWDTPS_DSWDTPS3 & I2C1SEL_PRI & DSWDTOSC_LPRC & RTCOSC_SOSC & DSBOREN_OFF & DSWDTEN_OFF) ; DSWDT Postscale Select->1:2,147,483,648 (25.7 days);
- config __CONFIG3,(WPFP_WPFP0 & WUTSEL_LEG & WPDIS_WPDIS & WPCFG_WPCFGDIS & WPEND_WPENDMEM & SOSCSEL_IO) ; enable RA4 and RB4 (#define SOSCSEL_EC 0xFCFF)
- config __CONFIG2,(POSCMOD_NONE & I2C1SEL_PRI & IOL1WAY_OFF & OSCIOFNC_ON & FCKSM_CSECMD & FNOSC_FRCPLL & PLL96MHZ_ON & PLLDIV_NODIV & IESO_OFF) ; was FCKSM_CSDCMD now FCKSM_CSECMD was OSCIOFNC_OFF was FNOSC_FRC and PLL96MHZ_OFF LDC 8/29/18, 9/18/18
- config __CONFIG1,(WDTPS_PS1 & FWPSA_PR128 & WINDIS_OFF & FWDTEN_OFF & ICS_PGx1 & GWRP_OFF & GCP_OFF & JTAGEN_OFF) ;Code Protect Off, Program pin 4,5
- ;..............................................................................
- ;Program Specific Constants (literals used in code)
- ;..............................................................................
- .equ SAMPLES, 64 ;Number of samples
- ;..............................................................................
- ;Global Declarations:
- ;..............................................................................
- .global _wreg_init ;Provide global scope to _wreg_init routine
- ;In order to call this routine from a C file,
- ;place "wreg_init" in an "extern" declaration
- ;in the C file.
- .global __reset ;The label for the first line of code.
- .global __T1Interrupt ;Declare Timer 1 ISR name global
- ;..............................................................................
- ;Constants stored in Program space
- ;..............................................................................
- .section .myconstbuffer, code
- .palign 2 ;Align next word stored in Program space to an
- ;address that is a multiple of 2
- ps_coeff:
- .hword 0x0002, 0x0003, 0x0005, 0x000A
- ;..............................................................................
- ;Uninitialized variables in Near data memory (Lower 8Kb of RAM)
- ;..............................................................................
- .section .nbss, bss, near
- var1: .space 2
- count: .space 2
- counter: .space 2
- setinal: .space 2
- TABaddr: .space 2
- temp: .space 2
- portb: .space 2
- ;..............................................................................
- ;Code Section in Program Memory
- ;..............................................................................
- .text ;Start of Code section
- Tune: .word 0X8DE0,0X0,0X1,0X0,0X1,0X0,0X1,0X0,0X1,0X0,0X1,0X0,0X1,0X0,0X1,0X0,0X1,0X0,0X1,0X0,0X1,0X0,0X8DE0,0X0,0X8DE0,0X0,0X8DE0,0X0,0X1,0X0,0X8DE0,0X0,0X8DE0,0X0,0X1,0X0,0X1,0X0,0X9F60,0X0,0X8DE0,0X0,0X1,0X0,0X1,0X0,0X1,0X0,0X1,0X0,0X1,0X0,0X1,0X0,0X8DE0,0X0,0X8DE0,0X0,0X8DE0,0X0,0X1,0X0,0X8DE0,0X0,0X8DE0,0X0,0X1,0X0,0X1,0X0,0X9F60,0X0,0X8DE0,0X0,0X1,0X0,0X1,0X0,0X1,0X0,0X1,0X0,0X1,0X0,0X1,0X0,0X8DE0,0X0,0X8DE0,0X0,0X8DE0,0X0,0X1,0X0,0X8DE0,0X0,0X8DE0,0X0,0X1,0X0,0XBD50,0X0,0XBD50,0X0,0XBD50,0X0,0X1,0X0,0XBD50,0X0,0XBD50,0X0,0XBD50,0X0,0X1,0X0,0XBD50,0X0,0XBD50,0X0,0XBD50,0X0,0X1,0X0,0XBD50,0X0,0X1,0X0,0X8DE0,0X0,0X1,0X0,0X1,0X0,0X1,0X0,0XBD50,0X0,0X1,0X0,0X1,0X0,0X1,0X0,0X1,0X0,0X1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X0,0X1,0X0,
- __reset:
- MOV #__SP_init, W15 ;Initalize the Stack Pointer
- MOV #__SPLIM_init, W0 ;Initialize the Stack Pointer Limit Register
- MOV W0, SPLIM
- NOP ;Add NOP to follow SPLIM initialization
- CALL _wreg_init ;Call _wreg_init subroutine
- ;Optionally use RCALL instead of CALL
- /*
- To configure the output compare module for PWM operation:
- 1. Configure the OCx output for one of the available Peripheral Pin Select pins.
- 2. Calculate the desired duty cycles and load them into the OCxR register.
- 3. Calculate the desired period and load it into the OCxRS register.
- 4. Select the current OCx as the sync source by writing 0x1F to SYNCSEL<4:0>
- (OCxCON2<4:0>), and clearing OCTRIG (OCxCON2<7>).
- 5. Select a clock source by writing the OCTSEL<2:0> (OCxCON<12:10>) bits.
- 6. Enable interrupts, if required, for the timer and output compare modules. The
- output compare interrupt is required for PWM Fault pin utilization.
- 7. Select the desired PWM mode in the OCM<2:0> (OCxCON1<2:0>) bits.
- 8. If a timer is selected as a clock source, set the TMRy prescale value and enable
- the time base by setting the TON (TxCON<15>) bit.
- */
- ;<<insert more user code here>>
- ;House keeping
- clr TRISB
- ; setup pwm
- BCLR OSCCONL,#6
- MOV #0x0012,w1
- MOV w1,RPOR5
- BSET OSCCONL,#6
- clr T2CON
- bset T2CON,#TON ; Turn on timer 2
- mov #0x0060,w0 ; stuff with a hex 60
- mov w0,OC1R
- mov #0x0006,w0
- mov w0,OC1CON1 ; edge-aligned pwm mode on ocx
- mov #0xFFFF,w0
- mov w0,PR2 ; stuff period register with a hex 7F
- mov #0x8020,W0 ; turn on timer 1 and loaded prescalar with 256
- mov w0,T1CON
- mov #16000,w0 ; 5ms between pwm
- mov w0,PR1
- bset IEC0,#T1IE
- bclr setinal,#0
- mov #tblpage(Tune),w0
- mov w0,_TBLPAG
- clr counter
- clr count
- start:
- btss setinal,#0
- goto start
- mov #tbloffset(Tune),w0
- add TABaddr,wreg
- TBLRDL [w0++],w0
- mov #0xFFFF,w1 ; mask off bit 15
- and w0,w1,w0
- mov w0,temp
- mov w0,PR2
- lsr temp
- mov temp,w0
- mov w0,OC1R
- bclr setinal,#0
- mov #2,w0
- add TABaddr
- inc counter
- mov counter,w3
- sub #1023,w3;1092
- BRA Z,skip2
- goto start
- skip2:
- clr counter
- clr TABaddr
- goto start
- ;..............................................................................
- ;Subroutine: Initialization of W registers to 0x0000
- ;..............................................................................
- _wreg_init:
- CLR W0
- MOV W0, W14
- REPEAT #12
- MOV W0, [++W14]
- CLR W14
- RETURN
- ;..............................................................................
- ;Timer 1 Interrupt Service Routine
- ;Example context save/restore in the ISR performed using PUSH.D/POP.D
- ;instruction. The instruction pushes two words W4 and W5 on to the stack on
- ;entry into ISR and pops the two words back into W4 and W5 on exit from the ISR
- ;..............................................................................
- __T1Interrupt:
- PUSH w0 ;Save context using double-word PUSH
- nop ; used for debugging with the simulator
- INC count
- mov count,w3
- sub #1,w3
- BRA NZ,isr_skip
- clr count
- bset setinal,#0
- isr_skip:
- BCLR IFS0, #T1IF ;Clear the Timer1 Interrupt flag Status
- POP w0 ;Retrieve context POP-ping from Stack
- RETFIE ;Return from Interrupt Service routine
- ;--------End of All Code Sections ---------------------------------------------
- .end ;End of program code in this file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement