init commit.
Проект каким он достался от Димы.
This commit is contained in:
178
v120/DSP2833x_examples/eqep_freqcal/Example_2833xEqep_freqcal.c
Normal file
178
v120/DSP2833x_examples/eqep_freqcal/Example_2833xEqep_freqcal.c
Normal file
@@ -0,0 +1,178 @@
|
||||
// TI File $Revision: /main/12 $
|
||||
// Checkin $Date: July 10, 2008 11:07:26 $
|
||||
//###########################################################################
|
||||
//
|
||||
// FILE: Example_2833xEqep_freqcal.c
|
||||
//
|
||||
// TITLE: Frequency measurement using EQEP peripheral
|
||||
//
|
||||
// ASSUMPTIONS:
|
||||
//
|
||||
// This program requires the DSP2833x header files.
|
||||
// As supplied, this project is configured for "boot to SARAM" operation.
|
||||
//
|
||||
// Test requires the following hardware connections
|
||||
//
|
||||
// GPIO20/EQEP1A <- External input - connect to GPIO0/EPWM1A
|
||||
//
|
||||
// As supplied, this project is configured for "boot to SARAM"
|
||||
// operation. The 2833x Boot Mode table is shown below.
|
||||
// For information on configuring the boot mode of an eZdsp,
|
||||
// please refer to the documentation included with the eZdsp,
|
||||
//
|
||||
// $Boot_Table:
|
||||
//
|
||||
// GPIO87 GPIO86 GPIO85 GPIO84
|
||||
// XA15 XA14 XA13 XA12
|
||||
// PU PU PU PU
|
||||
// ==========================================
|
||||
// 1 1 1 1 Jump to Flash
|
||||
// 1 1 1 0 SCI-A boot
|
||||
// 1 1 0 1 SPI-A boot
|
||||
// 1 1 0 0 I2C-A boot
|
||||
// 1 0 1 1 eCAN-A boot
|
||||
// 1 0 1 0 McBSP-A boot
|
||||
// 1 0 0 1 Jump to XINTF x16
|
||||
// 1 0 0 0 Jump to XINTF x32
|
||||
// 0 1 1 1 Jump to OTP
|
||||
// 0 1 1 0 Parallel GPIO I/O boot
|
||||
// 0 1 0 1 Parallel XINTF boot
|
||||
// 0 1 0 0 Jump to SARAM <- "boot to SARAM"
|
||||
// 0 0 1 1 Branch to check boot mode
|
||||
// 0 0 1 0 Boot to flash, bypass ADC cal
|
||||
// 0 0 0 1 Boot to SARAM, bypass ADC cal
|
||||
// 0 0 0 0 Boot to SCI-A, bypass ADC cal
|
||||
// Boot_Table_End$
|
||||
//
|
||||
// DESCRIPTION:
|
||||
//
|
||||
// This test will provide frequency measurement using capture unit (freqhz_pr)
|
||||
// and unit time out (freqhz_fr). The EPWM1A frequency will be measured by the EQEP.
|
||||
//
|
||||
// By default, EPWM1A is configured to generate a frequency of 5 kHz - measured
|
||||
// frequency found in freqhz_pr and freqhz_fr should be 5000.
|
||||
//
|
||||
// See DESCRIPTION in Example_freqcal.c for more details on the frequency calculation
|
||||
// performed in this example.
|
||||
//
|
||||
// In addition to this file, the following files must be included in this project:
|
||||
// Example_freqcal.c - includes all eQEP functions
|
||||
// Example_EPwmSetup.c - sets up EPWM1A for use with this example
|
||||
// Example_freqcalh - includes initialization values for frequency structure.
|
||||
//
|
||||
// * Maximum frequency is configured to 10Khz (BaseFreq)
|
||||
// * Minimum frequency is assumed at 50Hz for capture pre-scalar selection
|
||||
//
|
||||
// SPEED_FR: High Frequency Measurement is obtained by counting the external input pulses
|
||||
// for 10ms (unit timer set to 100Hz).
|
||||
//
|
||||
// SPEED_FR = { (Count Delta)/10ms }
|
||||
//
|
||||
//
|
||||
// SPEED_PR: Low Frequency Measurement is obtained by measuring time period of input edges.
|
||||
// Time measurement is averaged over 64edges for better results and
|
||||
// capture unit performs the time measurement using pre-scaled SYSCLK
|
||||
//
|
||||
// Note that pre-scaler for capture unit clock is selected such that
|
||||
// capture timer does not overflow at the required minimum frequency
|
||||
//
|
||||
// This example runs forever until the user stops it.
|
||||
//
|
||||
//
|
||||
// Watch Variables: freq.freqhz_fr - Frequency measurement using position counter/unit time out
|
||||
// freq.freqhz_pr - Frequency measurement using capture unit
|
||||
//
|
||||
//###########################################################################
|
||||
// Original Author: SD
|
||||
//
|
||||
// $TI Release: DSP2833x/DSP2823x Header Files V1.20 $
|
||||
// $Release Date: August 1, 2008 $
|
||||
//###########################################################################
|
||||
|
||||
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
|
||||
#include "Example_freqcal.h" // Example specific include file
|
||||
|
||||
void EPwmSetup(void);
|
||||
interrupt void prdTick(void);
|
||||
|
||||
FREQCAL freq=FREQCAL_DEFAULTS;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
|
||||
// Step 1. Initialize System Control:
|
||||
// PLL, WatchDog, enable Peripheral Clocks
|
||||
// This example function is found in the DSP2833x_SysCtrl.c file.
|
||||
InitSysCtrl();
|
||||
|
||||
// Step 2. Initalize GPIO:
|
||||
// This example function is found in the DSP2833x_Gpio.c file and
|
||||
// illustrates how to set the GPIO to it's default state.
|
||||
// InitGpio(); // Skipped for this example
|
||||
|
||||
// Only init the GPIO for EQep1 and EPwm1 in this case
|
||||
// This function is found in DSP2833x_EQep.c
|
||||
InitEQep1Gpio();
|
||||
InitEPwm1Gpio();
|
||||
|
||||
// Step 3. Clear all interrupts and initialize PIE vector table:
|
||||
// Disable CPU interrupts
|
||||
DINT;
|
||||
|
||||
// Initialize the PIE control registers to their default state.
|
||||
// The default state is all PIE interrupts disabled and flags
|
||||
// are cleared.
|
||||
// This function is found in the DSP2833x_PieCtrl.c file.
|
||||
InitPieCtrl();
|
||||
|
||||
// Disable CPU interrupts and clear all CPU interrupt flags:
|
||||
IER = 0x0000;
|
||||
IFR = 0x0000;
|
||||
|
||||
// Initialize the PIE vector table with pointers to the shell Interrupt
|
||||
// Service Routines (ISR).
|
||||
// This will populate the entire table, even if the interrupt
|
||||
// is not used in this example. This is useful for debug purposes.
|
||||
// The shell ISR routines are found in DSP2833x_DefaultIsr.c.
|
||||
// This function is found in DSP2833x_PieVect.c.
|
||||
InitPieVectTable();
|
||||
|
||||
// Interrupts that are used in this example are re-mapped to
|
||||
// ISR functions found within this file.
|
||||
EALLOW; // This is needed to write to EALLOW protected registers
|
||||
PieVectTable.EPWM1_INT= &prdTick;
|
||||
EDIS; // This is needed to disable write to EALLOW protected registers
|
||||
|
||||
// Step 4. Initialize all the Device Peripherals:
|
||||
// Example specific ePWM setup. This function is found
|
||||
// in Example_EPwmSetup.c
|
||||
EPwmSetup();
|
||||
|
||||
// Step 5. User specific code, enable interrupts:
|
||||
// Enable CPU INT1 which is connected to CPU-Timer 0:
|
||||
IER |= M_INT3;
|
||||
|
||||
// Enable TINT0 in the PIE: Group 3 interrupt 1
|
||||
PieCtrlRegs.PIEIER3.bit.INTx1 = 1;
|
||||
|
||||
// Enable global Interrupts and higher priority real-time debug events:
|
||||
EINT; // Enable Global interrupt INTM
|
||||
ERTM; // Enable Global realtime interrupt DBGM
|
||||
|
||||
freq.init(&freq); // Initializes eQEP for frequency calculation in
|
||||
// FREQCAL_Init(void)function in Example_EPwmSetup.c
|
||||
for(;;)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
interrupt void prdTick(void) // Interrupts once per ePWM period
|
||||
{
|
||||
freq.calc(&freq); // Checks for event and calculates frequency in FREQCAL_Calc(FREQCAL *p)
|
||||
// function in Example_EPwmSetup.c
|
||||
// Acknowledge this interrupt to receive more interrupts from group 1
|
||||
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
|
||||
EPwm1Regs.ETCLR.bit.INT=1;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
// TI File $Revision: /main/6 $
|
||||
// Checkin $Date: August 9, 2007 17:14:43 $
|
||||
//###########################################################################
|
||||
//
|
||||
// This .gel file can be used to help load and build the example project.
|
||||
// It should be unloaded from Code Composer Studio before loading another
|
||||
// projectn.
|
||||
//
|
||||
//###########################################################################
|
||||
// $TI Release: DSP2833x/DSP2823x Header Files V1.20 $
|
||||
// $Release Date: August 1, 2008 $
|
||||
//###########################################################################
|
||||
*/
|
||||
|
||||
menuitem "DSP2833x eQEP Frequency Calc"
|
||||
|
||||
hotmenu Load_and_Build_Project()
|
||||
{
|
||||
GEL_ProjectLoad("Example_2833xEqep_freqcal.pjt");
|
||||
GEL_ProjectBuild("Example_2833xEqep_freqcal.pjt");
|
||||
Setup_WatchWindow();
|
||||
}
|
||||
|
||||
hotmenu Load_Code()
|
||||
{
|
||||
GEL_Load(".\\debug\\Example_2833xEqep_freqcal.out");
|
||||
Setup_WatchWindow();
|
||||
}
|
||||
|
||||
hotmenu Setup_WatchWindow()
|
||||
{
|
||||
GEL_WatchReset();
|
||||
GEL_WatchAdd("freq.freqhz_fr",,"");
|
||||
GEL_WatchAdd("freq.freqhz_pr",,"");
|
||||
GEL_WatchAdd("EQep1Regs,x");
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
; Code Composer Project File, Version 2.0 (do not modify or remove this line)
|
||||
|
||||
[Project Settings]
|
||||
ProjectName="DSP2833x"
|
||||
ProjectDir="C:\tidcs\c28\DSP2833x\v120\DSP2833x_examples\eqep_freqcal\"
|
||||
ProjectType=Executable
|
||||
CPUFamily=TMS320C28XX
|
||||
Tool="Compiler"
|
||||
Tool="CustomBuilder"
|
||||
Tool="DspBiosBuilder"
|
||||
Tool="Linker"
|
||||
Config="Debug"
|
||||
Config="Release"
|
||||
|
||||
[Source Files]
|
||||
Source="..\..\DSP2833x_common\source\DSP2833x_ADC_cal.asm"
|
||||
Source="..\..\DSP2833x_common\source\DSP2833x_CodeStartBranch.asm"
|
||||
Source="..\..\DSP2833x_common\source\DSP2833x_DefaultIsr.c"
|
||||
Source="..\..\DSP2833x_common\source\DSP2833x_EPwm.c"
|
||||
Source="..\..\DSP2833x_common\source\DSP2833x_EQep.c"
|
||||
Source="..\..\DSP2833x_common\source\DSP2833x_PieCtrl.c"
|
||||
Source="..\..\DSP2833x_common\source\DSP2833x_PieVect.c"
|
||||
Source="..\..\DSP2833x_common\source\DSP2833x_SysCtrl.c"
|
||||
Source="..\..\DSP2833x_common\source\DSP2833x_usDelay.asm"
|
||||
Source="..\..\DSP2833x_headers\source\DSP2833x_GlobalVariableDefs.c"
|
||||
Source="..\..\DSP2833x_common\lib\IQmath_fpu32.lib"
|
||||
Source="Example_2833xEqep_freqcal.c"
|
||||
Source="Example_EPwmSetup.c"
|
||||
Source="Example_freqcal.c"
|
||||
Source="..\..\DSP2833x_common\cmd\28335_RAM_lnk.cmd"
|
||||
Source="..\..\DSP2833x_headers\cmd\DSP2833x_Headers_nonBIOS.cmd"
|
||||
|
||||
["Compiler" Settings: "Debug"]
|
||||
Options=-g -q -pdr -fr"C:\tidcs\c28\DSP2833x\v120\DSP2833x_examples\eqep_freqcal\Debug" -fs"C:\tidcs\c28\DSP2833x\v120\DSP2833x_examples\eqep_freqcal\Debug" -i".." -i"..\..\DSP2833x_headers\include" -i"..\..\DSP2833x_common\include" -i"..\..\DSP2833x_common\lib" -d"_DEBUG" -d"LARGE_MODEL" -ml -mt -v28 --float_support=fpu32
|
||||
|
||||
["Compiler" Settings: "Release"]
|
||||
Options=-q -o3 -fr"C:\tidcs\c28\DSP2833x\v120\DSP2833x_examples\eqep_freqcal\Release" -d"LARGE_MODEL" -ml -v28
|
||||
|
||||
["DspBiosBuilder" Settings: "Debug"]
|
||||
Options=-v28
|
||||
|
||||
["DspBiosBuilder" Settings: "Release"]
|
||||
Options=-v28
|
||||
|
||||
["Linker" Settings: "Debug"]
|
||||
Options=-q -c -ecode_start -m".\Debug\Example_2833xEqep_freqcal.map" -o".\Debug\Example_2833xEqep_freqcal.out" -stack0x380 -w -x -i"..\..\DSP2833x_headers\include" -l"rts2800_fpu32.lib"
|
||||
|
||||
["Linker" Settings: "Release"]
|
||||
Options=-q -c -o".\Release\Example_2833xEqep_freqcal.out" -x
|
||||
76
v120/DSP2833x_examples/eqep_freqcal/Example_EPwmSetup.c
Normal file
76
v120/DSP2833x_examples/eqep_freqcal/Example_EPwmSetup.c
Normal file
@@ -0,0 +1,76 @@
|
||||
// TI File $Revision: /main/10 $
|
||||
// Checkin $Date: April 21, 2008 15:42:03 $
|
||||
//###########################################################################
|
||||
//
|
||||
// FILE: Example_EpwmSetup.c
|
||||
//
|
||||
// TITLE: Frequency measurement using EQEP peripheral
|
||||
//
|
||||
// DESCRIPTION:
|
||||
//
|
||||
// This file contains source for the ePWM initialization for the
|
||||
// freq calculation module
|
||||
//
|
||||
//###########################################################################
|
||||
// Original Author: SD
|
||||
//
|
||||
// $TI Release: DSP2833x/DSP2823x Header Files V1.20 $
|
||||
// $Release Date: August 1, 2008 $
|
||||
//###########################################################################
|
||||
|
||||
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
|
||||
#include "Example_freqcal.h" // Example specific include file
|
||||
|
||||
#if (CPU_FRQ_150MHZ)
|
||||
#define CPU_CLK 150e6
|
||||
#endif
|
||||
#if (CPU_FRQ_100MHZ)
|
||||
#define CPU_CLK 100e6
|
||||
#endif
|
||||
#define PWM_CLK 5e3 // If diff freq. desired, change freq here.
|
||||
#define SP CPU_CLK/(2*PWM_CLK)
|
||||
#define TBCTLVAL 0x200E // Up-down cnt, timebase = SYSCLKOUT
|
||||
|
||||
|
||||
void EPwmSetup()
|
||||
{
|
||||
InitEPwm1Gpio();
|
||||
EPwm1Regs.TBSTS.all=0;
|
||||
EPwm1Regs.TBPHS.half.TBPHS=0;
|
||||
EPwm1Regs.TBCTR=0;
|
||||
|
||||
EPwm1Regs.CMPCTL.all=0x50; // Immediate mode for CMPA and CMPB
|
||||
EPwm1Regs.CMPA.half.CMPA =SP/2;
|
||||
EPwm1Regs.CMPB=0;
|
||||
|
||||
EPwm1Regs.AQCTLA.all=0x60; // EPWMxA = 1 when CTR=CMPA and counter inc
|
||||
// EPWMxA = 0 when CTR=CMPA and counter dec
|
||||
EPwm1Regs.AQCTLB.all=0;
|
||||
EPwm1Regs.AQSFRC.all=0;
|
||||
EPwm1Regs.AQCSFRC.all=0;
|
||||
|
||||
EPwm1Regs.DBCTL.all=0xb; // EPWMxB is inverted
|
||||
EPwm1Regs.DBRED=0;
|
||||
EPwm1Regs.DBFED=0;
|
||||
|
||||
EPwm1Regs.TZSEL.all=0;
|
||||
EPwm1Regs.TZCTL.all=0;
|
||||
EPwm1Regs.TZEINT.all=0;
|
||||
EPwm1Regs.TZFLG.all=0;
|
||||
EPwm1Regs.TZCLR.all=0;
|
||||
EPwm1Regs.TZFRC.all=0;
|
||||
|
||||
EPwm1Regs.ETSEL.all=9; // Interrupt when TBCTR = 0x0000
|
||||
EPwm1Regs.ETPS.all=1; // Interrupt on first event
|
||||
EPwm1Regs.ETFLG.all=0;
|
||||
EPwm1Regs.ETCLR.all=0;
|
||||
EPwm1Regs.ETFRC.all=0;
|
||||
|
||||
EPwm1Regs.PCCTL.all=0;
|
||||
|
||||
EPwm1Regs.TBCTL.all=0x0010+TBCTLVAL; // Enable Timer
|
||||
EPwm1Regs.TBPRD=SP;
|
||||
|
||||
}
|
||||
|
||||
|
||||
186
v120/DSP2833x_examples/eqep_freqcal/Example_freqcal.c
Normal file
186
v120/DSP2833x_examples/eqep_freqcal/Example_freqcal.c
Normal file
@@ -0,0 +1,186 @@
|
||||
// TI File $Revision: /main/10 $
|
||||
// Checkin $Date: April 21, 2008 15:42:07 $
|
||||
//###########################################################################
|
||||
//
|
||||
// FILE: Example_freqcal.c
|
||||
//
|
||||
// TITLE: Frequency measurement using EQEP peripheral
|
||||
//
|
||||
// DESCRIPTION:
|
||||
//
|
||||
// This file includes the EQEP initialization and frequency calcuation
|
||||
// functions called by Example_2833xEqep_freqcal.c. The frequency calculation
|
||||
// steps performed by FREQCAL_Calc()at SYSCLKOUT = 150 MHz and 100 MHz are
|
||||
// described below:
|
||||
//
|
||||
// For 150 MHz Operation:
|
||||
// ----------------------
|
||||
//
|
||||
// 1. This program calculates: **freqhz_fr**
|
||||
// freqhz_fr or v = (x2-x1)/T - Equation 1
|
||||
//
|
||||
// If max/base freq = 10kHz: 10kHz = (x2-x1)/(2/100Hz) - Equation 2
|
||||
// max (x2-x1) = 200 counts = freqScaler_fr
|
||||
// Note: T = 2/100Hz. 2 is from (x2-x1)/2 - because QPOSCNT counts 2 edges per cycle
|
||||
// (rising and falling)
|
||||
//
|
||||
// If both sides of Equation 2 are divided by 10 kHz, then:
|
||||
// 1 = (x2-x1)/[10kHz*(2/100Hz)] where [10kHz* (2/100Hz)] = 200
|
||||
// Because (x2-x1) must be <200 (max),
|
||||
// (x2-x1)/200 < 1 for all frequencies less than max
|
||||
// freq_fr = (x2-x1)/200 or (x2-x1)/[10kHz*(2/100Hz)] - Equation 3
|
||||
//
|
||||
// To get back to original velocity equation, Equation 1, multiply Equation 3 by 10 kHz
|
||||
// freqhz_fr (or velocity) = 10kHz*(x2-x1)/[10kHz*(2/100Hz)]
|
||||
// = (x2-x1)/(2/100Hz) - Final equation
|
||||
//
|
||||
// 2. min freq = 1 count/(2/100Hz) = 50 Hz
|
||||
//
|
||||
// 3. **freqhz_pr**
|
||||
// freqhz_pr or v = X/(t2-t1) - Equation 4
|
||||
//
|
||||
// If max/base freq = 10kHz: 10kHz = (4/2)/T = 4/2T
|
||||
// where 4 = QCAPCTL [UPPS] (Unit timeout - once every 4 edges)
|
||||
// 2 = divide by 2 because QPOSCNT counts 2 edges per cycle (rising and falling)
|
||||
// T = time in seconds
|
||||
// = t2-t1/(150MHz/128), t2-t1= # of QCAPCLK cycles, and
|
||||
// 1 QCAPCLK cycle = 1/(150MHz/128)
|
||||
// = QCPRDLAT
|
||||
//
|
||||
// So: 10 kHz = 4(150MHz/128)/2(t2-t1)
|
||||
// t2-t1 = 4(150MHz/128)/(10kHz*2) = (150MHz/128)/(2*10kHz/4) - Equation 5
|
||||
// = 234 QCAPCLK cycles = maximum (t2-t1) = freqScaler_pr
|
||||
//
|
||||
// Divide both sides by (t2-t1), and:
|
||||
// 1 = 234/(t2-t1) = [150MHz/128)/(2*10kHz/4)]/(t2-t1)
|
||||
// Because (t2-t1) must be <234 (max).
|
||||
// 234/(t2-t1) < 1 for all frequencies less than max
|
||||
// freq_pr = 234/(t2-t1) or [150MHz/128)/(2*10kHz/4)]/(t2-t1) - Equation 6
|
||||
// Now within velocity limits, to get back to original velocity equation, Equation 1,
|
||||
// multiply Equation 6 by 10 kHz:
|
||||
// freqhz_fr (or velocity) = 10kHz*[150MHz/128)/(2*10kHz/4)]/(t2-t1)
|
||||
// = (105MHz/128)*4/[2(t2-t1)]
|
||||
// or 4/[2*(t2-t1)(QCPRDLAT)] - Final Equation
|
||||
//
|
||||
//
|
||||
// For 100 MHz Operation:
|
||||
// ----------------------
|
||||
//
|
||||
// The same calculations as above are performed, but with 100 MHz
|
||||
// instead of 150MHz when calculating freqhz_pr, and at UPPS of 8 instead of 4.
|
||||
// The value for freqScaler_pr becomes: (100MHz/128)/(2*10kHz/8) = 313
|
||||
// More detailed calculation results can be found in the Example_freqcal.xls
|
||||
// spreadsheet included in the example folder.
|
||||
//
|
||||
//
|
||||
// This file contains source for the freq calculation module
|
||||
//
|
||||
//###########################################################################
|
||||
// Original Author: SD
|
||||
//
|
||||
// $TI Release: DSP2833x/DSP2823x Header Files V1.20 $
|
||||
// $Release Date: August 1, 2008 $
|
||||
//###########################################################################
|
||||
|
||||
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
|
||||
#include "Example_freqcal.h" // Example specific include file
|
||||
|
||||
void FREQCAL_Init(void)
|
||||
{
|
||||
#if (CPU_FRQ_150MHZ)
|
||||
EQep1Regs.QUPRD=1500000; // Unit Timer for 100Hz at 150MHz SYSCLKOUT
|
||||
#endif
|
||||
#if (CPU_FRQ_100MHZ)
|
||||
EQep1Regs.QUPRD=1000000; // Unit Timer for 100Hz at 100MHz SYSCLKOUT
|
||||
#endif
|
||||
|
||||
EQep1Regs.QDECCTL.bit.QSRC=2; // Up count mode (freq. measurement)
|
||||
EQep1Regs.QDECCTL.bit.XCR=0; // 2x resolution (cnt falling and rising edges)
|
||||
|
||||
EQep1Regs.QEPCTL.bit.FREE_SOFT=2;
|
||||
EQep1Regs.QEPCTL.bit.PCRM=00; // QPOSCNT reset on index evnt
|
||||
EQep1Regs.QEPCTL.bit.UTE=1; // Unit Timer Enable
|
||||
EQep1Regs.QEPCTL.bit.QCLM=1; // Latch on unit time out
|
||||
EQep1Regs.QPOSMAX=0xffffffff;
|
||||
EQep1Regs.QEPCTL.bit.QPEN=1; // QEP enable
|
||||
|
||||
#if (CPU_FRQ_150MHZ)
|
||||
EQep1Regs.QCAPCTL.bit.UPPS=2; // 1/4 for unit position at 150MHz SYSCLKOUT
|
||||
#endif
|
||||
#if (CPU_FRQ_100MHZ)
|
||||
EQep1Regs.QCAPCTL.bit.UPPS=3; // 1/8 for unit position at 100MHz SYSCLKOUT
|
||||
#endif
|
||||
|
||||
EQep1Regs.QCAPCTL.bit.CCPS=7; // 1/128 for CAP clock
|
||||
EQep1Regs.QCAPCTL.bit.CEN=1; // QEP Capture Enable
|
||||
|
||||
}
|
||||
|
||||
void FREQCAL_Calc(FREQCAL *p)
|
||||
{
|
||||
unsigned long tmp;
|
||||
_iq newp,oldp;
|
||||
|
||||
|
||||
//**** Freq Calcultation using QEP position counter ****//
|
||||
// Check unit Time out-event for speed calculation:
|
||||
// Unit Timer is configured for 100Hz in INIT function
|
||||
|
||||
// For a more detailed explanation of the calculation, read
|
||||
// the description at the top of this file
|
||||
|
||||
if(EQep1Regs.QFLG.bit.UTO==1) // Unit Timeout event
|
||||
{
|
||||
/** Differentiator **/
|
||||
newp=EQep1Regs.QPOSLAT; // Latched POSCNT value
|
||||
oldp=p->oldpos;
|
||||
|
||||
if (newp>oldp)
|
||||
tmp = newp - oldp; // x2-x1 in v=(x2-x1)/T equation
|
||||
else
|
||||
tmp = (0xFFFFFFFF-oldp)+newp;
|
||||
|
||||
p->freq_fr = _IQdiv(tmp,p->freqScaler_fr); // p->freq_fr = (x2-x1)/(T*10KHz)
|
||||
tmp=p->freq_fr;
|
||||
|
||||
if (tmp>=_IQ(1)) // is freq greater than max freq (10KHz for this example)?
|
||||
p->freq_fr = _IQ(1);
|
||||
else
|
||||
p->freq_fr = tmp;
|
||||
|
||||
p->freqhz_fr = _IQmpy(p->BaseFreq,p->freq_fr); // Q0 = Q0*GLOBAL_Q => _IQXmpy(), X = GLOBAL_Q
|
||||
// p->freqhz_fr = (p->freq_fr)*10kHz = (x2-x1)/T
|
||||
|
||||
// Update position counter
|
||||
p->oldpos = newp;
|
||||
//=======================================
|
||||
|
||||
EQep1Regs.QCLR.bit.UTO=1; // Clear interrupt flag
|
||||
}
|
||||
|
||||
//**** Freq Calcultation using QEP capture counter ****//
|
||||
if(EQep1Regs.QEPSTS.bit.UPEVNT==1) // Unit Position Event
|
||||
{
|
||||
if(EQep1Regs.QEPSTS.bit.COEF==0) // No Capture overflow
|
||||
tmp=(unsigned long)EQep1Regs.QCPRDLAT;
|
||||
else // Capture overflow, saturate the result
|
||||
tmp=0xFFFF;
|
||||
|
||||
p->freq_pr = _IQdiv(p->freqScaler_pr,tmp); // p->freq_pr = X/[(t2-t1)*10KHz]
|
||||
tmp=p->freq_pr;
|
||||
|
||||
if (tmp>_IQ(1))
|
||||
p->freq_pr = _IQ(1);
|
||||
else
|
||||
p->freq_pr = tmp;
|
||||
|
||||
p->freqhz_pr = _IQmpy(p->BaseFreq,p->freq_pr); // Q0 = Q0*GLOBAL_Q => _IQXmpy(), X = GLOBAL_Q
|
||||
// p->freqhz_pr =( p->freq_pr)*10kHz = X/(t2-t1)
|
||||
EQep1Regs.QEPSTS.all=0x88; // Clear Unit position event flag
|
||||
// Clear overflow error flag
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
112
v120/DSP2833x_examples/eqep_freqcal/Example_freqcal.h
Normal file
112
v120/DSP2833x_examples/eqep_freqcal/Example_freqcal.h
Normal file
@@ -0,0 +1,112 @@
|
||||
// TI File $Revision: /main/6 $
|
||||
// Checkin $Date: August 9, 2007 17:14:59 $
|
||||
//###########################################################################
|
||||
//
|
||||
// FILE: Example_freqcal.h
|
||||
//
|
||||
// TITLE: Frequency measurement using EQEP peripheral
|
||||
//
|
||||
// DESCRIPTION:
|
||||
//
|
||||
// Header file containing data type and object definitions and
|
||||
// initializers.
|
||||
//
|
||||
//###########################################################################
|
||||
// Original Author: SD
|
||||
//
|
||||
// $TI Release: DSP2833x/DSP2823x Header Files V1.20 $
|
||||
// $Release Date: August 1, 2008 $
|
||||
//###########################################################################
|
||||
|
||||
#ifndef __FREQCAL__
|
||||
#define __FREQCAL__
|
||||
|
||||
#include "IQmathLib.h" // Include header for IQmath library
|
||||
/*-----------------------------------------------------------------------------
|
||||
Define the structure of the FREQCAL Object
|
||||
-----------------------------------------------------------------------------*/
|
||||
typedef struct {
|
||||
Uint32 freqScaler_pr; // Parameter : Scaler converting 1/N cycles to a GLOBAL_Q freq (Q0) - independently with global Q
|
||||
Uint32 freqScaler_fr; // Parameter : Scaler converting 1/N cycles to a GLOBAL_Q freq (Q0) - independently with global Q
|
||||
Uint32 BaseFreq; // Parameter : Maximum Freq
|
||||
_iq freq_pr; // Output : Freq in per-unit using capture unit
|
||||
int32 freqhz_pr; // Output: Freq in Hz, measured using Capture unit
|
||||
Uint32 oldpos;
|
||||
_iq freq_fr; // Output : Freq in per-unit using position counter
|
||||
int32 freqhz_fr; // Output: Freq in Hz, measured using Capture unit
|
||||
void (*init)(); // Pointer to the init funcion
|
||||
void (*calc)(); // Pointer to the calc funtion
|
||||
} FREQCAL;
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
Define a QEP_handle
|
||||
-----------------------------------------------------------------------------*/
|
||||
typedef FREQCAL *FREQCAL_handle;
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
Default initializer for the FREQCAL Object.
|
||||
-----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#if (CPU_FRQ_150MHZ)
|
||||
#define FREQCAL_DEFAULTS {\
|
||||
234,200,10000,0,0,\
|
||||
0,0,0,\
|
||||
(void (*)(long))FREQCAL_Init,\
|
||||
(void (*)(long))FREQCAL_Calc }
|
||||
#endif
|
||||
#if (CPU_FRQ_100MHZ)
|
||||
#define FREQCAL_DEFAULTS {\
|
||||
313,200,10000,0,0,\
|
||||
0,0,0,\
|
||||
(void (*)(long))FREQCAL_Init,\
|
||||
(void (*)(long))FREQCAL_Calc }
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
Prototypes for the functions in Example_freqcal.c
|
||||
-----------------------------------------------------------------------------*/
|
||||
void FREQCAL_Init(void);
|
||||
void FREQCAL_Calc(FREQCAL_handle);
|
||||
|
||||
#endif /* __FREQCAL__ */
|
||||
|
||||
/* Notes:
|
||||
|
||||
For 150 MHz Operation:
|
||||
----------------------
|
||||
1. freqScaler_fr
|
||||
v = (x2-x1)/T - Equation 1
|
||||
|
||||
If max/base freq = 10kHz: 10kHz = (x2-x1)/(2/100Hz) - Equation 2
|
||||
max (x2-x1) = 200 counts = freqScaler_fr
|
||||
Note: T = 2/100Hz. 2 is from (x2-x1)/2 - because QPOSCNT counts 2 edges per cycle
|
||||
(rising and falling)
|
||||
freqhz_fr = 200 default
|
||||
|
||||
2. min freq = 1 count/(2/100Hz) = 50 Hz
|
||||
|
||||
3. freqScaler_pr
|
||||
v = X/(t2-t1) - Equation 4
|
||||
|
||||
If max/base freq = 10kHz: 10kHz = 8/(2T)
|
||||
where 4 = QCAPCTL [UPPS] (Unit timeout - once every 4 edges)
|
||||
T = time in seconds = t2-t1/(150MHz/128), t2-t1= # of QCAPCLK cycles, and
|
||||
1 QCAPCLK cycle = 1/(150MHz/128)
|
||||
= QCPRDLAT
|
||||
So: 10 kHz = 4(150MHz/128)/2(t2-t1)
|
||||
t2-t1 = 4(150MHz/128)/(10kHz*2) = (150MHz/128)/(2*10kHz/4) - Equation 5
|
||||
= 234 seconds = maximum (t2-t1) = freqScaler_pr
|
||||
freqhz_pr = 234 default
|
||||
|
||||
|
||||
For 100 MHz Operation:
|
||||
----------------------
|
||||
|
||||
The same calculations as above are performed, but with 100 MHz
|
||||
instead of 150MHz when calculation freqhr_pr, and at UPPS of 8 instead of 4.
|
||||
The value for freqScaler_pr becomes: (100MHz/128)/(2*10kHz/8) = 313
|
||||
More detailed calculation results can be found in the Example_freqcal.xls
|
||||
spreadsheet included in the example folder.
|
||||
|
||||
*/
|
||||
BIN
v120/DSP2833x_examples/eqep_freqcal/Example_freqcal.xls
Normal file
BIN
v120/DSP2833x_examples/eqep_freqcal/Example_freqcal.xls
Normal file
Binary file not shown.
Reference in New Issue
Block a user