@@ -8,6 +8,7 @@ use crate::gpio::*;
8
8
use crate :: rcc:: Rcc ;
9
9
use crate :: stm32:: comp:: { COMP1_CSR , COMP2_CSR } ;
10
10
use crate :: stm32:: { COMP , EXTI } ;
11
+ use crate :: time:: Hertz ;
11
12
12
13
pub struct COMP1 {
13
14
_rb : PhantomData < ( ) > ,
@@ -231,6 +232,7 @@ dac_input!(COMP2, dac::Channel2<dac::Enabled>, 0b0101);
231
232
232
233
pub struct Comparator < C > {
233
234
regs : C ,
235
+ pclk : Hertz ,
234
236
}
235
237
236
238
pub trait ComparatorExt < COMP > {
@@ -262,6 +264,9 @@ macro_rules! comparator_ext {
262
264
) {
263
265
positive_input. setup( & self . regs) ;
264
266
negative_input. setup( & self . regs) ;
267
+ // Delay for scaler voltage bridge initialization for certain negative inputs
268
+ let voltage_scaler_delay = self . pclk. 0 / ( 1_000_000 / 200 ) ; // 200us
269
+ cortex_m:: asm:: delay( voltage_scaler_delay) ;
265
270
self . regs. csr( ) . modify( |_, w| unsafe {
266
271
w. hyst( )
267
272
. bits( config. hysteresis as u8 )
@@ -272,7 +277,6 @@ macro_rules! comparator_ext {
272
277
. winout( )
273
278
. bit( config. output_xor)
274
279
} ) ;
275
- // TODO: Delay for comp scaler bridge voltage stabilization?
276
280
}
277
281
278
282
fn output( & self ) -> bool {
@@ -281,7 +285,6 @@ macro_rules! comparator_ext {
281
285
282
286
fn enable( & self ) {
283
287
self . regs. csr( ) . modify( |_, w| w. en( ) . set_bit( ) ) ;
284
- // TODO: Startup delay?
285
288
}
286
289
287
290
fn disable( & self ) {
@@ -425,12 +428,17 @@ pub fn split(_comp: COMP, rcc: &mut Rcc) -> (Comparator<COMP1>, Comparator<COMP2
425
428
rcc. rb . apbrstr2 . modify ( |_, w| w. syscfgrst ( ) . set_bit ( ) ) ;
426
429
rcc. rb . apbrstr2 . modify ( |_, w| w. syscfgrst ( ) . clear_bit ( ) ) ;
427
430
431
+ // Used to calculate delays for initialization
432
+ let pclk = rcc. clocks . apb_clk ;
433
+
428
434
(
429
435
Comparator {
430
436
regs : COMP1 { _rb : PhantomData } ,
437
+ pclk,
431
438
} ,
432
439
Comparator {
433
440
regs : COMP2 { _rb : PhantomData } ,
441
+ pclk,
434
442
} ,
435
443
)
436
444
}
0 commit comments