File tree 1 file changed +52
-0
lines changed
1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change
1
+ //! Connect an oscilloscope to an IO pin and see the modulation sine wave.
2
+ //!
3
+ //! Also you may connect low-pass filter to SDM output.
4
+ //!
5
+ //! The following wiring is assumed for ESP32:
6
+ //! - SDM pin => GPIO32
7
+ //! The following wiring is assumed for ESP32S2/S3:
8
+ //! - SDM pin => GPIO3
9
+ //! The following wiring is assumed for others:
10
+ //! - SDM pin => GPIO2
11
+
12
+ //% CHIPS: esp32 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
13
+
14
+ #![ no_std]
15
+ #![ no_main]
16
+
17
+ use esp_backtrace as _;
18
+ use esp_hal:: {
19
+ sdm:: Sdm ,
20
+ delay:: Delay ,
21
+ gpio:: Io ,
22
+ prelude:: * ,
23
+ } ;
24
+ use esp_println:: println;
25
+
26
+ #[ entry]
27
+ fn main ( ) -> ! {
28
+ let peripherals = esp_hal:: init ( esp_hal:: Config :: default ( ) ) ;
29
+
30
+ let io = Io :: new ( peripherals. GPIO , peripherals. IO_MUX ) ;
31
+ cfg_if:: cfg_if! {
32
+ if #[ cfg( feature = "esp32" ) ] {
33
+ let modulation_pin = io. pins. gpio32;
34
+ } else if #[ cfg( any( feature = "esp32s2" , feature = "esp32s3" ) ) ] {
35
+ let modulation_pin = io. pins. gpio3;
36
+ } else {
37
+ let modulation_pin = io. pins. gpio2;
38
+ }
39
+ }
40
+
41
+ let mut sdm = Sdm :: new ( peripherals. GPIO_SD ) ;
42
+ let mut sdm_ch = sdm. enable_pin ( modulation_pin, 100 . kHz ( ) ) . unwrap ( ) ;
43
+
44
+ let delay = Delay :: new ( ) ;
45
+
46
+ println ! ( "Sigma-delta modulation is on" ) ;
47
+
48
+ loop {
49
+ sdm_ch. set_pulse_density ( 0 ) ;
50
+ delay. delay_millis ( 1500 ) ;
51
+ }
52
+ }
You can’t perform that action at this time.
0 commit comments