Skip to content

Commit 61bbec8

Browse files
committed
Add periodm period/width/duty cycle measuring module
1 parent c67fb6e commit 61bbec8

6 files changed

Lines changed: 550 additions & 7 deletions

File tree

docs/man/man9/hostmot2.9

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ The valid entries in the format string are:
9292
[num_pwmgens=\fIN\fB]
9393
[num_3pwmgens=\fIN\fB]
9494
[num_oneshots=\fIN\fB]
95+
[num_periodms=\fIN\fB]
9596
[num_rcpwmgens=\fIN\fB]
9697
[num_stepgens=\fIN\fB]
9798
[stepgen_width=\fIN\fB]
@@ -855,6 +856,66 @@ These monitor the filtered inputs.
855856
(bit rw) swtrigger1,swtrigger2
856857
software trigger inputs to trigger timer1 and timer2.
857858

859+
.SS periodm
860+
The periodm is a period/width/duty cycle measuring module. It can measure period, frequency,
861+
pulse width and duty cycle. It can also average readings for noise filering.
862+
863+
Pins:
864+
865+
.TP
866+
(float r) period_us
867+
Input period in microseconds.
868+
869+
.TP
870+
(float r) width_us
871+
Input pulse width in microseconds.
872+
873+
.TP
874+
(float r) duty_cycle
875+
Input duty cycle (width/period) scaling and offset are changeable.
876+
877+
.TP
878+
(float rw) duty_cycle_scale
879+
Sets the scale of the duty cycle value, default is 100.
880+
881+
.TP
882+
(float rw) duty_cycle_offset
883+
Sets an offset to the duty cycle value, added after scaling. Default is 0.
884+
885+
.TP
886+
(float rw) averages
887+
Number of periods/widths to average. From 1 to 4095. Update rate of period, width, duty cycle, and frequency
888+
will be input frequency/averages.
889+
890+
.TP
891+
(float r) frequency
892+
Input frequency in Hz.
893+
894+
.TP
895+
(float w) minimum_frequency
896+
Minimum input frequency in Hz, if input frequency is lower than this threshold, the valid bit will be cleared.
897+
898+
.TP
899+
(float w) filtertc_us
900+
The periodm input in conditioned with a digital filter for noise rejection. The time constant
901+
of this filter is settable via this pin in units of microseconds. Pulses shorter than this time
902+
constant will not be recognized.
903+
904+
.TP
905+
(bit out) valid
906+
The valid output bit is true when the input signal is present and the input frequency exceeds the minimum frequency setting.
907+
908+
.TP
909+
(bit in) invert
910+
The invert bit sets the input polarity, when false, the input is direct which means the input high time
911+
determines the width. When set true, the input is inverted so the input low time determines the width.
912+
913+
.TP
914+
(bit out) input_status
915+
The input_status bit reads the real time filtered input status (affected by invert pin).
916+
917+
918+
858919
.SS rcpwmgen
859920
The rcpwmgen is a simple PWM generator optimized for use with standard RC servos that use pulse width to determine position.
860921
rcpwmgens have names like "hm2_\fI<BoardType>\fR.\fI<BoardNum>\fR.rcpwmgen.\fI<Instance>\fR" where <Instance> is a 2-digit number.

src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,7 @@ hostmot2-objs := \
10231023
hal/drivers/mesa-hostmot2/pktuart.o \
10241024
hal/drivers/mesa-hostmot2/pwmgen.o \
10251025
hal/drivers/mesa-hostmot2/oneshot.o \
1026+
hal/drivers/mesa-hostmot2/periodm.o \
10261027
hal/drivers/mesa-hostmot2/raw.o \
10271028
hal/drivers/mesa-hostmot2/rcpwmgen.o \
10281029
hal/drivers/mesa-hostmot2/resolver.o \

