File tree Expand file tree Collapse file tree 3 files changed +37
-3
lines changed
Expand file tree Collapse file tree 3 files changed +37
-3
lines changed Original file line number Diff line number Diff line change 88int main ()
99{
1010 stdio_init_all ();
11-
11+
1212 servo_init ();
13+ servo_clock_auto ();
14+
1315 servo_attach (A );
1416 servo_attach (B );
1517
Original file line number Diff line number Diff line change 44#include "pico/stdlib.h"
55
66int servo_init ();
7+ int servo_clock_auto ();
8+ int servo_clock_source (uint );
9+ int servo_clock_manual (uint );
710int servo_attach (uint );
811int servo_enable ();
912int servo_move_to (uint , uint );
Original file line number Diff line number Diff line change @@ -49,11 +49,40 @@ int servo_init()
4949 memset (servo_pos , 0 , 32 * sizeof (uint ));
5050 memset (servo_pos_buf , 0 , 16 * sizeof (uint ));
5151
52- clkdiv = (float )frequency_count_khz (CLOCKS_FC0_SRC_VALUE_PLL_SYS_CLKSRC_PRIMARY ) * 1000.f / (FREQ * WRAP );
52+ irq_set_exclusive_handler (PWM_IRQ_WRAP , wrap_cb );
53+
54+ return 0 ;
55+ }
56+
57+ int servo_clock_auto ()
58+ {
59+ return servo_clock_source (CLOCKS_FC0_SRC_VALUE_PLL_SYS_CLKSRC_PRIMARY );
60+ }
61+
62+ int servo_clock_source (uint src )
63+ {
64+ clkdiv = (float )frequency_count_khz (src ) * 1000.f / (FREQ * WRAP );
65+ if (clkdiv == 0 )
66+ {
67+ return 1 ;
68+ }
5369 min = 0.025f * WRAP ;
5470 max = 0.125f * WRAP ;
5571
56- irq_set_exclusive_handler (PWM_IRQ_WRAP , wrap_cb );
72+ return 0 ;
73+ }
74+
75+ int servo_clock_manual (uint freq )
76+ {
77+ clkdiv = (float )freq * 1000.f / (FREQ * WRAP );
78+ if (clkdiv == 0 )
79+ {
80+ return 1 ;
81+ }
82+ min = 0.025f * WRAP ;
83+ max = 0.125f * WRAP ;
84+
85+ return 0 ;
5786}
5887
5988int servo_attach (uint pin )
You can’t perform that action at this time.
0 commit comments