44/// Example showcasing the use of the HRTIM peripheral together with a comparator to implement a current fault.
55/// Once the comparator input exceeds the reference set by the DAC, the output is forced low and put into a fault state.
66use cortex_m_rt:: entry;
7+ use fugit:: ExtU32 as _;
78use panic_probe as _;
89use stm32_hrtim:: {
910 compare_register:: HrCompareRegister ,
@@ -18,7 +19,7 @@ use stm32g4xx_hal::{
1819 adc:: AdcClaim ,
1920 comparator:: { self , ComparatorExt , ComparatorSplit } ,
2021 dac:: { Dac3IntSig1 , DacExt , DacOut } ,
21- delay:: SYSTDelayExt ,
22+ delay:: { DelayExt as _ , SYSTDelayExt } ,
2223 gpio:: GpioExt ,
2324 pwr:: PwrExt ,
2425 rcc:: { self , RccExt } ,
@@ -88,8 +89,8 @@ fn main() -> ! {
8889 . polarity ( hal:: pwm:: Polarity :: ActiveHigh )
8990 . finalize ( & mut hr_control) ;
9091
91- // ...with a prescaler of 4 this gives us a HrTimer with a tick rate of 1.2GHz
92- // With max the max period set, this would be 1.2GHz /2^16 ~= 18kHz ...
92+ // ...with a prescaler of 4 this gives us a HrTimer with a tick rate of 960MHz
93+ // With max the max period set, this would be 960MHz /2^16 ~= 15kHz ...
9394 let prescaler = Pscl4 ;
9495
9596 let pin_a = gpioa. pa8 ;
@@ -126,15 +127,15 @@ fn main() -> ! {
126127 out1. enable_rst_event ( & cr1) ; // Set low on compare match with cr1
127128 out1. enable_set_event ( & timer) ; // Set high at new period
128129 cr1. set_duty ( timer. get_period ( ) / 3 ) ;
129- //unsafe {((HRTIM_COMMON::ptr() as *mut u8).offset(0x14) as *mut u32).write_volatile(1); }
130+
130131 out1. enable ( ) ;
131132 timer. start ( & mut hr_control. control ) ;
132133
133134 defmt:: info!( "Started" ) ;
134135
135136 loop {
136137 for _ in 0 ..5 {
137- // delay.delay(500_u32.millis());
138+ delay. delay ( 500_u32 . millis ( ) ) ;
138139 defmt:: info!(
139140 "State: {:?}, comp: {}, is_fault_active: {}, pc1: {}" ,
140141 out1. get_state( ) ,
0 commit comments