Allow to run PWM at frequencies multiples FOC loop to support applications with PWM running at 100+kHz.

Signed-off-by: Marcos Chaparro <mchaparro@powerdesigns.ca>
This commit is contained in:
Marcos Chaparro 2019-01-30 00:33:56 -03:00
parent fa9ed8dc55
commit 9652231edb
3 changed files with 19 additions and 0 deletions

View File

@ -162,6 +162,16 @@
*/
#define BLDC_SPEED_CONTROL_CURRENT 1
/*
* Run the FOC loop once every N ADC ISR requests. This way the pwm frequency is
* detached from the FOC calculation, which because it takes ~25usec it can't work
* at >40khz. To set a 100kHz pwm FOC_CONTROL_LOOP_FREQ_DIVIDER can be set at 3
* so it skips 2 ISR calls and execute the control loop in the 3rd call.
*/
#ifndef FOC_CONTROL_LOOP_FREQ_DIVIDER
#define FOC_CONTROL_LOOP_FREQ_DIVIDER 1
#endif
// Global configuration variables
extern bool conf_general_permanent_nrf_found;

View File

@ -219,6 +219,9 @@
#define MCCONF_FOC_SAMPLE_V0_V7 true // Run control loop in both v0 and v7 (requires phase shunts)
#endif
// Execute FOC loop once every "FOC_CONTROL_LOOP_FREQ_DIVIDER" ADC ISR calls
#define FOC_CONTROL_LOOP_FREQ_DIVIDER 1
// Setting limits
#define HW_LIM_CURRENT -200.0, 200.0
#define HW_LIM_CURRENT_IN -100.0, 100.0

View File

@ -1467,6 +1467,12 @@ void mcpwm_foc_adc_int_handler(void *p, uint32_t flags) {
(void)p;
(void)flags;
static int skip = 0;
if (++skip == FOC_CONTROL_LOOP_FREQ_DIVIDER)
skip = 0;
else
return;
TIM12->CNT = 0;
bool is_v7 = !(TIM1->CR1 & TIM_CR1_DIR);