cancel
Showing results for 
Search instead for 
Did you mean: 

How to add PWM control in SPC58EC-DISP using Ethernet gateway

SLEE.6
Associate II

Hello!​

I have a SPC58EC-DISP and imported a sample application: Network Gateway Test; I added PWM control, but it keeps running PWM and cannot run the network gateway, what should I do? it used FreeRTOS.

 
/* eMIOS1 CH22 (PWM, GROUP2) period callback.*/
void emios1_gr2ch22_pcb(PWMDriver *pwmp) {
 
  (void)pwmp;
}
 
/* eMIOS1 CH22 (PWM, GROUP2) period callback.*/
void emios1_gr2ch22_cb(PWMDriver *pwmp) {
 
  (void)pwmp;
}
 
portTASK_FUNCTION(motorPwmTask, pvParam ) {
  (void)pvParam;
 
 
  pwm_lld_start(&PWMD14,&pwm_config_e1_gr2_pwmcfg);
 
  for( ; ; ){
 
    pwm_lld_enable_channel(&PWMD14, 5, PWM_PERCENTAGE_TO_WIDTH(&PWMD14, 5000), 100, 0, 0);
 
  }
 
}
 
uint32_t motor_pwm_start(void) {
 
  uint32_t ret;
 
  /* create motor pwm task */
  ret = xTaskCreate(motorPwmTask, "motorPwmTask", 1024, NULL, 6, NULL);
 
  return (ret == pdPASS) ? 0 : 1;
}
 
 
 
/*
 * Application entry point.
 */
int main(void) {
 
  uint32_t error;
 
  /* Initialization of all the imported components in the order specified in
     the application wizard. The function is generated automatically.*/
  componentsInit();
 
  /* Enable Interrupts */
  irqIsrEnable();
 
  encoder_setup();
 
  /* Start the motor pwm task */
  error = motor_pwm_start();
  
  /* Start the gateway task */
  error = gateway_start();
 
  if (!error) {
    /* Start the remote device emulation task */
    error = remote_start();
  }
 
  if (!error) {
    /* Start all tasks */
    vTaskStartScheduler();
  }
 
  /* If all is well, the scheduler will now be running, and the following
     line will never be reached.  If the following line does execute, then
     there was insufficient FreeRTOS heap memory available for the idle and/or
     timer tasks     to be created.  See the memory management section on the
     FreeRTOS web site for more details.  http://www.freertos.org/a00111.html */
  for( ;; ) {}
 
  return 0;
}
 

This discussion has been locked for participation. If you have a question, please start a new topic in order to ask your question
1 ACCEPTED SOLUTION

Accepted Solutions
Piranha
Chief II

The pwm_lld_enable_channel() is called non-stop and therefore none of lower priority tasks don't get CPU time. As a quick workaround add some delay with vTaskDelay() after that call.

View solution in original post

3 REPLIES 3
Piranha
Chief II

The pwm_lld_enable_channel() is called non-stop and therefore none of lower priority tasks don't get CPU time. As a quick workaround add some delay with vTaskDelay() after that call.

Thank you for your help,It's working.

Giuseppe DI-GIORE
ST Employee

Hello,

no need to run pwm_lld_enable_channel() in a loop.

Call it once and the eMIOS will keep PWM going on.

Call other PWM driver functions to change period and/or duty (not in a loop).

Regards,

Giuseppe