MotorWare f2806x Module API Documentation

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

slip.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2 * Copyright (c) 2012, Texas Instruments Incorporated
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * --/COPYRIGHT--*/
37
38
39 // **************************************************************************
40 // the includes
41
42 #include "sw/modules/slip/src/32b/slip.h"
43
44
45 // **************************************************************************
46 // the defines
47
48
49 // **************************************************************************
50 // the globals
51
52
53 // **************************************************************************
54 // the functions
55
56 SLIP_Handle SLIP_init(void *pMemory,const size_t numBytes)
57 {
58 SLIP_Handle slipHandle;
59
60 if(numBytes < sizeof(SLIP_Obj))
61 return((SLIP_Handle)NULL);
62
63 // assign the handle
64 slipHandle = (SLIP_Handle)pMemory;
65
66 return(slipHandle);
67 } // end of SLIP_init() function
68
69
70 void SLIP_setup(SLIP_Handle slipHandle, _iq sampleTime)
71 {
72 SLIP_Obj *slip;
73
74 // create an object pointer for manipulation
75 slip = (SLIP_Obj *) slipHandle;
76
77 // set the sample time
78 slip->sample_time = sampleTime;
79
80 // initialize all other values to 0
81 slip->enc_elec_angle = 0;
82 slip->enc_magnetic_angle = 0;
83 slip->enc_slip_angle = 0;
84 slip->incremental_slip = 0;
85
86 return;
87 } // end of SLIP_setup() function
88
89
90 void SLIP_run(SLIP_Handle slipHandle)
91 {
92 SLIP_Obj *slip;
93 uint32_t temp;
94
95 // create an object pointer for manipulation
96 slip = (SLIP_Obj *) slipHandle;
97
98 // update the slip angle
99 slip->enc_slip_angle = slip->enc_slip_angle + slip->incremental_slip;
100 // wrap around 1.0 (Q24)
101 slip->enc_slip_angle &= ((uint32_t) 0x00ffffff);
102 // add in compensation for slip
103 temp = slip->enc_elec_angle + slip->enc_slip_angle;
104 // wrap around 1.0 (Q24)
105 temp &= ((uint32_t) 0x00ffffff);
106 // store encoder magnetic angle
107 slip->enc_magnetic_angle = (_iq)temp;
108
109 return;
110 } // end of SLIP_run() function
111
112
113 // end of file
SLIP_init
SLIP_Handle SLIP_init(void *pMemory, const size_t numBytes)
Initializes the encoder object.
Definition: slip.c:56
SLIP_Handle
struct _SLIP_Handle_ * SLIP_Handle
Defines the slip handle.
Definition: slip.h:80
_SLIP_Obj_::incremental_slip
int32_t incremental_slip
incremental amount of slip per sample time
Definition: slip.h:72
_SLIP_Obj_::enc_elec_angle
int32_t enc_elec_angle
current electrical angle from encoder
Definition: slip.h:71
_iq
long _iq
Definition: 32b/IQmathLib.h:223
_SLIP_Obj_::enc_slip_angle
int32_t enc_slip_angle
amount of total slip in Q24
Definition: slip.h:73
SLIP_setup
void SLIP_setup(SLIP_Handle slipHandle, _iq sampleTime)
Initializes slip object parameters.
Definition: slip.c:70
_SLIP_Obj_::sample_time
_iq sample_time
sample time of the SLIP module
Definition: slip.h:70
_SLIP_Obj_::enc_magnetic_angle
int32_t enc_magnetic_angle
current magnetic angle in Q24
Definition: slip.h:74
SLIP_run
void SLIP_run(SLIP_Handle slipHandle)
Based on the electrical angle and the incremental slip, calculates the magnetic angle.
Definition: slip.c:90
_SLIP_Obj_
Defines the slip object.
Definition: slip.h:68
slip.h
Contains the public interface to the slip compensation module routines.