9#if defined(__arm__) && defined(CORE_TEENSY) && (defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MKL26Z64__) || defined(__MK64FX512__) || defined(__MK66FX1M0__))
13#pragma message("SimpleFOC: compiling for Teensy 3.x")
17#if defined(__MK20DX128__)
18#define FTM0_CH0_PIN 22
19#define FTM0_CH1_PIN 23
21#define FTM0_CH3_PIN 10
23#define FTM0_CH5_PIN 20
24#define FTM0_CH6_PIN 21
28#elif defined(__MK20DX256__)
29#define FTM0_CH0_PIN 22
30#define FTM0_CH1_PIN 23
32#define FTM0_CH3_PIN 10
34#define FTM0_CH5_PIN 20
35#define FTM0_CH6_PIN 21
39#define FTM2_CH0_PIN 32
40#define FTM2_CH1_PIN 25
41#elif defined(__MKL26Z64__)
42#define FTM0_CH0_PIN 22
43#define FTM0_CH1_PIN 23
45#define FTM0_CH3_PIN 10
47#define FTM0_CH5_PIN 20
48#define FTM1_CH0_PIN 16
49#define FTM1_CH1_PIN 17
52#elif defined(__MK64FX512__)
53#define FTM0_CH0_PIN 22
54#define FTM0_CH1_PIN 23
56#define FTM0_CH3_PIN 10
58#define FTM0_CH5_PIN 20
59#define FTM0_CH6_PIN 21
63#define FTM2_CH0_PIN 29
64#define FTM2_CH1_PIN 30
66#define FTM3_CH1_PIN 14
69#define FTM3_CH4_PIN 35
70#define FTM3_CH5_PIN 36
71#define FTM3_CH6_PIN 37
72#define FTM3_CH7_PIN 38
73#elif defined(__MK66FX1M0__)
74#define FTM0_CH0_PIN 22
75#define FTM0_CH1_PIN 23
77#define FTM0_CH3_PIN 10
79#define FTM0_CH5_PIN 20
80#define FTM0_CH6_PIN 21
84#define FTM2_CH0_PIN 29
85#define FTM2_CH1_PIN 30
87#define FTM3_CH1_PIN 14
90#define FTM3_CH4_PIN 35
91#define FTM3_CH5_PIN 36
92#define FTM3_CH6_PIN 37
93#define FTM3_CH7_PIN 38
94#define TPM1_CH0_PIN 16
95#define TPM1_CH1_PIN 17
98int _findTimer(
const int Ah,
const int Al,
const int Bh,
const int Bl,
const int Ch,
const int Cl){
100 if((Ah == FTM0_CH0_PIN && Al == FTM0_CH1_PIN) ||
101 (Ah == FTM0_CH2_PIN && Al == FTM0_CH3_PIN) ||
102 (Ah == FTM0_CH4_PIN && Al == FTM0_CH5_PIN) ){
103 if((Bh == FTM0_CH0_PIN && Bl == FTM0_CH1_PIN) ||
104 (Bh == FTM0_CH2_PIN && Bl == FTM0_CH3_PIN) ||
105 (Bh == FTM0_CH4_PIN && Bl == FTM0_CH5_PIN) ){
106 if((Ch == FTM0_CH0_PIN && Cl == FTM0_CH1_PIN) ||
107 (Ch == FTM0_CH2_PIN && Cl == FTM0_CH3_PIN) ||
108 (Ch == FTM0_CH4_PIN && Cl == FTM0_CH5_PIN) ){
109#ifdef SIMPLEFOC_TEENSY_DEBUG
119 if((Ah == FTM3_CH0_PIN && Al == FTM3_CH1_PIN) ||
120 (Ah == FTM3_CH2_PIN && Al == FTM3_CH3_PIN) ||
121 (Ah == FTM3_CH4_PIN && Al == FTM3_CH5_PIN) ){
122 if((Bh == FTM3_CH0_PIN && Bl == FTM3_CH1_PIN) ||
123 (Bh == FTM3_CH2_PIN && Bl == FTM3_CH3_PIN) ||
124 (Bh == FTM3_CH4_PIN && Bl == FTM3_CH5_PIN) ){
125 if((Ch == FTM3_CH0_PIN && Cl == FTM3_CH1_PIN) ||
126 (Ch == FTM3_CH2_PIN && Cl == FTM3_CH3_PIN) ||
127 (Ch == FTM3_CH4_PIN && Cl == FTM3_CH5_PIN) ){
129#ifdef SIMPLEFOC_TEENSY_DEBUG
138#ifdef SIMPLEFOC_TEENSY_DEBUG
150 if(!pwm_frequency || !
_isset(pwm_frequency) ) pwm_frequency = _PWM_FREQUENCY;
151 else pwm_frequency =
_constrain(pwm_frequency, 0, _PWM_FREQUENCY_MAX);
152 unsigned long pwm_freq = 2*pwm_frequency;
153 _setHighFrequency(pwm_freq,
pinA_h);
154 _setHighFrequency(pwm_freq,
pinA_l);
155 _setHighFrequency(pwm_freq,
pinB_h);
156 _setHighFrequency(pwm_freq,
pinB_l);
157 _setHighFrequency(pwm_freq,
pinC_h);
158 _setHighFrequency(pwm_freq,
pinC_l);
162 .pwm_frequency = pwm_frequency
173 for (; prescaler<=16; prescaler*=4){
174 count = dead_time*((double)F_CPU)/((double)prescaler);
175 if(count < 64)
break;
183 FTM0_COMBINE = 0x00121212;
186 FTM0_DEADTIME = (int)count;
187 FTM0_DEADTIME |= ((prescaler>1) << 7) | ((prescaler>4) << 6);
190 FTM0_SC = 0x00000028;
194 FTM3_COMBINE = 0x00121212;
197 FTM3_DEADTIME = (int)count;
198 FTM3_DEADTIME |= ((prescaler>1) << 7) | ((prescaler>4) << 6);
201 FTM3_SC = 0x00000028;
#define SIMPLEFOC_DEBUG(msg,...)
GenericCurrentSenseParams * params
void * _configure6PWM(long pwm_frequency, float dead_zone, const int pinA_h, const int pinA_l, const int pinB_h, const int pinB_l, const int pinC_h, const int pinC_l)
#define SIMPLEFOC_DRIVER_INIT_FAILED
void _writeDutyCycle6PWM(float dc_a, float dc_b, float dc_c, PhaseState *phase_state, void *params)
float const int const int const int pinB_h
float const int const int const int const int pinB_l
float const int const int const int const int const int pinC_h
float float PhaseState * phase_state
float const int const int const int const int const int const int pinC_l
float const int const int pinA_l
analogWrite(((GenericDriverParams *) params) ->pins[1], 255.0f *dc_b)
#define _constrain(amt, low, high)