@@ -70,22 +70,24 @@ fn main() -> anyhow::Result<()> {
7070 println ! ( "Configuring MCPWM" ) ;
7171
7272 let peripherals = Peripherals :: take ( ) . unwrap ( ) ;
73- let config = OperatorConfig :: default ( ) . frequency ( 25 . kHz ( ) ) ;
74- let mcpwm = Mcpwm :: new ( peripherals. mcpwm0 . mcpwm ) ?;
75- let mut operator = Operator :: new (
76- peripherals. mcpwm0 . operator0 ,
77- & mcpwm,
78- & config,
79- peripherals. pins . gpio4 ,
80- peripherals. pins . gpio5 ,
81- ) ?;
73+ let timer_config = TimerConfig :: default ( ) . frequency ( 25 . kHz ( ) ) ;
74+ let operator_config = OperatorConfig :: default ( ) ;
75+ let timer = Mcpwm :: new ( peripherals. mcpwm0 . timer , timer_config) ?;
8276
83- println ! ( "Starting duty-cycle loop" ) ;
77+ let timer = timer. into_connection ( )
78+ . attatch_operator0 (
79+ peripherals. mcpwm0 . operator0 ,
80+ operator_config,
81+ peripherals. pins . gpio4 ,
82+ peripherals. pins . gpio5 ,
83+ ) ?;
84+
85+ let ( timer, operator, _, _) = timer. split ( ) ;
8486
85- for x in ( 0 ..10000u16 ) . cycle ( ) {
86- let duty = f32:: from ( x) * 0.01 ;
87+ println ! ( "Starting duty-cycle loop" ) ;
8788
88- if x % 100 == 0 {
89+ for duty in ( 0 ..timer. get_top_value ( ) ) . cycle ( ) {
90+ if duty % 100 == 0 {
8991 println ! ( "Duty {}%" , x / 100 ) ;
9092 }
9193
0 commit comments