@@ -496,7 +496,36 @@ int findBestTimerCombination(int numPins, int pins[], PinMap* pinTimers[]) {
496
496
497
497
498
498
499
+ void * _configure1PWM (long pwm_frequency, const int pinA) {
500
+ if (numTimerPinsUsed+1 > SIMPLEFOC_STM32_MAX_PINTIMERSUSED) {
501
+ SIMPLEFOC_DEBUG (" STM32-DRV: ERR: too many pins used" );
502
+ return (STM32DriverParams*)SIMPLEFOC_DRIVER_INIT_FAILED;
503
+ }
504
+
505
+ if ( !pwm_frequency || !_isset (pwm_frequency) ) pwm_frequency = _PWM_FREQUENCY; // default frequency 25khz
506
+ else pwm_frequency = _constrain (pwm_frequency, 0 , _PWM_FREQUENCY_MAX); // constrain to 50kHz max
507
+ // center-aligned frequency is uses two periods
508
+ pwm_frequency *=2 ;
509
+
510
+ int pins[1 ] = { pinA };
511
+ PinMap* pinTimers[1 ] = { NP };
512
+ if (findBestTimerCombination (1 , pins, pinTimers)<0 )
513
+ return (STM32DriverParams*)SIMPLEFOC_DRIVER_INIT_FAILED;
514
+
515
+ HardwareTimer* HT1 = _initPinPWM (pwm_frequency, pinTimers[0 ]);\
516
+ // allign the timers
517
+ _alignTimersNew ();
518
+
519
+ uint32_t channel1 = STM_PIN_CHANNEL (pinTimers[0 ]->function );
499
520
521
+ STM32DriverParams* params = new STM32DriverParams {
522
+ .timers = { HT1 },
523
+ .channels = { channel1 },
524
+ .pwm_frequency = pwm_frequency
525
+ };
526
+ timerPinsUsed[numTimerPinsUsed++] = pinTimers[0 ];
527
+ return params;
528
+ }
500
529
501
530
502
531
@@ -629,6 +658,16 @@ void* _configure4PWM(long pwm_frequency,const int pinA, const int pinB, const in
629
658
630
659
631
660
661
+ // function setting the pwm duty cycle to the hardware
662
+ // - DC motor - 1PWM setting
663
+ // - hardware speciffic
664
+ void _writeDutyCycle1PWM (float dc_a, void * params){
665
+ // transform duty cycle from [0,1] to [0,255]
666
+ _setPwm (((STM32DriverParams*)params)->timers [0 ], ((STM32DriverParams*)params)->channels [0 ], _PWM_RANGE*dc_a, _PWM_RESOLUTION);
667
+ }
668
+
669
+
670
+
632
671
// function setting the pwm duty cycle to the hardware
633
672
// - Stepper motor - 2PWM setting
634
673
// - hardware speciffic
0 commit comments