sdm: support sdm on esp32h2
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
|
||||
(See the README.md file in the upper level 'examples' directory for more information about examples.)
|
||||
|
||||
This example uses the sigma-delta driver to generate modulated output on a GPIO. If you filter the output signal with an active or passive filter, you can get a 1 KHz sine wave.
|
||||
This example uses the sigma-delta driver to generate modulated output on a GPIO. If you filter the output signal with an active or passive filter, you can get a 100 Hz sine wave.
|
||||
|
||||
## How to use example
|
||||
|
||||
@@ -46,21 +46,17 @@ Once the upload is complete and the board is reset, the program should start run
|
||||
I (299) main_task: Calling app_main()
|
||||
I (309) gpio: GPIO[0]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
|
||||
I (309) sdm_dac: Sigma-delta output is attached to GPIO 0
|
||||
I (319) sdm_dac: Timer allocated with resolution 10000000 Hz
|
||||
I (329) sdm_dac: Timer callback registered, interval 10 us
|
||||
I (319) sdm_dac: Timer allocated with resolution 1000000 Hz
|
||||
I (329) sdm_dac: Timer callback registered, interval 100 us
|
||||
I (329) sdm_dac: Timer enabled
|
||||
I (339) sdm_dac: Output start
|
||||
```
|
||||
|
||||
After the output stated, you can monitor the output signal by an oscilloscope.
|
||||
|
||||
If you monitor on the GPIO directly, you can see the raw SDM output, it consists by square waves (i.e. pulse) with different density
|
||||
If you monitor on the GPIO directly, you can see the raw SDM output, it consists of square waves (i.e. pulse) with different densities (see the blue wave in the figure), and if you monitor the signal after a low-pass filter, you can see the pulses are filtered into a sine wave already (see the yellow wave in the figure).
|
||||
|
||||

|
||||
|
||||
If you monitor the signal after a low-pass filter, you can see the pulses are filtered into a sine wave already
|
||||
|
||||

|
||||

|
||||
|
||||
## Troubleshooting
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 9.9 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 8.8 KiB |
@@ -11,15 +11,16 @@
|
||||
#include "driver/sdm.h"
|
||||
#include "driver/gptimer.h"
|
||||
|
||||
#define EXAMPLE_SIGMA_DELTA_GPIO_NUM (0) // Select GPIO_NUM_0 as the sigma-delta output pin
|
||||
#define EXAMPLE_OVER_SAMPLE_RATE (20 * 1000 * 1000) // 20 MHz over sample rate
|
||||
#define EXAMPLE_TIMER_RESOLUTION (10 * 1000 * 1000) // 10 MHz timer counting resolution
|
||||
#define EXAMPLE_CALLBACK_INTERVAL_US (10) // 10 us interval of each timer callback
|
||||
#define EXAMPLE_ALARM_COUNT (EXAMPLE_CALLBACK_INTERVAL_US * (EXAMPLE_TIMER_RESOLUTION / 1000000))
|
||||
#define EXAMPLE_SINE_WAVE_FREQ_HZ (1000) // 1 KHz wave, adjust this value to decide the sine wave frequency
|
||||
#define EXAMPLE_SINE_WAVE_AMPLITUDE (127.0f) // 1 ~ 127, adjust this value to decide the sine wave amplitude
|
||||
#define EXAMPLE_SINE_WAVE_POINT_NUM (1000000 / (EXAMPLE_CALLBACK_INTERVAL_US * EXAMPLE_SINE_WAVE_FREQ_HZ))
|
||||
#define MHZ (1000000)
|
||||
#define CONST_PI (3.1416f) // Constant of PI, used for calculating the sine wave
|
||||
#define EXAMPLE_SIGMA_DELTA_GPIO_NUM (0) // Select GPIO_NUM_0 as the sigma-delta output pin
|
||||
#define EXAMPLE_OVER_SAMPLE_RATE (10 * MHZ) // 10 MHz over sample rate
|
||||
#define EXAMPLE_TIMER_RESOLUTION (1 * MHZ) // 1 MHz timer counting resolution
|
||||
#define EXAMPLE_CALLBACK_INTERVAL_US (100) // 100 us interval of each timer callback
|
||||
#define EXAMPLE_ALARM_COUNT (EXAMPLE_CALLBACK_INTERVAL_US * (EXAMPLE_TIMER_RESOLUTION / MHZ))
|
||||
#define EXAMPLE_SINE_WAVE_FREQ_HZ (100) // 100 Hz sine wave, adjust this value to decide the sine wave frequency
|
||||
#define EXAMPLE_SINE_WAVE_AMPLITUDE (127.0f) // 1 ~ 127, adjust this value to decide the sine wave amplitude
|
||||
#define EXAMPLE_SINE_WAVE_POINT_NUM (MHZ / (EXAMPLE_CALLBACK_INTERVAL_US * EXAMPLE_SINE_WAVE_FREQ_HZ))
|
||||
|
||||
ESP_STATIC_ASSERT(EXAMPLE_SINE_WAVE_POINT_NUM > 1, "Sine wave frequency is too high");
|
||||
ESP_STATIC_ASSERT(EXAMPLE_CALLBACK_INTERVAL_US >= 7, "Timer callback interval is too short");
|
||||
|
||||
@@ -10,6 +10,7 @@ from pytest_embedded import Dut
|
||||
@pytest.mark.esp32s3
|
||||
@pytest.mark.esp32c3
|
||||
@pytest.mark.esp32c6
|
||||
# @pytest.mark.esp32h2 // TODO: IDF-6263, IDF-6242
|
||||
@pytest.mark.generic
|
||||
def test_sdm_dac_example(dut: Dut) -> None:
|
||||
dut.expect(r'sdm_dac: Sigma-delta output is attached to GPIO \w+')
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 9.3 KiB |
@@ -10,6 +10,7 @@ from pytest_embedded import Dut
|
||||
@pytest.mark.esp32s3
|
||||
@pytest.mark.esp32c3
|
||||
@pytest.mark.esp32c6
|
||||
# @pytest.mark.esp32h2 // TODO: IDF-6263
|
||||
@pytest.mark.generic
|
||||
def test_sdm_led_example(dut: Dut) -> None:
|
||||
dut.expect_exact('sdm_led: Install sigma delta channel')
|
||||
|
||||
Reference in New Issue
Block a user