2018年12月26日 星期三

DIY - ESP32:ESP32 頻率計數器 Frequency Counter 程式(五十九)

DIY - ESP32:ESP32 頻率計數器 Frequency Counter 程式(五十九):

ESP32 頻率計數器(Frequency Counter)的主要控制是放在程式中,頻率計數器程式是可以更改時基(Time Base),PCNT 是作波形發生的數量,使用 ESP32 IDF 的 PCNT 和 RMT API來實現。

ESP32 頻率計數器 Frequency Counter 製作
ESP32 頻率計數器 Frequency Counter IO 設定:
// Please connect GPIO26  and GPIO18
#define GPIO_SIGNAL_INPUT 26     // RMT Input = GPIO26
#define GPIO_RMT_GATE         5     
#define LEDC_OUTPUT_IO     18      // LEDC Output = GPIO 18

static void init_pcnt(uint8_t pulse_gpio, uint8_t ctrl_gpio, pcnt_unit_t unit, pcnt_channel_t channel, uint16_t filter_length)
{
    // set up counter
    pcnt_config_t pcnt_config = {
        .pulse_gpio_num = pulse_gpio,
        .ctrl_gpio_num = ctrl_gpio,
        .lctrl_mode = PCNT_MODE_DISABLE,
        .hctrl_mode = PCNT_MODE_KEEP,
        .pos_mode = PCNT_COUNT_INC, 
        .neg_mode = PCNT_COUNT_INC,
        .counter_h_lim = 0,
        .counter_l_lim = 0,
        .unit = unit,
        .channel = channel,
    };
}

ESP32 頻率計數器 Frequency Counter 主程式:
void app_main()
{
    frequency_count_configuration_t config;
    config.pcnt_gpio = GPIO_SIGNAL_INPUT;
    config.pcnt_unit = PCNT_UNIT;
    config.pcnt_channel = PCNT_CHANNEL;
    config.rmt_gpio = GPIO_RMT_GATE;
    config.rmt_channel = RMT_CHANNEL;
    config.rmt_clk_div = new_clk_div;
    config.rmt_max_blocks = 2;
    config.sampling_period_seconds = new_sample_period;
    config.sampling_window_seconds = new_window_duration;
    config.filter_length = new_filter_length;
    config.window_start_callback = &pcnt_window_callback;
    config.frequency_update_callback = &pcnt_freqcount_callback;

    // task takes ownership of allocated memory
    xTaskCreate(&frequency_count_task_function, "frequency_count_task", 4096, config, 5, NULL);
    }


操作系統:Windows 7 64-bit 版本
開發環境:AiThinker05 版本
原程碼: ESP32 ESP-IDF V3.0rc1
程式:DIY-ESP32-029-PCNT_05_FreqCount_Menu-20181214
 
ESP32 頻率計數器 Frequency Counter 運行中
ESP32 頻率計數器 Frequency Counter 電路製作顯示
ESP32 頻率計數器 Frequency Counter 電路製作的設定菜單
ESP32 頻率計數器 Frequency Counter 電路製作的 Frequency Counter 設定菜單
ESP32 頻率計數器 Frequency Counter 電路製作設定最高頻率的菜單
ESP32 頻率計數器 Frequency Counter 電路製作和遙控器
2018年 12月 26日 天氣報告
氣溫:19.3@ 20:40
相對濕度:百分之 90%
天氣:天色良好

2018年12月25日 星期二

DIY - ESP32:ESP32 頻率計數器 Frequency Counter 電路(五十八)

DIY - ESP32:ESP32 頻率計數器 Frequency Counter 電路(五十八):

筆者利用 ESP32 LEDC( LED控制)模塊製作了個頻率產生器(Frequency Generator / Function Generator),然後當然是製作一個可以讀出頻率的頻率計數器(Frequency Counter),測量和顯示頻率產生器的電子信號頻率。頻率計數器主要是由程式來控制,電路是將 GPIO26 接口作輸入,然後用 OLED 顯示出頻率讀數。

ESP32 頻率計數器 Frequency Counter 製作
ESP32 頻率計數器 Frequency Counter 電路圖
ESP32 頻率計數器 Frequency Counter 輸入:
LEDC
Signal
Description
ESP32 Board
Board Signal
I/O Signal
1
PCNT
Input
10
G26
GPIO26 (Input)

ESP32 頻率計數器 Frequency Counter 連接紅外線接收器電路:
紅外線 IR
Signal
Description
ESP32 Board
Board Signal
I/O Signal
2
RX
接收器
28
G17
GPIO17 (Input)

ESP32 頻率計數器 Frequency Counter 製作的正面
ESP32 頻率計數器 Frequency Counter 製作的背面
2018年 12月 25日 天氣報告
氣溫:19.7@ 21:00
相對濕度:百分之 81%
天氣:多雲

2018年12月22日 星期六

DIY - ESP32:ESP32 LEDC 控制 API 函數結構件及其它(五十七)

DIY - ESP32:ESP32 LEDC 控制 API 函數結構件及其它(五十七):

除了 ESP32 LEDC API 外,還提供了結構件(Structures)、巨集(Marco)、 泛型型別定義(Type Definitions)和枚舉(Enumerations)。

1. Structure
1.1. struct ledc_channel_config_t
Configuration parameters of LEDC channel for ledc_channel_config function.
Public Members
Description
int gpio_num
the LEDC output gpio_num, if you want to use gpio16, gpio_num = 16
ledc_mode_t speed_mode
LEDC speed speed_mode, high-speed mode or low-speed mode
ledc_channel_t channel
LEDC channel (0 - 7)
ledc_intr_type_t intr_type
configure interrupt, Fade interrupt enable or Fade interrupt disable
ledc_timer_t timer_sel
Select the timer source of channel (0 - 3)
uint32_t duty
LEDC channel duty, the range of duty setting is [0, (2**duty_resolution)]
int hpoint
LEDC channel hpoint value, the max value is 0xfffff