src/hal/drivers/mesa-hostmot2/hostmot2.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ static void hm2_read(void *void_hm2, long period) {
115115
hm2_bspi_process_tram_read(hm2, period);
116116
hm2_absenc_process_tram_read(hm2, period);
117117
hm2_oneshot_process_tram_read(hm2);
118+
hm2_periodm_process_tram_read(hm2);
118119
//UARTS PktUARTS need to be explicitly handled by an external component
119120

120121
hm2_tp_pwmgen_process_read(hm2); // check the status of the fault bit
@@ -137,6 +138,7 @@ static void hm2_write(void *void_hm2, long period) {
137138
hm2_ioport_gpio_prepare_tram_write(hm2);
138139
hm2_pwmgen_prepare_tram_write(hm2);
139140
hm2_oneshot_prepare_tram_write(hm2);
141+
hm2_periodm_prepare_tram_write(hm2);
140142
hm2_rcpwmgen_prepare_tram_write(hm2);
141143
hm2_inmux_prepare_tram_write(hm2);
142144
hm2_inm_prepare_tram_write(hm2);
@@ -146,6 +148,7 @@ static void hm2_write(void *void_hm2, long period) {
146148
hm2_bspi_prepare_tram_write(hm2, period);
147149
hm2_ssr_prepare_tram_write(hm2);
148150
hm2_outm_prepare_tram_write(hm2);
151+
149152
//UARTS need to be explicitly handled by an external component
150153
hm2_tram_write(hm2);
151154

@@ -155,6 +158,7 @@ static void hm2_write(void *void_hm2, long period) {
155158
hm2_watchdog_write(hm2, period); // in case the user has written to the watchdog.timeout_ns param
156159
hm2_pwmgen_write(hm2); // update pwmgen registers if needed
157160
hm2_oneshot_write(hm2); // update oneshot registers if needed
161+
hm2_periodm_write(hm2); // update periodm registers if needed
158162
hm2_rcpwmgen_write(hm2); // update rcpwmgen registers if needed
159163
hm2_inmux_write(hm2); // update inmux control register if needed
160164
hm2_inm_write(hm2); // update inm control register if needed
@@ -321,6 +325,7 @@ const char *hm2_get_general_function_name(int gtag) {
321325
case HM2_GTAG_DPAINTER: return "Data Painter";
322326
case HM2_GTAG_SSR: return "SSR";
323327
case HM2_GTAG_ONESHOT: return "OneShot";
328+
case HM2_GTAG_PERIODM: return "PeriodM";
324329

325330
default: {
326331
static char unknown[100];
@@ -400,6 +405,7 @@ static int hm2_parse_config_string(hostmot2_t *hm2, char *config_string) {
400405
hm2->config.num_ssrs = -1;
401406
hm2->config.num_outms = -1;
402407
hm2->config.num_oneshots = -1;
408+
hm2->config.num_periodms = -1;
403409
hm2->config.enable_raw = 0;
404410
hm2->config.firmware = NULL;
405411

@@ -462,6 +468,10 @@ static int hm2_parse_config_string(hostmot2_t *hm2, char *config_string) {
462468
token += 13;
463469
hm2->config.num_oneshots = simple_strtol(token, NULL, 0);
464470

471+
} else if (strncmp(token, "num_periodms=", 13) == 0) {
472+
token += 13;
473+
hm2->config.num_periodms = simple_strtol(token, NULL, 0);
474+
465475
} else if (strncmp(token, "num_ssrs=", 9) == 0) {
466476
token += 9;
467477
hm2->config.num_ssrs = simple_strtol(token, NULL, 0);
@@ -558,6 +568,7 @@ static int hm2_parse_config_string(hostmot2_t *hm2, char *config_string) {
558568
HM2_DBG(" num_inms=%d\n", hm2->config.num_inms);
559569
HM2_DBG(" num_outms=%d\n", hm2->config.num_outms);
560570
HM2_DBG(" num_oneshots=%d\n", hm2->config.num_oneshots);
571+
HM2_DBG(" num_periodms=%d\n", hm2->config.num_periodms);
561572
HM2_DBG(" num_ssrs=%d\n", hm2->config.num_ssrs);
562573
HM2_DBG(" num_xy2mods=%d\n", hm2->config.num_xy2mods);
563574
HM2_DBG(" num_3pwmgens=%d\n", hm2->config.num_tp_pwmgens);
@@ -1062,6 +1073,10 @@ static int hm2_parse_module_descriptors(hostmot2_t *hm2) {
10621073
md_accepted = hm2_oneshot_parse_md(hm2, md_index);
10631074
break;
10641075

1076+
case HM2_GTAG_PERIODM:
1077+
md_accepted = hm2_periodm_parse_md(hm2, md_index);
1078+
break;
1079+
10651080
case HM2_GTAG_RCPWMGEN:
10661081
md_accepted = hm2_rcpwmgen_parse_md(hm2, md_index);
10671082
break;
@@ -1140,6 +1155,7 @@ static void hm2_cleanup(hostmot2_t *hm2) {
11401155
hm2_ssr_cleanup(hm2);
11411156
hm2_outm_cleanup(hm2);
11421157
hm2_oneshot_cleanup(hm2);
1158+
hm2_periodm_cleanup(hm2);
11431159
hm2_rcpwmgen_cleanup(hm2);
11441160

11451161
// free all the tram entries
@@ -1162,6 +1178,7 @@ void hm2_print_modules(hostmot2_t *hm2) {
11621178
hm2_ssr_print_module(hm2);
11631179
hm2_outm_print_module(hm2);
11641180
hm2_oneshot_print_module(hm2);
1181+
hm2_periodm_print_module(hm2);
11651182
hm2_watchdog_print_module(hm2);
11661183
hm2_inmux_print_module(hm2);
11671184
hm2_inm_print_module(hm2);
@@ -1826,6 +1843,7 @@ void hm2_force_write(hostmot2_t *hm2) {
18261843
hm2_inm_force_write(hm2);
18271844
hm2_xy2mod_force_write(hm2);
18281845
hm2_oneshot_force_write(hm2);
1846+
hm2_periodm_force_write(hm2);
18291847

18301848
// NOTE: It's important that the SSR is written *after* the
18311849
// ioport is written. Initialization of the SSR requires that

src/hal/drivers/mesa-hostmot2/hostmot2.h

Lines changed: 75 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
#define HM2_GTAG_SSR (195)
134134
#define HM2_GTAG_SMARTSERIALB (198) // smart-serial with 224 data bits
135135
#define HM2_GTAG_ONESHOT (199) // One shot
136+
#define HM2_GTAG_PERIODM (200) // Period module
136137

137138

138139
//
@@ -649,6 +650,60 @@ typedef struct {
649650

650651
} hm2_oneshot_t;
651652

653+
//
654+
// period module
655+
//
656+
657+
658+
typedef struct {
659+
660+
struct {
661+
662+
struct {
663+
hal_float_t *period;
664+
hal_float_t *width;
665+
hal_float_t *dutycycle;
666+
hal_float_t *frequency;
667+
hal_float_t *filtertc;
668+
hal_float_t *dutyscale;
669+
hal_float_t *dutyoffset;
670+
hal_float_t *minfreq;
671+
hal_u32_t *averages;
672+
hal_bit_t *polarity;
673+
hal_bit_t *valid;
674+
hal_bit_t *input;
675+
} pin;
676+
677+
} hal;
678+
679+
} hm2_periodm_instance_t;
680+
681+
682+
683+
typedef struct {
684+
int num_instances;
685+
hm2_periodm_instance_t *instance;
686+
687+
rtapi_u32 clock_frequency;
688+
rtapi_u8 version;
689+
690+
rtapi_u32 mode_read_addr;
691+
rtapi_u32 *mode_read_reg;
692+
693+
rtapi_u32 mode_write_addr;
694+
rtapi_u32 *mode_write_reg;
695+
696+
rtapi_u32 limit_addr;
697+
rtapi_u32 *limit_reg;
698+
699+
rtapi_u32 period_addr;
700+
rtapi_u32 *period_reg;
701+
702+
rtapi_u32 width_addr;
703+
rtapi_u32 *width_reg;
704+
705+
} hm2_periodm_t;
706+
652707
//
653708
// rcpwmgen pwmgen optimized for RC servos
654709
//
@@ -1576,6 +1631,7 @@ typedef struct {
15761631
int num_ssrs;
15771632
int num_outms;
15781633
int num_oneshots;
1634+
int num_periodms;
15791635
char sserial_modes[4][8];
15801636
int enable_raw;
15811637
char *firmware;
@@ -1626,6 +1682,7 @@ typedef struct {
16261682
hm2_ssr_t ssr;
16271683
hm2_outm_t outm;
16281684
hm2_oneshot_t oneshot;
1685+
hm2_periodm_t periodm;
16291686

16301687
hm2_raw_t *raw;
16311688

@@ -1786,6 +1843,17 @@ void hm2_oneshot_force_write(hostmot2_t *hm2);
17861843
void hm2_oneshot_prepare_tram_write(hostmot2_t *hm2);
17871844
void hm2_oneshot_process_tram_read(hostmot2_t *hm2);
17881845

1846+
//
1847+
// periodm functions
1848+
//
1849+
int hm2_periodm_parse_md(hostmot2_t *hm2, int md_index);
1850+
void hm2_periodm_print_module(hostmot2_t *hm2);
1851+
void hm2_periodm_cleanup(hostmot2_t *hm2);
1852+
void hm2_periodm_write(hostmot2_t *hm2);
1853+
void hm2_periodm_force_write(hostmot2_t *hm2);
1854+
void hm2_periodm_prepare_tram_write(hostmot2_t *hm2);
1855+
void hm2_periodm_process_tram_read(hostmot2_t *hm2);
1856+
17891857
//
17901858
// rcpwmgen functions
17911859
//
@@ -1863,8 +1931,8 @@ int hm2_bspi_write_chan(char* name, int chan, rtapi_u32 val);
18631931
int hm2_allocate_bspi_tram(char* name);
18641932
int hm2_tram_add_bspi_frame(char *name, int chan, rtapi_u32 **wbuff, rtapi_u32 **rbuff);
18651933
int hm2_bspi_setup_chan(char *name, int chan, int cs, int bits, double mhz,
1866-
int delay, int cpol, int cpha, int noclear, int noecho,
1867-
int samplelate);
1934+
int delay, int cpol, int cpha, int noclear, int noecho,
1935+
int samplelate);
18681936
int hm2_bspi_set_read_function(char *name, int (*func)(void *subdata), void *subdata);
18691937
int hm2_bspi_set_write_function(char *name, int (*func)(void *subdata), void *subdata);
18701938

@@ -1996,11 +2064,11 @@ void hm2_outm_print_module(hostmot2_t *hm2);
19962064
// ONESHOT functions
19972065
//
19982066

1999-
int hm2_oneshot_parse_md(hostmot2_t *hm2, int md_index);
2000-
void hm2_oneshot_cleanup(hostmot2_t *hm2);
2001-
void hm2_oneshot_force_write(hostmot2_t *hm2);
2002-
void hm2_oneshot_prepare_tram_write(hostmot2_t *hm2);
2003-
void hm2_oneshot_print_module(hostmot2_t *hm2);
2067+
//int hm2_oneshot_parse_md(hostmot2_t *hm2, int md_index);
2068+
//void hm2_oneshot_cleanup(hostmot2_t *hm2);
2069+
//void hm2_oneshot_force_write(hostmot2_t *hm2);
2070+
//void hm2_oneshot_prepare_tram_write(hostmot2_t *hm2);
2071+
//void hm2_oneshot_print_module(hostmot2_t *hm2);
20042072

20052073

20062074
//

0 commit comments

Comments
 (0)