Browse Source

update

Finny_test
zwsd 3 years ago
parent
commit
07ec16ee53
  1. 47
      main/heating_plate.c
  2. 2
      main/heating_plate.h

47
main/heating_plate.c

@ -10,6 +10,16 @@
*/ */
#include "heating_plate.h" #include "heating_plate.h"
#include "driver/ledc.h"
#include "esp_err.h"
#define LEDC_TIMER LEDC_TIMER_0 //
#define LEDC_MODE LEDC_LOW_SPEED_MODE //
#define LEDC_OUTPUT_IO (20) // Define the output GPIO
#define LEDC_CHANNEL LEDC_CHANNEL_0 //
#define LEDC_DUTY_RES LEDC_TIMER_13_BIT // Set duty resolution to 13 bits
#define LEDC_DUTY (4095) // Set duty to 50%. ((2 ** 13) - 1) * 50% = 4095
#define LEDC_FREQUENCY (5000) // Frequency in Hertz. Set frequency at 5 kHz
#define heating_plate_target_temp 48.0 #define heating_plate_target_temp 48.0
#define heating_plate_variable_temperature_range 0.5 #define heating_plate_variable_temperature_range 0.5
@ -20,13 +30,38 @@ static get_temp_callback_t get_temp_cb_s;
void T_heating_plate_init(heating_plate_structer_t *heating_plate_structer) void T_heating_plate_init(heating_plate_structer_t *heating_plate_structer)
{ {
heating_plate_structer_s = heating_plate_structer; heating_plate_structer_s = heating_plate_structer;
// Prepare and then apply the LEDC PWM timer configuration
ledc_timer_config_t ledc_timer = {
.speed_mode = LEDC_MODE,
.timer_num = LEDC_TIMER,
.duty_resolution = LEDC_DUTY_RES,
.freq_hz = LEDC_FREQUENCY, // Set output frequency at 5 kHz
.clk_cfg = LEDC_AUTO_CLK};
ESP_ERROR_CHECK(ledc_timer_config(&ledc_timer));
// Prepare and then apply the LEDC PWM channel configuration
ledc_channel_config_t ledc_channel = {
.speed_mode = LEDC_MODE,
.channel = LEDC_CHANNEL,
.timer_sel = LEDC_TIMER,
.intr_type = LEDC_INTR_DISABLE,
.gpio_num = LEDC_OUTPUT_IO,
.duty = 0, // Set duty to 0%
.hpoint = 0};
ESP_ERROR_CHECK(ledc_channel_config(&ledc_channel));
} }
void T_heating_plate_registered_cb(get_temp_callback_t cb) { get_temp_cb_s = cb; } void T_heating_plate_registered_cb(get_temp_callback_t cb) { get_temp_cb_s = cb; }
void T_heating_plate_start(void) {}
void T_heating_plate_start(void)
{
T_heating_plate_set_and_update_duty(LEDC_DUTY);
}
void T_heating_plate_stop(void) {}
void T_heating_plate_stop(void)
{
T_heating_plate_set_and_update_duty(0);
}
void T_heating_plate_schedule(void) void T_heating_plate_schedule(void)
{ {
@ -42,3 +77,11 @@ void T_heating_plate_schedule(void)
} }
} }
} }
void T_heating_plate_set_and_update_duty(uint32_t duty)
{
// Set duty
ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, duty));
// Update duty to apply the new value
ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL));
}

2
main/heating_plate.h

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h>
typedef struct typedef struct
{ {
@ -14,3 +15,4 @@ void T_heating_plate_registered_cb(get_temp_callback_t cb);
void T_heating_plate_start(void); void T_heating_plate_start(void);
void T_heating_plate_stop(void); void T_heating_plate_stop(void);
void T_heating_plate_schedule(void); void T_heating_plate_schedule(void);
void T_heating_plate_set_and_update_duty(uint32_t duty);
Loading…
Cancel
Save