1.2. struct ledc_timer_config_t
Configuration parameters of LEDC Timer timer for ledc_timer_config function.
Public Members
Description
ledc_mode_t speed_mode
LEDC speed speed_mode, high-speed mode or low-speed mode
ledc_timer_bit_t duty_resolution
LEDC channel duty resolution
ledc_timer_bit_t bit_num
Deprecated in ESP-IDF 3.0. This is an alias to ‘duty_resolution’ for backward compatibility with ESP-IDF 2.1
ledc_timer_t timer_num
The timer source of channel (0 - 3)
uint32_t freq_hz
LEDC timer frequency (Hz)

2. Macros
Macros
Description
LEDC_APB_CLK_HZ
LEDC_REF_CLK_HZ
LEDC_ERR_DUTY
LEDC_ERR_VAL

3. Type Definitions
Type Definitions
Description
typedef intr_handle_t ledc_isr_handle_t

4. Enumerations
4.1. enum ledc_mode_t
Enumeration
Description
LEDC_HIGH_SPEED_MODE = 0
LEDC high speed speed_mode
LEDC_LOW_SPEED_MODE
LEDC low speed speed_mode
LEDC_SPEED_MODE_MAX
LEDC speed limit

4.2. ledc_intr_type_t
Enumeration
Description
LEDC_INTR_DISABLE = 0
Disable LEDC interrupt
LEDC_INTR_FADE_END
Enable LEDC interrupt

4.3. enum ledc_duty_direction_t
Enumeration
Description
LEDC_DUTY_DIR_DECREASE = 0
LEDC duty decrease direction
LEDC_DUTY_DIR_INCREASE = 1
LEDC duty increase direction
LEDC_DUTY_DIR_MAX

4.4. enum ledc_clk_src_t
Enumeration
Description
LEDC_REF_TICK = 0
LEDC timer clock divided from reference tick (1Mhz)
LEDC_APB_CLK
LEDC timer clock divided from APB clock (80Mhz)

4.5. enum ledc_timer_t
Enumeration
Description
LEDC_TIMER_0 = 0
LEDC timer 0
LEDC_TIMER_1
LEDC timer 1
LEDC_TIMER_2
LEDC timer 2
LEDC_TIMER_3
LEDC timer 3
LEDC_TIMER_MAX

4.6. enum ledc_channel_t
Enumeration
Description
LEDC_CHANNEL_0 = 0
LEDC channel 0
LEDC_CHANNEL_1
LEDC channel 1
LEDC_CHANNEL_2
LEDC channel 2
LEDC_CHANNEL_3
LEDC channel 3
LEDC_CHANNEL_4
LEDC channel 4
LEDC_CHANNEL_5
LEDC channel 5
LEDC_CHANNEL_6
LEDC channel 6
LEDC_CHANNEL_7
LEDC channel 7
LEDC_CHANNEL_MAX

4.7. enum ledc_timer_bit_t
Enumeration
Description
LEDC_TIMER_1_BIT = 1
LEDC PWM duty resolution of 1 bits
LEDC_TIMER_2_BIT
LEDC PWM duty resolution of 2 bits
LEDC_TIMER_3_BIT
LEDC PWM duty resolution of 3 bits
LEDC_TIMER_4_BIT
LEDC PWM duty resolution of 4 bits
LEDC_TIMER_5_BIT
LEDC PWM duty resolution of 5 bits
LEDC_TIMER_6_BIT
LEDC PWM duty resolution of 6 bits
LEDC_TIMER_7_BIT
LEDC PWM duty resolution of 7 bits
LEDC_TIMER_8_BIT
LEDC PWM duty resolution of 8 bits
LEDC_TIMER_9_BIT
LEDC PWM duty resolution of 9 bits
LEDC_TIMER_10_BIT
LEDC PWM duty resolution of 10 bits
LEDC_TIMER_11_BIT
LEDC PWM duty resolution of 11 bits
LEDC_TIMER_12_BIT
LEDC PWM duty resolution of 12 bits
LEDC_TIMER_13_BIT
LEDC PWM duty resolution of 13 bits
LEDC_TIMER_14_BIT
LEDC PWM duty resolution of 14 bits
LEDC_TIMER_15_BIT
LEDC PWM duty resolution of 15 bits
LEDC_TIMER_16_BIT
LEDC PWM duty resolution of 16 bits
LEDC_TIMER_17_BIT
LEDC PWM duty resolution of 17 bits
LEDC_TIMER_18_BIT
LEDC PWM duty resolution of 18 bits
LEDC_TIMER_19_BIT
LEDC PWM duty resolution of 19 bits
LEDC_TIMER_20_BIT
LEDC PWM duty resolution of 20 bits
LEDC_TIMER_BIT_MAX

4.8. enum ledc_fade_mode_t
Enumeration
Description
LEDC_FADE_NO_WAIT = 0
LEDC fade function will return immediately
LEDC_FADE_WAIT_DONE
LEDC fade function will block until fading to the target duty
LEDC_FADE_MAX

Header File:driver/include/driver/ledc.h

相關網址:
※ DIY - ESP32:ESP32 LEDC 控制模塊介紹(五十三)
※ DIY - ESP32:ESP32 頻率產生器 Frequency Generator 電路(五十四)
※ DIY - ESP32:ESP32 頻率產生器 Frequency Generator 程式(五十五)
※ DIY - ESP32:ESP32 LEDC 控制 API 函數(五十六)

2018年 12月 22日 天氣報告
氣溫:23.3@ 20:40
相對濕度:百分之 69%
天氣:多雲