File tree Expand file tree Collapse file tree 3 files changed +21
-1
lines changed Expand file tree Collapse file tree 3 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,8 @@ fn main() -> ! {
32
32
let pa0 = gpioa. pa0 . into_analog ( ) ;
33
33
let comp1 = comp1. comparator ( pa1, pa0, Config :: default ( ) , & rcc. clocks ) ;
34
34
let comp1 = comp1. enable ( ) ;
35
+
36
+ // led1 pa1 will be updated manually when to match comp1 value
35
37
let mut led1 = gpioa. pa5 . into_push_pull_output ( ) ;
36
38
37
39
let pa7 = gpioa. pa7 . into_analog ( ) ;
@@ -50,6 +52,7 @@ fn main() -> ! {
50
52
let _comp2 = comp2. enable ( ) . lock ( ) ;
51
53
52
54
loop {
55
+ // Read comp1 output and update led1 accordingly
53
56
match comp1. output ( ) {
54
57
true => led1. set_high ( ) . unwrap ( ) ,
55
58
false => led1. set_low ( ) . unwrap ( ) ,
Original file line number Diff line number Diff line change @@ -25,12 +25,16 @@ fn main() -> ! {
25
25
let mut delay = cp. SYST . delay ( & rcc. clocks ) ;
26
26
27
27
let gpioa = dp. GPIOA . split ( & mut rcc) ;
28
- let dac1ch1 = dp. DAC1 . constrain ( ( gpioa. pa4 , Dac1IntSig1 ) , & mut rcc) ;
29
28
29
+ // Set up DAC to output to pa4 and to internal signal Dac1IntSig1
30
+ // which just so happens is compatible with comp1
31
+ let dac1ch1 = dp. DAC1 . constrain ( ( gpioa. pa4 , Dac1IntSig1 ) , & mut rcc) ;
30
32
let mut dac = dac1ch1. calibrate_buffer ( & mut delay) . enable ( ) ;
31
33
32
34
let ( comp1, _comp2, ..) = dp. COMP . split ( & mut rcc) ;
33
35
let pa1 = gpioa. pa1 . into_analog ( ) ;
36
+
37
+ // Set up comparator with pa1 as positive, and the DAC as negative input
34
38
let comp = comp1. comparator (
35
39
pa1,
36
40
& dac,
@@ -47,6 +51,12 @@ fn main() -> ! {
47
51
let mut dir = Direction :: Upcounting ;
48
52
let mut val = 0 ;
49
53
54
+ // Manually step the DAC's value to produce a triangle wave
55
+ //
56
+ // This will produce a pwm-like signal at pa0 with the duty controlled by pa1
57
+ // where
58
+ // * 0V at p1 => 0% duty
59
+ // * VDDA at p1 => 100% duty
50
60
loop {
51
61
dac. set_value ( val) ;
52
62
match val {
Original file line number Diff line number Diff line change @@ -31,21 +31,28 @@ fn main() -> ! {
31
31
let gpioa = dp. GPIOA . split ( & mut rcc) ;
32
32
let ( dac1ch1, dac1ch2) = dp. DAC1 . constrain ( ( gpioa. pa4 , gpioa. pa5 ) , & mut rcc) ;
33
33
34
+ // dac_manual will have its value set manually
34
35
let mut dac_manual = dac1ch1. calibrate_buffer ( & mut delay) . enable ( ) ;
36
+
37
+ // dac_generator will have its value set automatically from its internal noise generator
35
38
let mut dac_generator = dac1ch2. enable_generator ( GeneratorConfig :: noise ( 11 ) ) ;
36
39
37
40
let mut dir = Direction :: Upcounting ;
38
41
let mut val = 0 ;
39
42
40
43
loop {
44
+ // This will pull out a new value from the noise generator and apply it to the DAC
41
45
dac_generator. trigger ( ) ;
46
+
47
+ // This will manually set the DAC's value
42
48
dac_manual. set_value ( val) ;
43
49
match val {
44
50
0 => dir = Direction :: Upcounting ,
45
51
4095 => dir = Direction :: Downcounting ,
46
52
_ => ( ) ,
47
53
} ;
48
54
55
+ // Step manually set value as a triangle wave
49
56
match dir {
50
57
Direction :: Upcounting => val += 1 ,
51
58
Direction :: Downcounting => val -= 1 ,
You can’t perform that action at this time.
0 commit comments