|
#define | HW_ID_SUPPORT |
|
#define | MODULE_NAME "pwm_module" |
|
#define | DEVICE1_NAME PWM_DEVICE |
|
#define | DEVICE2_NAME MOTOR_DEVICE |
|
#define | SOFT_TIMER_MS 2 |
|
#define | SOFT_TIMER_SETUP (SOFT_TIMER_MS * 1000000) |
|
#define | NO_OF_TACHO_SAMPLES 128 |
|
#define | NO_OF_OUTPUT_PORTS 4 |
|
#define | MAX_PWM_CNT (10000) |
|
#define | MAX_SPEED (100) |
|
#define | SPEED_PWMCNT_REL (100) |
|
#define | RAMP_FACTOR (1000) |
|
#define | MAX_SYNC_MOTORS (2) |
|
#define | COUNTS_PER_PULSE_LM 12800L |
|
#define | COUNTS_PER_PULSE_MM 8100L |
|
#define | TB_COUNT_UP 0x0 |
|
#define | TB_COUNT_FREEZE 0x3 |
|
#define | TB_DISABLE 0x0 |
|
#define | TB_ENABLE 0x4 |
|
#define | TB_SHADOW 0x0 |
|
#define | TB_IMMEDIATE 0x8 |
|
#define | TB_SYNC_DISABLE 0x30 |
|
#define | TB_HDIV1 0x0 |
|
#define | TB_DIV1 0x0 |
|
#define | TB_UP 0x2000 |
|
#define | CC_CTR_A_ZERO 0x0 |
|
#define | CC_CTR_B_ZERO 0x0 |
|
#define | CC_A_SHADOW 0x00 |
|
#define | CC_B_SHADOW 0x00 |
|
#define | TBCTL 0x0 |
|
#define | TBPHS 0x3 |
|
#define | TBCNT 0x4 |
|
#define | TBPRD 0x5 |
|
#define | CMPCTL 0x7 |
|
#define | CMPA 0x9 |
|
#define | CMPB 0xA |
|
#define | AQCTLA 0xB |
|
#define | AQCTLB 0xC |
|
#define | NON_INV 1 |
|
#define | INV -1 |
|
#define | IRQA_PINNO ((pOutputPortPin[Hw])[(0 * OUTPUT_PORT_PINS) + INT].Pin) |
|
#define | IRQB_PINNO ((pOutputPortPin[Hw])[(1 * OUTPUT_PORT_PINS) + INT].Pin) |
|
#define | IRQC_PINNO ((pOutputPortPin[Hw])[(2 * OUTPUT_PORT_PINS) + INT].Pin) |
|
#define | IRQD_PINNO ((pOutputPortPin[Hw])[(3 * OUTPUT_PORT_PINS) + INT].Pin) |
|
#define | OutputReadDir(port, pin) ((HwInvBits ^ (*pOutputPortPin[Hw][(port * OUTPUT_PORT_PINS) + pin].pGpio).in_data) & pOutputPortPin[Hw][(port * OUTPUT_PORT_PINS) + pin].Mask) |
|
#define | READDirA OutputReadDir(0,DIR) |
|
#define | READDirB OutputReadDir(1,DIR) |
|
#define | READDirC OutputReadDir(2,DIR) |
|
#define | READDirD OutputReadDir(3,DIR) |
|
#define | FLOATFaultPins |
|
#define | SETSleepPins |
|
#define | SETMotorType(Port, NewType) |
|
#define | SETAvgTachoCount(Port, Speed) |
|
#define | FREERunning24bittimer ((ULONG)((((ULONG*)(TIMER64P3))[TIM34])>>8)) |
|
#define | CLEARTachoArray(No) |
|
#define | OutputFloat(port, pin) |
|
#define | OutputRead(port, pin) ((*pOutputPortPin[Hw][(port * OUTPUT_PORT_PINS) + pin].pGpio).in_data & pOutputPortPin[Hw][(port * OUTPUT_PORT_PINS) + pin].Mask) |
|
#define | OutputHigh(port, pin) |
|
#define | OutputLow(port, pin) |
|
#define | EHRPWMClkDis |
|
#define | EHRPWMClkEna |
|
#define | STOPPwm |
|
#define | SETPwmFreqKHz(KHz) |
|
#define | SETUPPwmModules |
|
#define | READIntA OutputRead(0,INT) |
|
#define | READIntB OutputRead(1,INT) |
|
#define | READIntC OutputRead(2,INT) |
|
#define | READIntD OutputRead(3,INT) |
|
#define | SHM_LENGTH (sizeof(MotorData)) |
|
#define | NPAGES ((SHM_LENGTH + PAGE_SIZE - 1) / PAGE_SIZE) |
|
|
enum | {
SAMPLES_BELOW_SPEED_25 = 0,
SAMPLES_SPEED_25_50 = 1,
SAMPLES_SPEED_50_75 = 2,
SAMPLES_ABOVE_SPEED_75 = 3,
NO_OF_SAMPLE_STEPS = 4
} |
|
enum | { CFGCHIP1 = 0x60
} |
|
enum | { TBCLKSYNC = 0x00001000
} |
|
enum | {
REVID = 0,
EMUMGT = 1,
GPINTGPEN = 2,
GPDATGPDIR = 3,
TIM12 = 4,
TIM34 = 5,
PRD12 = 6,
PRD34 = 7,
TCR = 8,
TGCR = 9,
WDTCR = 10,
NOTUSED1 = 11,
NOTUSED2 = 12,
REL12 = 13,
REL34 = 14,
CAP12 = 15,
CAP34 = 16,
NOTUSED3 = 17,
NOTUSED4 = 18,
NOTUSED5 = 19,
NOTUSED6 = 20,
NOTUSED7 = 21,
NOTUSED8 = 22,
INTCTLSTAT = 23,
CMP0 = 24,
CMP1 = 25,
CMP2 = 26,
CMP3 = 27,
CMP4 = 28,
CMP5 = 39,
CMP6 = 30,
CMP7 = 31
} |
|
enum | {
TSCTR = 0,
CTRPHS = 2,
CAP1 = 4,
CAP2 = 6,
CAP3 = 8,
CAP4 = 10,
ECCTL1 = 20,
ECCTL2 = 21,
ECEINT = 22,
ECFLG = 23,
ECCLR = 24,
ECFRC = 25,
ECAP_REVID = 46
} |
|
enum | { FORWARD,
BACKWARD,
BRAKE,
COAST
} |
|
enum | {
UNLIMITED_UNREG,
UNLIMITED_REG,
LIMITED_REG_STEPUP,
LIMITED_REG_STEPCONST,
LIMITED_REG_STEPDOWN,
LIMITED_UNREG_STEPUP,
LIMITED_UNREG_STEPCONST,
LIMITED_UNREG_STEPDOWN,
LIMITED_REG_TIMEUP,
LIMITED_REG_TIMECONST,
LIMITED_REG_TIMEDOWN,
LIMITED_UNREG_TIMEUP,
LIMITED_UNREG_TIMECONST,
LIMITED_UNREG_TIMEDOWN,
LIMITED_STEP_SYNC,
LIMITED_TURN_SYNC,
LIMITED_DIFF_TURN_SYNC,
SYNCED_SLAVE,
RAMP_DOWN_SYNC,
HOLD,
BRAKED,
STOP_MOTOR,
IDLE
} |
|
enum | { UNUSED_SYNC_MOTOR = 0xFF
} |
|
enum | OutputPortPins {
OUTPUT_PORT_PIN1,
OUTPUT_PORT_PIN2,
OUTPUT_PORT_PIN5W,
OUTPUT_PORT_PIN5R,
OUTPUT_PORT_PIN6,
OUTPUT_PORT_PINS,
OUTPUT_PORT_VALUE,
PWM,
DIR0,
DIR1,
INT,
DIR,
SLEEP,
FAULT,
OUTPUT_PORT_PINS
} |
|
|
UBYTE | dCalculateSpeed (UBYTE No, SBYTE *pSpeed) |
| dCalculateSpeed More...
|
|
void | SetGpioRisingIrq (UBYTE PinNo, irqreturn_t(*IntFuncPtr)(int, void *)) |
|
void | GetSyncDurationCnt (SLONG *pCount0, SLONG *pCount1) |
|
void | CheckforEndOfSync (void) |
|
void | SetDutyMA (ULONG Duty) |
|
void | SetDutyMB (ULONG Duty) |
|
void | SetDutyMC (ULONG Duty) |
|
void | SetDutyMD (ULONG Duty) |
|
| MODULE_LICENSE ("GPL") |
|
| MODULE_AUTHOR ("The LEGO Group") |
|
| MODULE_DESCRIPTION (MODULE_NAME) |
|
| MODULE_SUPPORTED_DEVICE (DEVICE1_NAME) |
|
| module_init (ModuleInit) |
|
| module_exit (ModuleExit) |
|
void | CheckSpeedPowerLimits (SBYTE *pCheckVal) |
|
UBYTE | CheckLessThanSpecial (SLONG Param1, SLONG Param2, SLONG Inv) |
|
void | IncSpeed (SBYTE Dir, SBYTE *pSpeed) |
|
void | DecSpeed (SBYTE Dir, SBYTE *pSpeed) |
|
void | SetDirRwd (UBYTE Port) |
|
void | SetDirFwd (UBYTE Port) |
|
void | SetBrake (UBYTE Port) |
|
void | SetCoast (UBYTE Port) |
|
UWORD | GetTachoDir (UBYTE Port) |
|
UWORD | GetTachoInt (UBYTE Port) |
|
void | SetPower (UBYTE Port, SLONG Power) |
|
void | SetRegulationPower (UBYTE Port, SLONG Power) |
|
void | ClearPIDParameters (UBYTE No) |
|
void | StepPowerStopMotor (UBYTE No, SLONG AdjustTachoValue) |
| StepPowerStopMotor. More...
|
|
UBYTE | StepSpeedCheckTachoCntUp (UBYTE No) |
| StepSpeedCheckTachoCntUp. More...
|
|
UBYTE | StepSpeedCheckTachoCntConst (UBYTE No, SLONG AdjustTachoValue) |
| StepPowerCheckTachoCntConst. More...
|
|
void | StepSpeedCheckTachoCntDown (UBYTE No, SLONG AdjustTachoValue) |
| StepSpeedCheckTachoCntDown. More...
|
|
UBYTE | StepPowerCheckTachoCntUp (UBYTE No) |
| StepPowerCheckTachoCntUp. More...
|
|
UBYTE | StepPowerCheckTachoCntConst (UBYTE No, SLONG AdjustTachoValue) |
| StepPowerCheckTachoCntConst. More...
|
|
void | StepPowerCheckTachoCntDown (UBYTE No, SLONG AdjustTachoValue) |
| StepPowerCheckTachoCntDown. More...
|
|
void | dRegulateSpeed (UBYTE No) |
| dRegulateSpeed More...
|
|
void | BrakeMotor (UBYTE No, SLONG TachoCnt) |
|
UBYTE | RampDownToBrake (UBYTE No, SLONG CurrentCnt, SLONG TargetCnt, SLONG Dir) |
|
void | CalcRampDownFactor (UBYTE No, ULONG CurrentPower, ULONG Counts) |
|
void | GetCompareCounts (UBYTE No, SLONG *Counts, SLONG *CompareCounts) |
|
void | StopAndBrakeMotor (UBYTE MotorNo) |
|
void | StopAndFloatMotor (UBYTE MotorNo) |
|
void | FloatSyncedMotors (void) |
|
void | TestAndFloatSyncedMotors (UBYTE MotorBitField, UBYTE SyncCmd) |
|
void | GetPeriphealBasePtr (ULONG Address, ULONG Size, ULONG **Ptr) |
| GetPeriphealBasePtr. More...
|
|
void | SetGpio (int Pin) |
|
void | InitGpio (void) |
|
| module_param (HwId, charp, 0) |
|
dCalculateSpeed
- Calculates the actual speed for a motor
- Returns TRUE when a new speed has been calculated, FALSE if otherwise
- Time is sampled every edge on the tacho
- Timer used is 64bit timer plus (P3) module (dual 32bit un-chained mode)
- 64bit timer is running 33Mhz (24Mhz (Osc) * 22 (Multiplier) / 2 (Post divider) / 2 (DIV2)) / 4 (T64 prescaler)
- When reading the timer it is divided by 256 => timer is a factor 256 slower
- Tacho counter is updated on every edge of the tacho INTx pin signal
- Time capture is updated on every edge of the tacho INTx pin signal
- Speed is calculated from the following parameters
- Time is measured edge to edge of the tacho interrupt pin. Average of time is always minimum 2 pulses (1 high + 1 low period or 1 low + 1 high period) because the duty of the high and low period of the tacho pulses are not always 50%.
- Average of the large motor
- Above speed 80 it is: 64 samples
- Between speed 60 - 80 it is: 32 samples
- Between speed 40 - 60 it is: 16 samples
- below speed 40 it is: 4 samples
- Average of the medium motor
- Above speed 80 it is: 16 samples
- Between speed 60 - 80 it is: 8 samples
- Between speed 40 - 60 it is: 4 samples
- below speed 40 it is: 2 sample
- Number of samples is always determined based on 1 sample meaning 1 low period nor 1 high period, this is to enable fast adoption to changes in speed. Medium motor has the critical timing because it can change speed and direction very fast.
- Large Motor
- Maximum speed of the Large motor is approximately 2mS per tacho pulse (low + high period) resulting in minimum timer value of: 2mS / (1/(33MHz / 256)) = 256 T64 timer ticks. Because 1 sample is based on only half a period minimum speed is 256/2 = 128.
- Minimum speed of the large motor is a factor of 100 less than max. speed max. speed timer ticks * 100 => 256 * 100 = 25600 T64 timer ticks Because 1 sample is based on only half a period minimum speed is 25600/2 = 12800.
- Medium Motor
- Maximum speed of the medium motor is approximately 1,25mS per tacho pulse (low + high period)
resulting in minimum timer value og: 1,25mS / (1/(33MHz / 256)) = 162 (approximately)
Because 1 sample is based on only half a period minimum speed is 162/2 = 81.
- Minimum speed of the medium motor is a factor of 100 less than max. speed
max. speed timer ticks * 100 => 162 * 100 = 16200 T64 timer ticks
Because 1 sample is based on only half a period minimum speed is 16200/2 = 8100.
- Actual speed is then calculated as:
- Medium motor:
8100 * number of samples / actual time elapsed for number of samples
- Large motor:
12800 * number of samples / actual time elapsed for number of samples
- Parameters:
- Input:
- No : Motor output number
- *pSpeed : Pointer to the speed value
- Output:
- Status : Indication of new speed available or not
- Tacho pulse examples:
| | | | | | | | | | | | | | ----— ----— ----— — DIRx signal
---- ------ ------ ------ INTx signal
| | | | | |
| | | | | |
------- ------- -------
^ ^ ^ ^ ^ ^
| | | | | |
| Timer | Timer | Timer
| + | + | +
| Counter | Counter | Counter
| | |
Timer Timer Timer
+ + +
Counter Counter Counter
| | | | | | | | | | | | | | | | ----— ----— ----— ----— DIRx signal
------ ------------- ------ ------INTx signal
| | | | | |
| | | | | |
------- ------- -------
^ ^ ^ ^ ^ ^
| | | | | |
Timer | Timer | Timer |
+ | + | + |
Counter | Counter | Counter |
+ | + | + |
DirChgPtr++ | DirChgPtr=0 |DirChgPtr++ |
Timer Timer Timer
+ + +
Counter Counter Counter
+ + +
DirChgPtr++ DirChgPtr++ DirChgPtr++
---- ------ ------ ----
| | | | | |
| | | | | |
------- ------------- ------- DIRx signal
------ ------ ------ ------ INTx signal
| | | | | | |
| | | | | | |
------- ------- ------- ----
^ ^ ^ ^ ^ ^ ^
| | | | | | |
Timer | Timer | Timer | Timer
+ | + | + | +
Counter | Counter | Counter | Counter
+ | + | + | +
DirChgPtr++| DirChgPtr++| DirChgPtr++| DirChgPtr++
Timer Timer Timer
+ + +
Counter Counter Counter
+ + +
DirChgPtr++ DirChgPtr=0 DirChgPtr++
Definition at line 3978 of file d_pwm.c.