?? tecfunctions.c
字號(hào):
/*********************************************************************
* File: TecFunctions.c *
* Description: Contains functions used in the TEC application. *
* DSP: TMS320F2812 *
* Author: David M. Alter *
* Function List: *
* void FirFilter(PID *x, int *a, int n) *
* void InitGptimer2(float32 timer_Hz) *
* void InitPwm(Uint16 period, Uint16 compare) *
* void PidCtrl1(PID* x) *
* History: *
* 11/05/02 - Original, based on DSP28 header files v0.58 (D. Alter)*
* Notes: none *
*********************************************************************/
/*********************************************************************
* THIS PROGRAM IS PROVIDED "AS IS". TI MAKES NO WARRANTIES OR *
* REPRESENTATIONS, EITHER EXPRESS, IMPLIED OR STATUTORY, *
* INCLUDING ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS *
* FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR *
* COMPLETENESS OF RESPONSES, RESULTS AND LACK OF NEGLIGENCE. *
* TI DISCLAIMS ANY WARRANTY OF TITLE, QUIET ENJOYMENT, QUIET *
* POSSESSION, AND NON-INFRINGEMENT OF ANY THIRD PARTY *
* INTELLECTUAL PROPERTY RIGHTS WITH REGARD TO THE PROGRAM OR *
* YOUR USE OF THE PROGRAM. *
* *
* IN NO EVENT SHALL TI BE LIABLE FOR ANY SPECIAL, INCIDENTAL, *
* CONSEQUENTIAL OR INDIRECT DAMAGES, HOWEVER CAUSED, ON ANY *
* THEORY OF LIABILITY AND WHETHER OR NOT TI HAS BEEN ADVISED *
* OF THE POSSIBILITY OF SUCH DAMAGES, ARISING IN ANY WAY OUT *
* OF THIS AGREEMENT, THE PROGRAM, OR YOUR USE OF THE PROGRAM. *
* EXCLUDED DAMAGES INCLUDE, BUT ARE NOT LIMITED TO, COST OF *
* REMOVAL OR REINSTALLATION, COMPUTER TIME, LABOR COSTS, LOSS *
* OF GOODWILL, LOSS OF PROFITS, LOSS OF SAVINGS, OR LOSS OF *
* USE OR INTERRUPTION OF BUSINESS. IN NO EVENT WILL TI'S *
* AGGREGATE LIABILITY UNDER THIS AGREEMENT OR ARISING OUT OF *
* YOUR USE OF THE PROGRAM EXCEED FIVE HUNDRED DOLLARS *
* (U.S.$500). *
* *
* Unless otherwise stated, the Program written and copyrighted *
* by Texas Instruments is distributed as "freeware". You may, *
* only under TI's copyright in the Program, use and modify the *
* Program without any charge or restriction. You may *
* distribute to third parties, provided that you transfer a *
* copy of this license to the third party and the third party *
* agrees to these terms by its first use of the Program. You *
* must reproduce the copyright notice and any other legend of *
* ownership on each copy or partial copy, of the Program. *
* *
* You acknowledge and agree that the Program contains *
* copyrighted material, trade secrets and other TI proprietary *
* information and is protected by copyright laws, *
* international copyright treaties, and trade secret laws, as *
* well as other intellectual property laws. To protect TI's *
* rights in the Program, you agree not to decompile, reverse *
* engineer, disassemble or otherwise translate any object code *
* versions of the Program to a human-readable form. You agree *
* that in no event will you alter, remove or destroy any *
* copyright notice included in the Program. TI reserves all *
* rights not specifically granted under this license. Except *
* as specifically provided herein, nothing in this agreement *
* shall be construed as conferring by implication, estoppel, *
* or otherwise, upon you, any license or other right under any *
* TI patents, copyrights or trade secrets. *
* *
* You may not use the Program in non-TI devices. *
*********************************************************************/
#include "DSP281x_Device.h"
/*********************************************************************
* Function: FirFilter() *
* Description: Implements an I1Q15 fixed-point FIR filter on a PID *
* structure. *
* DSP: TMS320F2812 *
* Author: David M. Alter *
* Include files: none *
* Function Prototype: void FirFilter(PID*, int*, int) *
* Useage: PidCtrl1(x, a, n); *
* Input Parameters: x = structure of type PID *
* a = array of coefficients *
* n = number of coefficients *
* Return Value: none *
* Notes: The filtering is done from last tap to first tap. This *
* allows more efficient delay chain updating. The user must make *
* sure the PID structure has at least as many delay chain entries *
* as there are coefficients. *
*********************************************************************/
void FirFilter(PID *x, int *a, int n)
{
/*** Local variables ***/
int32 temp32; // general purpose unsigned long32
int16 *p; // general purpose pointer to int16
Uint16 i; // general purpose unsigned int16
/*** Setup pointers ***/
p = &x->y + (n-1); // pointer setup to end of delay chain
a = a + (n-1); // point to the last coefficient
temp32 = 0; // initialize the sum
/*** Last tap has no delay chain update ***/
temp32 = temp32 + ( ((int32)*a--) * ((int32)*p--) );
/*** Do the rest of the taps with delay chain update ***/
for(i=n-1; i>0; i--)
{
temp32 = temp32 + ( ((int32)*a--) * ((int32)*p--) );
*(p+1) = *p; // update delay chain
}
/*** Convert final value to floating point and put into the PID structure ***/
x->yf = (3.0/0x3FFC0000L)*(float32)(temp32);
} //end FirFilter()
/*********************************************************************
* Function: InitGptimer2() *
* Description: Initializes GP Timer 2 to give periodic interrupt. *
* DSP: TMS320F2812 *
* Author: David M. Alter *
* Include files: none *
* Function Prototype: void InitGptimer2(Uint16) *
* Useage: InitGptimer2(period); *
* Input Parameters: Uint16 period = timer period (in counts) *
* Return Value: none *
* Notes: *
* 1) uses x/128 clock prescaler *
*********************************************************************/
void InitGptimer2(Uint16 period)
{
EvaRegs.T2CON.all = 0x0000; //disable timer
/*
SET1PR:1; // 0 Period register select
TECMPR:1; // 1 Timer compare enable
TCLD10:2; // 3:2 Timer copare register reload
TCLKS10:2; // 5:4 Clock source select
TENABLE:1; // 6 Timer enable
T2SWT1:1; // 7 Start GP timer 2 with GP timer 1's enable 1
TPS:3; // 10:8 Input clock prescaler
TMODE:2; // 12:11 Count mode selection
rsvd:1; // 13 reserved
FREE:1; // 14 Free emulation control
SOFT:1; // 15 Soft emulation control
*/
EvaRegs.T2CNT = 0x0000; //clear timer counter
EvaRegs.T2PR = period; //set timer period
EvaRegs.T2CMPR = 0x0006; //set compare for ADC trigger
EvaRegs.GPTCONA.all = (EvaRegs.GPTCONA.all | 0x0620) & 0x0FF3;
/* x = don't change
bit 15 0: reserved
bit 14 0: T2STAT, read-only
bit 13 0: T1STAT, read-only
bit 12 0: T2CTRIPE, 0=disable timer2 compare trip
bit 11 x: T1CTRIPE, 0=disable timer1 compare trip
bit 10-9 11: T2TOADC, 11 = timer2 compare flag starts ADC 比較中斷啟動(dòng)模式
bit 8-7 xx: T1TOADC
bit 6 x: TCOMPOE, 0 = Hi-z all timer compare outputs
bit 5 1: T2COMPOE, 0 = timer2 compare HI-z'd
bit 4 x: T1COMPOE, 0 = timer1 compare HI-z'd
bit 3-2 00: T2PIN, 00 = forced low
bit 1-0 xx: T1PIN
*/
EvaRegs.T2CON.all = 0xD782; //enable timer
/*
bit 15-14 11: 11=do not stop on emulator suspend
bit 13 0: reserved
bit 12-11 10: 10 = continuous-up count mode
bit 10-8 111: 111 = x/128 prescaler
bit 7 1: T2SWT1, 1 = use GPTimer1 TENABLE bit
bit 6 0: TENABLE, 1 = enable timer
bit 5-4 00: 00 = HSPCLK is clock source
bit 3-2 00: 00 = reload compare reg on underflow
bit 1 1: 1 = enable timer compare
bit 0 0: SELT1PR, 0 = use own period register
*/
} //end InitGptimer2()
void InitGptimer3(Uint16 period)
{
EvbRegs.T3CON.all = 0x0000; //disable timer
/*
SET1PR:1; // 0 Period register select
TECMPR:1; // 1 Timer compare enable
TCLD10:2; // 3:2 Timer copare register reload
TCLKS10:2; // 5:4 Clock source select
TENABLE:1; // 6 Timer enable
T2SWT1:1; // 7 Start GP timer 2 with GP timer 1's enable 1
TPS:3; // 10:8 Input clock prescaler
TMODE:2; // 12:11 Count mode selection
rsvd:1; // 13 reserved
FREE:1; // 14 Free emulation control
SOFT:1; // 15 Soft emulation control
*/
EvbRegs.T3CNT = 0x0000; //clear timer counter
EvbRegs.T3PR = period; //set timer period
EvbRegs.T3CMPR = 0x0006; //set compare for ADC trigger
EvbRegs.GPTCONB.all = (EvbRegs.GPTCONB.all | 0x0620) & 0x0FF3;
/* x = don't change
bit 15 0: reserved
bit 14 0: T2STAT, read-only
bit 13 0: T1STAT, read-only
bit 12 0: T2CTRIPE, 0=disable timer2 compare trip
bit 11 x: T1CTRIPE, 0=disable timer1 compare trip
bit 10-9 11: T2TOADC, 11 = timer2 compare flag starts ADC 比較中斷啟動(dòng)模式
bit 8-7 xx: T1TOADC
bit 6 x: TCOMPOE, 0 = Hi-z all timer compare outputs
bit 5 1: T2COMPOE, 0 = timer2 compare HI-z'd
bit 4 x: T1COMPOE, 0 = timer1 compare HI-z'd
bit 3-2 00: T2PIN, 00 = forced low
bit 1-0 xx: T1PIN
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -