ESP32 Dev Kit C LEDC jitter while WIFI

steven84009
Posts: 1
Joined: Mon Jul 11, 2022 9:55 am

ESP32 Dev Kit C LEDC jitter while WIFI

Postby steven84009 » Mon Jul 11, 2022 10:37 am

Hello everyone,
in my project i create a wifi and a socket. Clients then can connect to the wifi and transmit frequency numbers. The server has to assign the clients to a ledc channel and create a signal based on the frequency of the send data. This frequency is adjusted every 2ms. So i more use the ledc module as a FM instead of an PWM generator.

I'm using Eclipse IDE for programming, here is my code:
  1. #include <string.h>
  2. #include <stdlib.h>
  3. #include "freertos/FreeRTOS.h"
  4. #include "freertos/task.h"
  5. #include "freertos/event_groups.h"
  6. #include "esp_wifi.h"
  7. #include "esp_wpa2.h"
  8. #include "esp_event.h"
  9. #include "esp_log.h"
  10. #include "esp_system.h"
  11. #include "nvs_flash.h"
  12. #include "esp_netif.h"
  13.  
  14.  
  15. #include <sys/param.h>
  16. #include "protocol_examples_common.h"
  17. #include "addr_from_stdin.h"
  18. #include "lwip/err.h"
  19. #include "lwip/sockets.h"
  20.  
  21.  
  22. #include <stdio.h>
  23. #include "string.h"
  24. #include "esp_attr.h"
  25. #include "soc/rtc.h"
  26. #include "driver/mcpwm.h"
  27. #include "soc/mcpwm_periph.h"
  28. #include "esp_intr_alloc.h"
  29.  
  30. #include "driver/timer.h"
  31. #include "hal/mcpwm_types.h"
  32. #include "driver/mcpwm.h"
  33. #include "soc/mcpwm_periph.h"
  34.  
  35. #include "driver/ledc.h"
  36. #include "driver/mcpwm.h"
  37. #include "driver/rmt.h"
  38.  
  39. #define PORT                        4827
  40. #define HOST_IP_ADDR "192.168.43.124"
  41. #define KEEPALIVE_IDLE              5
  42. #define KEEPALIVE_INTERVAL          5
  43. #define KEEPALIVE_COUNT             3
  44.  
  45. #define GPIO_MCPWM0A   16
  46.  
  47. static const char *TAG = "example";
  48.  
  49. /* FreeRTOS event group to signal when we are connected & ready to make a request */
  50. static EventGroupHandle_t wifi_event_group;
  51.  
  52. /* esp netif object representing the WIFI station */
  53.  
  54. /* The event group allows multiple bits for each event,
  55.    but we only care about one event - are we connected
  56.    to the AP with an IP? */
  57. //static esp_netif_t *ap_netif = NULL;
  58.  
  59. const int CONNECTED_BIT = BIT0;
  60.  
  61. typedef struct {
  62.     int timer_group;
  63.     int timer_idx;
  64.     int alarm_interval;
  65.     bool auto_reload;
  66. } example_timer_info_t;
  67.  
  68. typedef struct {
  69.     uint32_t frequency;
  70.     int channel;
  71. }rx_data;
  72.  
  73.  
  74.  
  75. #define led_duty 1
  76. #define led_speep_mode LEDC_HIGH_SPEED_MODE
  77. #define led_intr_type LEDC_INTR_DISABLE
  78. #define led_timer_clk_cfg LEDC_USE_REF_TICK
  79. #define led_timer_duty_resolution LEDC_TIMER_1_BIT
  80. #define led_timer_freq_hz 60000
  81. #define led_timer_speed_mode LEDC_HIGH_SPEED_MODE
  82.  
  83. #define led_out0 16
  84. #define led_out1 17
  85. #define led_out2 18
  86. #define led_out3 19
  87.  
  88. typedef struct {
  89.     ledc_channel_config_t led_config;
  90.     ledc_timer_config_t led_timer_config;
  91.     uint8_t mac[6];
  92.     xQueueHandle f_buffer;
  93.     uint8_t socket;
  94.     int freq_default;
  95. } channel;
  96.  
  97. channel channel_default = {.led_config = {.speed_mode = led_speep_mode, .intr_type = led_intr_type, .duty = led_duty},
  98.                     .led_timer_config = {.speed_mode = led_timer_speed_mode, .duty_resolution = led_timer_duty_resolution,
  99.                     .freq_hz = led_timer_freq_hz, .clk_cfg = led_timer_clk_cfg},
  100.                     .socket = 0,
  101.                     .freq_default = 60000};
  102. typedef struct{
  103.     channel channel[4];
  104.     uint8_t num;
  105. }channel_list;
  106.  
  107. channel_list list;
  108.  
  109. xQueueHandle incoming_mac;
  110.  
  111. static void tcp_server_task();
  112.  
  113. static void event_handler(void* arg, esp_event_base_t event_base,
  114.                                 int32_t event_id, void* event_data)
  115. {
  116.  
  117.     if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_AP_START) {
  118.         xTaskCreate(tcp_server_task, "tcp_server_task", 4096, NULL, 5, NULL);
  119.     } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_AP_STADISCONNECTED) {
  120.         esp_wifi_connect();
  121.         xEventGroupClearBits(wifi_event_group, CONNECTED_BIT);
  122.     } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_AP_STACONNECTED) {
  123.         wifi_event_ap_staconnected_t* event = (wifi_event_ap_staconnected_t*) event_data;
  124.         xQueueSendToFront(incoming_mac, &event->mac, 0);
  125.         ESP_LOGI(TAG, "station "MACSTR" join, AID=%d, is this working?!?!?!", MAC2STR(event->mac), event->aid);
  126.     }
  127. }
  128.  
  129.  
  130. static void init_channels(){
  131.     int i =0;
  132.     while(i<4){
  133.         list.channel[i]=channel_default;
  134.         list.channel[i].led_config.gpio_num = led_out0 + i;
  135.         list.channel[i].led_config.channel = i;
  136.         list.channel[i].led_config.timer_sel = 3;
  137.         list.channel[i].led_timer_config.timer_num = 3;
  138.         list.channel[i].led_timer_config.freq_hz = 60000+10000*i;
  139.         list.channel[i].f_buffer = xQueueCreate(2500, sizeof(rx_data));
  140.         int j =0;
  141.         while(j<6){
  142.             list.channel[i].mac[j] = 0;
  143.             j++;
  144.         }
  145.         i++;
  146.     }
  147.  
  148.     list.num=0;
  149. }
  150.  
  151. static int check_mac(uint8_t *mac_to_check, uint8_t *mac){
  152.     int j=0;
  153.     int result =0;
  154.     while(*mac+j == *mac_to_check+j && j<6){
  155.         j++;
  156.     }
  157.     if(j==6)
  158.         return 1;
  159.     else if(j==0){
  160.         while (mac[j]==0 && j<6){
  161.             j++;
  162.         }
  163.         if(j==6)
  164.             result =  2;
  165.         else
  166.             result = 0;
  167.     }
  168.     else
  169.         result = 0;
  170.     return result;
  171. }
  172.  
  173. static void cpyMac(uint8_t *mac, uint8_t *mac_change){
  174.     int i=0;
  175.     while(i<6){
  176.         mac[i] = mac_change[i];
  177.         i++;
  178.     }
  179. }
  180.  
  181. static void start_dhcp_server(){
  182.  
  183.         // initialize the tcp stack
  184.         tcpip_adapter_init();
  185.         // stop DHCP server
  186.         ESP_ERROR_CHECK(tcpip_adapter_dhcps_stop(TCPIP_ADAPTER_IF_AP));
  187.         // assign a static IP to the network interface
  188.         tcpip_adapter_ip_info_t info;
  189.         memset(&info, 0, sizeof(info));
  190.         IP4_ADDR(&info.ip, 192, 168, 43, 124);
  191.         IP4_ADDR(&info.gw, 192, 168, 43, 124);//ESP acts as router, so gw addr will be its own addr
  192.         IP4_ADDR(&info.netmask, 255, 255, 255, 0);
  193.         ESP_ERROR_CHECK(tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_AP, &info));
  194.         // start the DHCP server
  195.         ESP_ERROR_CHECK(tcpip_adapter_dhcps_start(TCPIP_ADAPTER_IF_AP));
  196.         printf("DHCP server started \n");
  197. }
  198.  
  199.  
  200. static void initialise_wifi(void *arg)
  201. {
  202.  
  203. #ifdef CONFIG_EXAMPLE_EAP_METHOD_TLS
  204.     unsigned int client_crt_bytes = client_crt_end - client_crt_start;
  205.     unsigned int client_key_bytes = client_key_end - client_key_start;
  206. #endif /* CONFIG_EXAMPLE_EAP_METHOD_TLS */
  207.  
  208.     ESP_ERROR_CHECK(esp_netif_init());
  209.     wifi_event_group = xEventGroupCreate();
  210.     ESP_ERROR_CHECK(esp_event_loop_create_default());
  211.     /*ap_netif = esp_netif_create_default_wifi_ap();
  212.     assert(ap_netif);*/
  213.  
  214.     wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  215.  
  216.     ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
  217.     ESP_ERROR_CHECK( esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL) );
  218.     //ESP_ERROR_CHECK( esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL) );
  219.     ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
  220.  
  221.     wifi_config_t wifi_config = {
  222.         .ap = {
  223.             .ssid = "wpa2_test",
  224.             .password = "123456789",
  225.             .authmode = WIFI_AUTH_WPA_WPA2_PSK,
  226.             .max_connection = 16,
  227.         },
  228.     };
  229.  
  230.     ESP_LOGI(TAG, "Setting WiFi configuration SSID %s...", wifi_config.ap.ssid);
  231.     ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_AP) );
  232.     ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_AP, &wifi_config) );
  233.  
  234.     ESP_ERROR_CHECK( esp_wifi_start() );
  235.     vTaskDelete(NULL);
  236. }
  237.  
  238.  
  239. static void ledc_config(channel *channel){
  240.  
  241.     /*led0_config.channel = LEDC_CHANNEL_0;
  242.     led0_config.duty = 1;
  243.     led0_config.speed_mode = LEDC_HIGH_SPEED_MODE;
  244.     led0_config.gpio_num = 16;
  245.     led0_config.timer_sel = LEDC_TIMER_0;
  246.     led0_config.intr_type = LEDC_INTR_DISABLE;
  247.  
  248.     led_timer0_config.timer_num = LEDC_TIMER_0;
  249.     led_timer0_config.clk_cfg = LEDC_USE_APB_CLK;
  250.     led_timer0_config.duty_resolution = LEDC_TIMER_1_BIT;
  251.     led_timer0_config.freq_hz = 100000;
  252.     led_timer0_config.speed_mode = LEDC_HIGH_SPEED_MODE;
  253. */
  254.     ledc_channel_config(&channel->led_config);
  255.     ledc_timer_config(&channel->led_timer_config);
  256.     ledc_set_pin(channel->led_config.gpio_num, channel->led_config.speed_mode, channel->led_config.channel);
  257.     //ledc_isr_register(isr_pwm_handler, NULL, ESP_INTR_FLAG_IRAM, NULL);
  258.     ledc_timer_set(channel->led_timer_config.speed_mode, channel->led_timer_config.timer_num, 0, channel->led_timer_config.duty_resolution, LEDC_REF_TICK);
  259.  
  260.     ledc_set_freq(channel->led_config.speed_mode, channel->led_timer_config.timer_num, channel->led_timer_config.freq_hz);
  261. }
  262.  
  263. static void mcpwm_example_config()
  264. {
  265.     mcpwm_config_t pwm_config = {.frequency=80000, .cmpr_a=50.0, .cmpr_b=50.0, .duty_mode=MCPWM_DUTY_MODE_0 , .counter_mode=MCPWM_UP_COUNTER};
  266.  
  267.     mcpwm_gpio_init(0, MCPWM0A, 16);
  268.     mcpwm_init(0, 0, &pwm_config);
  269.     mcpwm_set_frequency(0, 0, 40000);
  270.     mcpwm_set_duty(0, 0, 0, 50.0);
  271.     mcpwm_set_duty_type(0, 0, 0, 0);
  272.     mcpwm_start(0, 0);
  273.  
  274. }
  275.  
  276.  
  277. static rx_data get_channel(const int sock)
  278. {
  279.     int len;
  280.     char rx_buffer[10];
  281.     rx_data event;
  282.     event.frequency=0;
  283.     event.channel = 1;
  284.  
  285.     len = recv(sock, rx_buffer, sizeof(rx_buffer) - 1, 0);
  286.     switch (rx_buffer[0]){
  287.         case 11:
  288.             event.channel = 0;
  289.             break;
  290.         case 12:
  291.             event.channel = 1;
  292.             break;
  293.         case 21:
  294.             event.channel = 2;
  295.             break;
  296.         case 22:
  297.             event.channel = 3;
  298.             break;
  299.     }
  300.  
  301.     /*do {
  302.         len = recv(sock, rx_buffer, sizeof(rx_buffer) - 1, 0);
  303.         printf("number of received bytes: %i\n", len);
  304.         if (len < 0) {
  305.             ESP_LOGE(TAG, "Error occurred during receiving: errno %d", errno);
  306.         } else if (len == 0) {
  307.             ESP_LOGW(TAG, "Connection closed");
  308.         } else {
  309.             rx_buffer[len] = 0; // Null-terminate whatever is received and treat it like a string
  310.             int to_write = 0;
  311.             while (to_write < len) {
  312.                 if(to_write == 0){
  313.                     switch (rx_buffer[to_write]){
  314.                     case 11:
  315.                         event.channel = 0;
  316.                         break;
  317.                     case 12:
  318.                         event.channel = 1;
  319.                         break;
  320.                     case 21:
  321.                         event.channel = 2;
  322.                         break;
  323.                     case 22:
  324.                         event.channel = 3;
  325.                         break;
  326.                     }
  327.                 }
  328.                 else if (i < 6){
  329.                     event.frequency = (10 * event.frequency) + (int)(rx_buffer[to_write])-48;
  330.                     i++;
  331.                 }
  332.                 else if(i >= 6){
  333.                 }
  334.                 to_write ++;
  335.             }
  336.         }
  337.     } while (i < 6);*/
  338.     return event;
  339. }
  340.  
  341.  
  342. static void do_receive(void *arg)
  343. {
  344.     int channel = (int)arg;
  345.     int len;
  346.     int i = 0;
  347.     char rx_buffer[128];
  348.     rx_data event;
  349.     event.frequency=0;
  350.     event.channel = channel;
  351.     do {
  352.         len = recv(list.channel[channel].socket, rx_buffer, sizeof(rx_buffer) - 1, 0);
  353.         if (len < 0) {
  354.             ESP_LOGE(TAG, "Error occurred during receiving: errno %d", errno);
  355.         } else if (len == 0) {
  356.             ESP_LOGW(TAG, "Connection closed");
  357.         } else {
  358.             rx_buffer[len] = 0; // Null-terminate whatever is received and treat it like a string
  359.             int to_write = 0;
  360.             while (to_write < len) {
  361.                 if (i < 6){
  362.                     event.frequency = (10 * event.frequency) + (rx_buffer[to_write])-48;
  363.                     i++;
  364.                 }
  365.                 else if(i >= 6){
  366.                     //ESP_LOGI(TAG, "Data: %i", event.frequency);
  367.                     //ESP_LOGI(TAG, "%i", mcpwm_get_frequency(0,0));
  368.                     //mcpwm_set_frequency(MCPWM_UNIT_0, MCPWM0A, event.frequency);
  369.                     //ledc_set_freq(list.channel[0].led_timer_config.speed_mode, list.channel[0].led_timer_config.timer_num, list.channel[0].led_timer_config.freq_hz);
  370.                     xQueueSendToFront(list.channel[channel].f_buffer, &event, 0);
  371.                     event.frequency = 0;
  372.                     i = 0;
  373.                 }
  374.                 to_write ++;
  375.             }
  376.         }
  377.     } while (len > 0);
  378.     shutdown(list.channel[channel].socket, 0);
  379.     close(list.channel[channel].socket);
  380.     vTaskDelete(NULL);
  381. }
  382.  
  383. static void tcp_server_task(void *arg)
  384. {
  385.     char addr_str[128];
  386.     uint8_t mac_address[6];
  387.     char host_ip[] = HOST_IP_ADDR;
  388.     int addr_family = 2;
  389.     int ip_protocol = 0;
  390.     int keepAlive = 1;
  391.     int keepIdle = KEEPALIVE_IDLE;
  392.     int keepInterval = KEEPALIVE_INTERVAL;
  393.     int keepCount = KEEPALIVE_COUNT;
  394.     struct sockaddr_storage dest_addr;
  395.     rx_data connecting_channel;
  396.  
  397.     vTaskDelay(1000 / portTICK_PERIOD_MS);
  398.  
  399.     if (addr_family == AF_INET) {
  400.         struct sockaddr_in *dest_addr_ip4 = (struct sockaddr_in *)&dest_addr;
  401.         dest_addr_ip4->sin_addr.s_addr = inet_addr(host_ip);
  402.         dest_addr_ip4->sin_family = AF_INET;
  403.         dest_addr_ip4->sin_port = htons(PORT);
  404.         ip_protocol = IPPROTO_IP;
  405.     }
  406.  
  407.     int listen_sock = socket(addr_family, SOCK_STREAM, ip_protocol);
  408.     if (listen_sock < 0) {
  409.         ESP_LOGE(TAG, "Unable to create socket: errno %d", errno);
  410.         vTaskDelete(NULL);
  411.         return;
  412.     }
  413.     int opt = 1;
  414.     setsockopt(listen_sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
  415.  
  416.  
  417.     ESP_LOGI(TAG, "Socket created");
  418.  
  419.     int err = bind(listen_sock, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
  420.     if (err != 0) {
  421.         ESP_LOGE(TAG, "Socket unable to bind: errno %d", errno);
  422.         ESP_LOGE(TAG, "IPPROTO: %d", addr_family);
  423.         goto CLEAN_UP;
  424.     }
  425.     ESP_LOGI(TAG, "Socket bound, port %d", PORT);
  426.  
  427.     err = listen(listen_sock, 1);
  428.     if (err != 0) {
  429.         ESP_LOGE(TAG, "Error occurred during listen: errno %d", errno);
  430.         goto CLEAN_UP;
  431.     }
  432.  
  433.     while (1) {
  434.  
  435.         ESP_LOGI(TAG, "Socket listening");
  436.  
  437.         struct sockaddr_storage source_addr; // Large enough for both IPv4 or IPv6
  438.         socklen_t addr_len = sizeof(source_addr);
  439.         int sock = accept(listen_sock, (struct sockaddr *)&source_addr, &addr_len);
  440.         if (sock < 0) {
  441.             ESP_LOGE(TAG, "Unable to accept connection: errno %d", errno);
  442.             break;
  443.         }
  444.  
  445.         // Set tcp keepalive option
  446.         setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &keepAlive, sizeof(int));
  447.         setsockopt(sock, IPPROTO_TCP, TCP_KEEPIDLE, &keepIdle, sizeof(int));
  448.         setsockopt(sock, IPPROTO_TCP, TCP_KEEPINTVL, &keepInterval, sizeof(int));
  449.         setsockopt(sock, IPPROTO_TCP, TCP_KEEPCNT, &keepCount, sizeof(int));
  450.         // Convert ip address to string
  451.         if (source_addr.ss_family == PF_INET) {
  452.             inet_ntoa_r(((struct sockaddr_in *)&source_addr)->sin_addr, addr_str, sizeof(addr_str) - 1);
  453.         }
  454.         ESP_LOGI(TAG, "Socket accepted ip address: %s", addr_str);
  455.  
  456.  
  457.         connecting_channel = get_channel(sock);
  458.         xQueueReceive(incoming_mac, &( mac_address ), ( TickType_t ) 10);
  459.         ESP_LOGI(TAG, "stations mac: "MACSTR"", MAC2STR(mac_address));
  460.         ESP_LOGI(TAG, "saved mac: "MACSTR"", MAC2STR(list.channel[connecting_channel.channel].mac));
  461.  
  462.         int check = check_mac(&mac_address[0], &list.channel[connecting_channel.channel].mac[0]);
  463.  
  464.         if(check==1){           //mac stimmt überein
  465.             ESP_LOGI(TAG, "Mac stimmt überein");
  466.             list.channel[connecting_channel.channel].socket=sock;
  467.             //xQueueSendToFront(list.channel[connecting_channel.channel].f_buffer, &connecting_channel.frequency, 0);
  468.             xTaskCreate(do_receive, "do_receive", 4096, connecting_channel.channel, 5, NULL);
  469.         }
  470.         else if (check ==2){    //noch keine mac vorhanden
  471.             ESP_LOGI(TAG, "Der Channel ist noch nicht vorhanden");
  472.             cpyMac(&list.channel[connecting_channel.channel].mac[0], &mac_address[0]);
  473.             list.channel[connecting_channel.channel].socket=sock;
  474.             //list.channel[connecting_channel.channel].led_timer_config.freq_hz = connecting_channel.frequency;
  475.             ledc_config(&list.channel[connecting_channel.channel]);
  476.             //xQueueSendToFront(list.channel[connecting_channel.channel].f_buffer, &connecting_channel.frequency, 0);
  477.             xTaskCreate(do_receive, "do_receive", 4096, connecting_channel.channel, 5, NULL);
  478.             //do_receive(&channel_list.channel[connecting_channel.channel]);
  479.         }
  480.         else{                   //mac ist falsch: zugriff verweigern
  481.             shutdown(sock, 0);
  482.             close(sock);
  483.         }
  484.     }
  485.  
  486. CLEAN_UP:
  487.     close(listen_sock);
  488.     vTaskDelete(NULL);
  489. }
  490.  
  491. static bool IRAM_ATTR timer_group_isr_callback(void *arg){
  492.     rx_data evt;
  493.     BaseType_t xTaskWokenByReceive = pdFALSE;
  494.     int i=0;
  495.     //while(i<4){
  496.         if(xQueueReceiveFromISR(list.channel[0].f_buffer, &evt, &xTaskWokenByReceive)){
  497.             if(evt.frequency>=30000 && evt.frequency<=220000){
  498.                 list.channel[0].led_timer_config.freq_hz = evt.frequency;
  499.                     //mcpwm_set_frequency(MCPWM_UNIT_0, MCPWM0A, evt.frequency);
  500.                     //ledc_set_freq(list.channel[0].led_timer_config.speed_mode, list.channel[0].led_timer_config.timer_num, list.channel[0].led_timer_config.freq_hz);
  501.             }
  502.         }
  503.         i++;
  504.     //}
  505.     return 0;
  506. }
  507.  
  508. static void timer_config(){
  509.     timer_config_t t0_config = {
  510.             .alarm_en = TIMER_ALARM_DIS,            //enable alarm
  511.             .counter_en = TIMER_PAUSE,              //counter disabled
  512.             .counter_dir =  TIMER_COUNT_UP,     //direction count up
  513.             .auto_reload = true,        //enable auto reload on interrupt
  514.             .divider = 2};          //no divider
  515.  
  516.     timer_group_t group = 0;
  517.     timer_idx_t timer = 0;
  518.  
  519.     timer_init(group, timer, &t0_config);
  520.  
  521.      //Timer's counter will initially start from value below.
  522.      //  Also, if auto_reload is set, this value will be automatically reload on alarm
  523.     timer_set_counter_value(group, timer, 0);
  524.  
  525.     // Configure the alarm value and the interrupt on alarm.
  526.     timer_set_alarm_value(group, timer, 40000);
  527.     timer_enable_intr(group, timer);
  528.     timer_set_alarm(group, timer, TIMER_ALARM_EN);
  529.  
  530.     timer_isr_callback_add(group, timer, timer_group_isr_callback, NULL, 0);
  531.  
  532.     timer_start(group, timer);
  533. }
  534.  
  535. void app_main(void)
  536. {
  537.     ESP_ERROR_CHECK( nvs_flash_init() );
  538.     /* This helper function configures Wi-Fi or Ethernet, as selected in menuconfig.
  539.      * Read "Establishing Wi-Fi or Ethernet Connection" section in
  540.      * examples/protocols/README.md for more information about this function.
  541.      */
  542.  
  543.     init_channels();
  544.     incoming_mac = xQueueCreate(1, sizeof(rx_data));
  545.     start_dhcp_server();
  546.     xTaskCreate(initialise_wifi, "initialise_wifi", 4096, NULL, 5, NULL);
  547.     timer_config();
  548.     //mcpwm_example_config();
  549. }
Now the issues i face:
I can't get a stable frequency while wifi module is working.
U9B03.PNG
U9B03.PNG (8.36 KiB) Viewed 989 times
U9B03.PNG
U9B03.PNG (8.36 KiB) Viewed 989 times
U9B03.PNG
U9B03.PNG (8.36 KiB) Viewed 989 times
When turning WIFI off and changing frequency by a counter every 2ms, there is no jitter. When there are clients connected there is more jitter than without clients connected. Since there is more jitter while communication is active, i guess there are some internal interrupts generated which delay ledc functionallity.

Has anyone else had this kind of issues with the ledc module?
I also tried mcpwm module with same outcome.
RMT module isnt working for me since my eclipse shows errors in rmt.c file

Thanks in advance
Attachments
U9B04.PNG
U9B04.PNG (8.25 KiB) Viewed 989 times
U9B06.PNG
U9B06.PNG (8.19 KiB) Viewed 989 times

Who is online

Users browsing this forum: No registered users and 89 guests