2 * Copyright (C) 2012-2016 Czech Technical University in Prague
4 * Created on: 28.2.2013
9 * This document contains proprietary information belonging to Czech
10 * Technical University in Prague. Passing on and copying of this
11 * document, and communication of its contents is not permitted
12 * without prior written authorization.
17 * This file contains command for reading adc port.
30 * @brief Read values from ADC port
32 * @param[in] cmd_io Pointer to IO stack
33 * @param[in] des Pointer to command descriptor
34 * @param[in] param Parameters of command
35 * @return 0 when OK or error code lower than 0
37 int cmd_do_read_adc1_values(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
39 uint32_t i, min, max; // Cycle control variable
42 if (param[1] == param[0] + 7) { /* Single pin variant */
43 if (sscanf(param[1], "%d", &min) != 1)
44 return -CMDERR_BADPAR;
45 if (min >= PORT_ADC_CHANNELS)
51 max = PORT_ADC_CHANNELS - 1;
53 for (i = min; i <= max; i++) {
54 unsigned d = rpp_adc_get(i+1);
55 double v = port_adc_lsb2volts(d);
56 rpp_sci_printf("ADC%-2d %4d lsb ~ %5.2f V\n", i, d, v);
61 int cmd_do_adc_watch(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
65 rpp_sci_printf("ADC Inputs Test [0-%d]:\r\n", PORT_ADC_CHANNELS - 1);
67 for (i = 0; i < PORT_ADC_CHANNELS; i++)
68 rpp_sci_printf("======");
71 for (i = 0; i < PORT_ADC_CHANNELS; i++)
72 rpp_sci_printf("%5d ", i);
75 // Calculate wait time in OS ticks
76 static const portTickType freq_ticks = 100 /* ms */ / portTICK_RATE_MS;
77 portTickType last_wake_time = xTaskGetTickCount();
79 while (cmd_io->getc(cmd_io) < 0) {
83 for (i = 0; i < PORT_ADC_CHANNELS; i++)
84 rpp_sci_printf("%5d ", rpp_adc_get(i+1));
85 rpp_sci_printf("lsb\n");
86 for (i = 0; i < PORT_ADC_CHANNELS; i++)
87 rpp_sci_printf("%5.2f ", port_adc_lsb2volts(rpp_adc_get(i+1)));
88 rpp_sci_printf("V\r\033[A"); /* Cursor up */
91 vTaskDelayUntil(&last_wake_time, freq_ticks);
93 rpp_sci_printf("\n\n");
100 /** Descriptor of command for adc port reading */
101 cmd_des_t const cmd_des_read_adc1 = {
103 "adcread","Read values from ADC inputs",
104 "### Command syntax ###\n"
108 "### Description ###\n"
110 "This command reads values corresponding to analog voltages on ADC\n"
111 "inputs 0-15 and prints them as decimal numbers as well as converted to\n"
117 " ADC0 2332 lsb ~ 11.66 V\n"
118 " ADC1 2332 lsb ~ 11.66 V\n"
119 " ADC2 107 lsb ~ 0.54 V\n"
120 " ADC3 108 lsb ~ 0.54 V\n"
121 " ADC4 107 lsb ~ 0.54 V\n"
122 " ADC5 108 lsb ~ 0.54 V\n"
123 " ADC6 111 lsb ~ 0.56 V\n"
124 " ADC7 110 lsb ~ 0.55 V\n"
125 " ADC8 109 lsb ~ 0.55 V\n"
126 " ADC9 107 lsb ~ 0.54 V\n"
127 " ADC10 107 lsb ~ 0.54 V\n"
128 " ADC11 110 lsb ~ 0.55 V\n"
129 " ADC12 108 lsb ~ 0.54 V\n"
130 " ADC13 108 lsb ~ 0.54 V\n"
131 " ADC14 108 lsb ~ 0.54 V\n"
132 " ADC15 108 lsb ~ 0.54 V\n",
133 CMD_HANDLER(cmd_do_read_adc1_values), (void *)&cmd_list_adc
136 cmd_des_t const cmd_des_read_adc2 = {
138 "adcread*","Read a value from a single ADC input",
139 "### Command syntax ###\n"
143 "where `<PIN>` is a number in range 0 - 15.\n"
145 "### Description ###\n"
147 "This command reads the value corresponding to analog voltage on an ADC\n"
148 "input and prints it as decimal numbers as well as converted to Volts.\n"
153 " ADC1 2331 lsb ~ 11.66 V\n",
154 CMD_HANDLER(cmd_do_read_adc1_values), (void *)&cmd_list_adc
157 cmd_des_t const cmd_des_adcwatch = {
159 "adcwatch","Watch the values from ADC inputs",
160 "### Command syntax ###\n"
164 "### Description ###\n"
166 "This command reads values corresponding to analog voltages on ADC\n"
167 "inputs 0-15 10 times per second and prints them as decimal numbers (in\n"
168 "lsb units) as well as converted to Volts. The command is ended by any\n"
174 " ADC Inputs Test [0-15]:\n"
175 " =========================================================================================\n"
176 " 0 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n"
177 " 2331 107 108 106 107 110 110 109 107 107 110 109 109 109 109 lsb\n"
178 " 11.66 0.54 0.54 0.53 0.54 0.55 0.55 0.55 0.54 0.54 0.55 0.55 0.55 0.55 0.55 V\n",
179 CMD_HANDLER(cmd_do_adc_watch), (void *)&cmd_list_adc
182 /** List of commands for adc, defined as external */
183 cmd_des_t const *cmd_list_adc[] = {