@@ -193,139 +193,6 @@ class AnalogInClass {
193
193
194
194
extern AnalogInClass analog_in;
195
195
196
- class AnalogOutPWMClass {
197
- public:
198
- AnalogOutPWMClass () {
199
- GPIO_InitTypeDef GPIO_InitStruct;
200
-
201
- // Enables peripherals and GPIO Clocks HRTIM1 Peripheral clock enable
202
- __HAL_RCC_HRTIM1_CLK_ENABLE ();
203
-
204
- // Enable GPIO Channels Clock
205
- __HAL_RCC_GPIOG_CLK_ENABLE ();
206
-
207
- // Configure HRTIMA TIMA TA1/A2, TIMB TB1/2, TIMC TC1/2, TIMD TD1/2 and TIME TE1.2
208
- // channels as alternate function mode
209
-
210
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
211
- GPIO_InitStruct.Pull = GPIO_PULLUP;
212
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
213
- GPIO_InitStruct.Alternate = GPIO_AF2_HRTIM1;
214
- GPIO_InitStruct.Pin = GPIO_PIN_7;
215
- HAL_GPIO_Init (GPIOG, &GPIO_InitStruct);
216
-
217
- // Configure the HRTIM peripheral
218
- // Initialize the HRTIM structure
219
- HrtimHandle.Instance = HRTIM1;
220
- HrtimHandle.Init .HRTIMInterruptResquests = HRTIM_IT_NONE;
221
- HrtimHandle.Init .SyncOptions = HRTIM_SYNCOPTION_NONE;
222
-
223
- HAL_HRTIM_Init (&HrtimHandle);
224
-
225
- // Configure the HRTIM TIME PWM channels 2
226
- sConfig_time_base .Mode = HRTIM_MODE_CONTINUOUS;
227
- sConfig_time_base .Period = 100 ;
228
- sConfig_time_base .PrescalerRatio = HRTIM_PRESCALERRATIO_DIV1;
229
- sConfig_time_base .RepetitionCounter = 0 ;
230
-
231
- HAL_HRTIM_TimeBaseConfig (&HrtimHandle, HRTIM_TIMERINDEX_TIMER_E, &sConfig_time_base );
232
-
233
- sConfig_timerE .DMARequests = HRTIM_TIM_DMA_NONE;
234
- sConfig_timerE .HalfModeEnable = HRTIM_HALFMODE_DISABLED;
235
- sConfig_timerE .StartOnSync = HRTIM_SYNCSTART_DISABLED;
236
- sConfig_timerE .ResetOnSync = HRTIM_SYNCRESET_DISABLED;
237
- sConfig_timerE .DACSynchro = HRTIM_DACSYNC_NONE;
238
- sConfig_timerE .PreloadEnable = HRTIM_PRELOAD_ENABLED;
239
- sConfig_timerE .UpdateGating = HRTIM_UPDATEGATING_INDEPENDENT;
240
- sConfig_timerE .BurstMode = HRTIM_TIMERBURSTMODE_MAINTAINCLOCK;
241
- sConfig_timerE .RepetitionUpdate = HRTIM_UPDATEONREPETITION_ENABLED;
242
- sConfig_timerE .ResetUpdate = HRTIM_TIMUPDATEONRESET_DISABLED;
243
- sConfig_timerE .InterruptRequests = HRTIM_TIM_IT_NONE;
244
- sConfig_timerE .PushPull = HRTIM_TIMPUSHPULLMODE_DISABLED;
245
- sConfig_timerE .FaultEnable = HRTIM_TIMFAULTENABLE_NONE;
246
- sConfig_timerE .FaultLock = HRTIM_TIMFAULTLOCK_READWRITE;
247
- sConfig_timerE .DeadTimeInsertion = HRTIM_TIMDEADTIMEINSERTION_DISABLED;
248
- sConfig_timerE .DelayedProtectionMode = HRTIM_TIMER_D_E_DELAYEDPROTECTION_DISABLED;
249
- sConfig_timerE .UpdateTrigger = HRTIM_TIMUPDATETRIGGER_NONE;
250
- sConfig_timerE .ResetTrigger = HRTIM_TIMRESETTRIGGER_NONE;
251
-
252
- HAL_HRTIM_WaveformTimerConfig (&HrtimHandle, HRTIM_TIMERINDEX_TIMER_E,&sConfig_timerE );
253
-
254
- sConfig_compare .AutoDelayedMode = HRTIM_AUTODELAYEDMODE_REGULAR;
255
- sConfig_compare .AutoDelayedTimeout = 0 ;
256
- sConfig_compare .CompareValue = 1 ;
257
-
258
- HAL_HRTIM_WaveformCompareConfig (&HrtimHandle, HRTIM_TIMERINDEX_TIMER_E, HRTIM_COMPAREUNIT_2, &sConfig_compare );
259
-
260
- sConfig_output_config .Polarity = HRTIM_OUTPUTPOLARITY_LOW;
261
- sConfig_output_config .SetSource = HRTIM_OUTPUTRESET_TIMCMP2;
262
- sConfig_output_config .ResetSource = HRTIM_OUTPUTSET_TIMPER;
263
- sConfig_output_config .IdleMode = HRTIM_OUTPUTIDLEMODE_NONE;
264
- sConfig_output_config .IdleLevel = HRTIM_OUTPUTIDLELEVEL_INACTIVE;
265
- sConfig_output_config .FaultLevel = HRTIM_OUTPUTFAULTLEVEL_NONE;
266
- sConfig_output_config .ChopperModeEnable = HRTIM_OUTPUTCHOPPERMODE_DISABLED;
267
- sConfig_output_config .BurstModeEntryDelayed = HRTIM_OUTPUTBURSTMODEENTRY_REGULAR;
268
- sConfig_output_config .ResetSource = HRTIM_OUTPUTRESET_TIMPER;
269
- sConfig_output_config .SetSource = HRTIM_OUTPUTSET_TIMCMP2;
270
-
271
- HAL_HRTIM_WaveformOutputConfig (&HrtimHandle, HRTIM_TIMERINDEX_TIMER_E, HRTIM_OUTPUT_TE2, &sConfig_output_config );
272
-
273
- // Start PWM signals generation
274
- if (HAL_HRTIM_WaveformOutputStart (&HrtimHandle, HRTIM_OUTPUT_TE2) != HAL_OK)
275
- {
276
- // PWM Generation Error
277
- }
278
-
279
- // Start HRTIM counter
280
- if (HAL_HRTIM_WaveformCounterStart (&HrtimHandle, HRTIM_TIMERID_TIMER_E) != HAL_OK)
281
- {
282
- // PWM Generation Error
283
- }
284
- }
285
-
286
- ~AnalogOutPWMClass (){}
287
- void period_ms (int period) {
288
- sConfig_time_base .Mode = HRTIM_MODE_CONTINUOUS;
289
- sConfig_time_base .Period = period;
290
- sConfig_time_base .PrescalerRatio = HRTIM_PRESCALERRATIO_DIV1;
291
- sConfig_time_base .RepetitionCounter = 0 ;
292
-
293
- HAL_HRTIM_TimeBaseConfig (&HrtimHandle, HRTIM_TIMERINDEX_TIMER_E, &sConfig_time_base );
294
- }
295
-
296
- bool write (uint8_t pulse) {
297
- if (pulse > 100 ) {
298
- pulse = 100 ;
299
- }
300
- sConfig_compare .CompareValue = pulse;
301
- if (HAL_HRTIM_WaveformCompareConfig (&HrtimHandle, HRTIM_TIMERINDEX_TIMER_E, HRTIM_COMPAREUNIT_2, &sConfig_compare ) != HAL_OK)
302
- {
303
- return false ;
304
- }
305
- return true ;
306
- }
307
-
308
- bool stop () {
309
- if (HAL_HRTIM_SimplePWMStop (&HrtimHandle, HRTIM_TIMERINDEX_TIMER_E, HRTIM_OUTPUT_TE2) != HAL_OK)
310
- {
311
- return false ;
312
- }
313
- return true ;
314
- }
315
-
316
- private:
317
- HRTIM_HandleTypeDef HrtimHandle;
318
-
319
- HRTIM_TimeBaseCfgTypeDef sConfig_time_base ;
320
- HRTIM_TimerCfgTypeDef sConfig_timerE ;
321
- HRTIM_OutputCfgTypeDef sConfig_output_config ;
322
- HRTIM_CompareCfgTypeDef sConfig_compare ;
323
- };
324
-
325
-
326
- extern AnalogOutPWMClass analopwm;
327
-
328
-
329
196
class AnalogOutClass {
330
197
public:
331
198
void write (int index, float voltage) {
@@ -341,7 +208,7 @@ class AnalogOutClass {
341
208
out_1.write (voltage / 10.5 );
342
209
break ;
343
210
case 2 :
344
- out_2.write (( voltage* 9.5 ) );
211
+ out_2.write (voltage / 10.5 );
345
212
break ;
346
213
case 3 :
347
214
out_3.write (voltage / 10.5 );
@@ -357,7 +224,7 @@ class AnalogOutClass {
357
224
out_1.period_ms (period);
358
225
break ;
359
226
case 2 :
360
- out_2.period_ms (( period/ 4 )* 100 );
227
+ out_2.period_ms (period);
361
228
break ;
362
229
case 3 :
363
230
out_3.period_ms (period);
@@ -370,16 +237,16 @@ class AnalogOutClass {
370
237
return out_0;
371
238
case 1 :
372
239
return out_1;
373
- // case 2:
374
- // return out_2;
240
+ case 2 :
241
+ return out_2;
375
242
case 3 :
376
243
return out_3;
377
244
}
378
245
}
379
246
private:
380
247
mbed::PwmOut out_0 = mbed::PwmOut(PJ_11);
381
248
mbed::PwmOut out_1 = mbed::PwmOut(PK_1);
382
- AnalogOutPWMClass out_2 = AnalogOutPWMClass( );
249
+ mbed::PwmOut out_2 = mbed::PwmOut(PG_7 );
383
250
mbed::PwmOut out_3 = mbed::PwmOut(PC_7);
384
251
};
385
252
0 commit comments