📄 notch_60.lst
字号:
MPC "C" COMPILER BC.193 22-Aug-1995 PAGE 1
/*****************************************************************************
* 60 Hertz Notch Filter
*
* Written for "Digital Signal Processing with the PIC16C74" Application Note.
*
* This example program use the filter() function to implement a 60Hz notch
* filter. T0 is used to generate a 1kHz sample clock. The program samples the
* input signal x(n) on A-D channel 1, calls the filter routine signal, and
* outputs y(n) to PWM channel 1.
*
* If FILTER set to 0, performs straight talkthru from A-D to PWM output.
* T0 period can be changed to cary the sample rate.
*
* D. Mostowfi 4/95
******************************************************************************/
#include <16c74.h> /* c74 header file */
#pragma option +l;
0FFB #define MAXROM 4091
0005 0FFB #pragma memory ROM [MAXROM] @ 0x05;
0020 0060 #pragma memory RAM [0x60] @ 0x20;
00A0 0060 #pragma memory RAM [0x60] @ 0xA0;
#pragma option +l;
#include "analogio.c" /* analog I/O module */
/****************************************************************************
* Analog I/O Module
*
* Written for "Digital Signal Processing with the PIC16C74" Application Note
*
* This module contains functions that read the A-D inputs, initialize the PWM
* ports, and write values to the PWM ports.
*
* D. Mostowfi 4/95
****************************************************************************/
0001 #define active 1 /* define active as 1 */
0000 #define LOW 0 /* define LOW as 0 */
0001 #define HIGH 1 /* define HIGH as 1 */
0000 #define OFFSET 0 /* define offset binary mode as 0 */
0001 #define TWOS 1 /* define two's compliment mode as 1 */
0001 #define AD_FORMAT TWOS /* define A-D format as TWOS */
0001 #define PWM_FORMAT TWOS /* define PWM format as TWOS */
0001 #define PWM_RES HIGH /* define PWM resolution as HIGH */
0025 bits FLAGS; /* general purpose flags */
0001 #define sample_flag FLAGS.1 /* define sample_flag as FLAGS.1 */
/*****************************************************************************
* A-D Converter Routine - reads A-D converter inputs
*
* usage:
* - call get_sample(channel #)
MPC "C" COMPILER BC.193 22-Aug-1995 PAGE 2
* - returns 8 bit value
*****************************************************************************/
char get_sample(char channel)
0026 {
0005 1283 BCF STATUS,RP0
0006 00A6 MOVWF 26
0027 char i;
0007 019E CLRF ADRES ADRES=0; /* clear ADRES */
0008 1003 BCF STATUS,C STATUS.C=0; /* clear carry */
0009 0DA6 RLF 26 RLCF(channel); /* and rotate channel 3 times */
000A 0DA6 RLF 26 RLCF(channel); /* to put in proper position */
000B 0DA6 RLF 26 RLCF(channel); /* for write to ADCON0 */
000C 0826 MOVF 26,W ADCON0=channel; /* write channel to ADCON0 */
000D 009F MOVWF ADCON0
000E 141F BSF ADCON0,0 ADCON0.0=1; /* turn on A-D */
000F 01A7 CLRF 27 i=0; /* set delay loop variable to 0 */
0010 1283 BCF STATUS,RP0 while(i++<=5){}; /* delay (to ensure min sampling time) */
0011 0827 MOVF 27,W
0012 0AA7 INCF 27
0013 00A1 MOVWF 21
0014 3005 MOVLW 05h
0015 0221 SUBWF 21,W
0016 1D03 BTFSS STATUS,Z
0017 1C03 BTFSS STATUS,C
0018 2810 GOTO 0010h
0019 1283 BCF STATUS,RP0 ADCON0.2=1; /* start conversion */
001A 151F BSF ADCON0,2
001B 1283 BCF STATUS,RP0 while(ADCON0.2){} /* wait for eoc */
001C 191F BTFSC ADCON0,2
001D 281B GOTO 001Bh
001E 1283 BCF STATUS,RP0 ADCON0.0=0; /* turn off a-d converter */
001F 101F BCF ADCON0,0
if(AD_FORMAT==TWOS){ /* if format is two's compliment */
0020 3080 MOVLW 80h ADRES.7=!ADRES.7; /* compliment MSB */
0021 069E XORWF ADRES
}
0022 1283 BCF STATUS,RP0 return ADRES; /* return value in a-d result reg */
0023 081E MOVF ADRES,W
0024 0008 RETURN
}
/******************************************************************************
* PWM Initialization Routine - sets up PR2, sets output to mid-point, and
* starts timer 2 with interrupts disabled.
*
* usage:
* - call init_PWM(PR2 register value)
******************************************************************************/
void init_PWM(char _pr2)
0028 {
0025 1283 BCF STATUS,RP0
0026 00A8 MOVWF 28
0027 1683 BSF STATUS,RP0 PR2=_pr2; /* reload value for 40khz PWM period */
MPC "C" COMPILER BC.193 22-Aug-1995 PAGE 3
0028 0092 MOVWF T2CON
0029 1283 BCF STATUS,RP0 CCP1CON.5=0; /* set CCPxCON = 0 for 50% output */
002A 1297 BCF CCP1CON,5
002B 1217 BCF CCP1CON,4 CCP1CON.4=0;
002C 129D BCF CCP2CON,5 CCP2CON.5=0;
002D 121D BCF CCP2CON,4 CCP2CON.4=0;
if(PWM_RES==HIGH){ /* if resolution is high, set CCPRxH=0 and */
002E 0196 CLRF CCPR1H CCPR1H=0x00; /* CCPRxL=0x20 for 50% PWM duty cycle */
002F 3020 MOVLW 20h CCPR1L=0x20;
0030 0095 MOVWF CCPR1L
0031 019C CLRF CCPR2H CCPR2H=0x00;
0032 009B MOVWF CCPR2L CCPR2L=0x20;
}
0033 2839 GOTO 0039h else{
0034 0196 CLRF CCPR1H CCPR1H=0x00; /* if resolution is low, set CCPRxH=0 and */
0035 3080 MOVLW 80h CCPR1L=0x80; /* CCPRxL=0x80 for 50% PWM duty cycle */
0036 0095 MOVWF CCPR1L
0037 019C CLRF CCPR2H CCPR2H=0x00;
0038 009B MOVWF CCPR2L CCPR2L=0x80;
}
0039 1512 BSF T2CON,2 T2CON.TMR2ON=1; /* start timer 2 */
003A 1683 BSF STATUS,RP0 PIE1.TMR2IE=0; /* and disable timer 2 interrupt */
003B 108C BCF PIR1,1
003C 0008 RETURN }
/*******************************************************************************
* PWM Output Routine - writes output values to PWM ports
*
* Both high resolution and low resolution modes write 8 bit values - use of
* high or low resolution depends on PWM output period.
*
* usage:
* - call write_PWM(channel 1 value, channel 2 value)
* if channel 2 value=0, PWM port 2 not written
*******************************************************************************/
void write_PWM(bits pwm_out1, bits pwm_out2)
0029 002A {
003D 1283 BCF STATUS,RP0
003E 00AA MOVWF 2A
003F 0804 MOVF FSR,W
0040 00A9 MOVWF 29
if(PWM_FORMAT==TWOS){ /* if format is two's compliment */
0041 3080 MOVLW 80h pwm_out1.7=!pwm_out1.7; /* compliment msb's */
0042 06A9 XORWF 29
0043 1FA9 BTFSS 29,7 pwm_out2.7=!pwm_out1.7;
0044 2847 GOTO 0047h
0045 13AA BCF 2A,7
0046 2849 GOTO 0049h
0047 1283 BCF STATUS,RP0
0048 17AA BSF 2A,7
}
if(PWM_RES==HIGH){ /* if resolution is high */
MPC "C" COMPILER BC.193 22-Aug-1995 PAGE 4
0049 1003 BCF STATUS,C STATUS.C=0; /* clear carry */
004A 1283 BCF STATUS,RP0 pwm_out1=RRCF(pwm_out1); /* rotate right and write two lsb's */
004B 0CA9 RRF 29
004C 1803 BTFSC STATUS,C CCP1CON.4=STATUS.C; /* to CCP1CON4 and CCP1CON5 */
004D 2850 GOTO 0050h
004E 1217 BCF CCP1CON,4
004F 2852 GOTO 0052h
0050 1283 BCF STATUS,RP0
0051 1617 BSF CCP1CON,4
0052 1003 BCF STATUS,C STATUS.C=0;
0053 1283 BCF STATUS,RP0 pwm_out1=RRCF(pwm_out1);
0054 0CA9 RRF 29
0055 1803 BTFSC STATUS,C CCP1CON.5=STATUS.C;
0056 2859 GOTO 0059h
0057 1297 BCF CCP1CON,5
0058 285B GOTO 005Bh
0059 1283 BCF STATUS,RP0
005A 1697 BSF CCP1CON,5
005B 1283 BCF STATUS,RP0 if(pwm_out2!=0){ /* if pwm_out2 not 0, do the same */
005C 08AA MOVF 2A
005D 1903 BTFSC STATUS,Z
005E 2871 GOTO 0071h
005F 1003 BCF STATUS,C STATUS.C=0; /* for channel 2 */
0060 1283 BCF STATUS,RP0 pwm_out2=RRCF(pwm_out2);
0061 0CAA RRF 2A
0062 1803 BTFSC STATUS,C CCP2CON.4=STATUS.C;
0063 2866 GOTO 0066h
0064 121D BCF CCP2CON,4
0065 2868 GOTO 0068h
0066 1283 BCF STATUS,RP0
0067 161D BSF CCP2CON,4
0068 1003 BCF STATUS,C STATUS.C=0;
0069 1283 BCF STATUS,RP0 pwm_out2=RRCF(pwm_out2);
006A 0CAA RRF 2A
006B 1803 BTFSC STATUS,C CCP2CON.5=STATUS.C;
006C 286F GOTO 006Fh
006D 129D BCF CCP2CON,5
006E 2871 GOTO 0071h
006F 1283 BCF STATUS,RP0
0070 169D BSF CCP2CON,5
}
}
0071 1283 BCF STATUS,RP0 CCPR1L=pwm_out1; /* write value to CCPR1L */
0072 0829 MOVF 29,W
0073 0095 MOVWF CCPR1L
0074 08AA MOVF 2A if(pwm_out2!=0){ /* if pwm_out2 not 0, do the same */
0075 1903 BTFSC STATUS,Z
0076 287A GOTO 007Ah
0077 1283 BCF STATUS,RP0 CCPR2L=pwm_out2; /* for CCPR2L */
0078 082A MOVF 2A,W
0079 009B MOVWF CCPR2L
}
007A 0008 RETURN } /* done */
#include "iir_filt.c" /* iir filter module */
/*****************************************************************************
MPC "C" COMPILER BC.193 22-Aug-1995 PAGE 5
* Second-Order IIR Filter Module
*
* Written for "Digital SIgnal Processing with the PIC16C74" Application Note.
*
* This routine implements an IIR filter using a second order difference
* eqauation of the form:
*
* y(n) = b0*x(n)+b1*x(n-1)+b2*x(n-2)+a1*y(n-1)+a2*y(n-2)
*
* D. Mostowfi 3/95
*****************************************************************************/
#include "dbl_math.c"
/******************************************************************************
* Double Precision Math Routines
*
* This module contains assembly language routines from "Math Routines for the
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -