Need help fast switching of PWM

orbitcoms
Posts: 141
Joined: Fri Aug 03, 2018 10:08 pm
Location: Sydney, Australia

Need help fast switching of PWM

Postby orbitcoms » Thu Oct 22, 2020 12:02 am

Hi,

I am working on a project that sends data using 125 kHz signal. So far, I have used LEDC to generate 125kHz signal ok and can switch it on and off using the timer_pause and timer_resume. However, I cannot turn it on an off fast enough without getting watchdog timer errors showing up.

I need to be able to switch the time on and off for bit times of 280us.

My code is below...

Code: Select all

#include <stdio.h>
#include "driver/ledc.h"
#include "freertos/freeRTOS.h"
#include "freertos/task.h"

#define PWM_CH0_GPIO (18)

void PWM_Init(void)
{

  ledc_timer_config_t ledc_timer = {
    .speed_mode = LEDC_HIGH_SPEED_MODE,
    .duty_resolution = LEDC_TIMER_8_BIT,
    .timer_num = LEDC_TIMER_0,
    .freq_hz = 125000,
    .clk_cfg = LEDC_AUTO_CLK
  };

  ledc_timer_config(&ledc_timer); 
  

 ledc_channel_config_t ledc_channel = {
    .gpio_num = PWM_CH0_GPIO,
    .speed_mode = LEDC_HIGH_SPEED_MODE,
    .channel = LEDC_CHANNEL_0,
    .intr_type = LEDC_INTR_DISABLE,
    .timer_sel = LEDC_TIMER_0,
    .duty = 127
  };
	
	ledc_channel_config(&ledc_channel);
	
}

void app_main(void)
{
  printf("Init PWM\n");
  PWM_Init();
  for(;;)
  {
    ledc_timer_pause(LEDC_HIGH_SPEED_MODE,LEDC_TIMER_0);
    vTaskDelay(50/portTICK_PERIOD_MS);
    ledc_timer_resume(LEDC_HIGH_SPEED_MODE,LEDC_TIMER_0);
    vTaskDelay(50/portTICK_PERIOD_MS);
  }

}

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Need help fast switching of PWM

Postby WiFive » Thu Oct 22, 2020 1:29 am

Rmt peripheral has carrier too

orbitcoms
Posts: 141
Joined: Fri Aug 03, 2018 10:08 pm
Location: Sydney, Australia

Re: Need help fast switching of PWM

Postby orbitcoms » Thu Oct 22, 2020 2:00 am

Thanks, that peripheral looks like it will do a better job.

Have you used it? I am having trouble assigning the GPIO pin 18 in the config.

The code example does this

Code: Select all

 rmt_config_t config = RMT_DEFAULT_CONFIG_TX(CONFIG_EXAMPLE_RMT_TX_GPIO, RMT_TX_CHANNEL);
My code is like this

Code: Select all

rmt_config_t config = RMT_DEFAULT_CONFIG_TX(RMT_GPIO, RMT_CHANNEL_0)
Where RMT_GPIO I set as 18
The error I get is "a value of type "int" cannot be used to initialize an entity of type "rmt_config_t"C/C++(144)

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: Need help fast switching of PWM

Postby ESP_Sprite » Thu Oct 22, 2020 2:18 am

You're using Arduino or C++ to compile this? Possibly you need to do

Code: Select all

rmt_config_t config = RMT_DEFAULT_CONFIG_TX((gpio_num_t)RMT_GPIO, RMT_CHANNEL_0)

orbitcoms
Posts: 141
Joined: Fri Aug 03, 2018 10:08 pm
Location: Sydney, Australia

Re: Need help fast switching of PWM

Postby orbitcoms » Thu Oct 22, 2020 2:46 am

I am using ESP-IDF in vscode

Who is online

Users browsing this forum: No registered users and 129 guests