]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/blobdiff - rpp-test-sw/commands/cmd_adc.c
Fix HDK ADC voltage conversion
[pes-rpp/rpp-test-sw.git] / rpp-test-sw / commands / cmd_adc.c
index 104c4a37842f64f82b5c451d96095d870ff32830..4a389eabd95094c0572cb9e74be8ab6f0fefa1b2 100644 (file)
@@ -1,28 +1,20 @@
 /*
- * Copyright (C) 2012-2013 Czech Technical University in Prague
+ * Copyright (C) 2012-2015 Czech Technical University in Prague
  *
  * Created on: 28.2.2013
  *
  * Authors:
  *     - Michal Horn
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * This document contains proprietary information belonging to Czech
+ * Technical University in Prague. Passing on and copying of this
+ * document, and communication of its contents is not permitted
+ * without prior written authorization.
  *
  * File : cmd_adc.c
  *
  * Abstract:
- *     This file contains command for reading adc port.
+ *      This file contains command for reading adc port.
  *
  */
 
@@ -36,7 +28,7 @@
 
 static double lsb2volts(unsigned lsb)
 {
-       return ((double)lsb + 0.0)*2.5/4095*10;
+       return ((double)lsb + 0.0)*2.5/4095*2;
 }
 
 
@@ -50,145 +42,150 @@ static double lsb2volts(unsigned lsb)
  */
 int cmd_do_read_adc1_values(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
 {
-    uint32_t i, min, max;      // Cycle control variable
-
-    rpp_adc_update();
-    if (param[1] == param[0] + 7) { /* Single pin variant */
-       if (sscanf(param[1], "%d", &min) != 1)
-           return -CMDERR_BADPAR;
-       if (min < 1 || min > 12)
-           return -CMDERR_NODEV;
-       max = min;
-    } else {                   /* All pins */
-       min = 1;
-       max = PORT_ADC_CHANNEL_NUM;
-    }
-    for (i = min-1; i < max; i++) {
-           unsigned d = rpp_adc_get(i+1);
-           double v = lsb2volts(d);
-           rpp_sci_printf((uint8_t *)"ADC%-2d %4d lsb ~ %5.2f V\n", i+1, d, v);
-    }
-    return 0;
+       uint32_t i, min, max;   // Cycle control variable
+
+       rpp_adc_update();
+       if (param[1] == param[0] + 7) { /* Single pin variant */
+               if (sscanf(param[1], "%d", &min) != 1)
+                       return -CMDERR_BADPAR;
+               if (min > 15)
+                       return -CMDERR_NODEV;
+               max = min;
+       }
+       else {              /* All pins */
+               min = 0;
+               max = PORT_ADC_CHANNEL_NUM-1;
+       }
+       for (i = min; i <= max; i++) {
+               unsigned d = rpp_adc_get(i+1);
+               double v = lsb2volts(d);
+               rpp_sci_printf("ADC%-2d %4d lsb ~ %5.2f V\n", i, d, v);
+       }
+       return 0;
 }
 
 int cmd_do_adc_watch(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
 {
-    int i;
-    rpp_sci_printf("ADC Inputs Test [1-12]:\r\n");
-    rpp_sci_printf("=======================================================================\r\n");
+       int i;
 
-    for (i = 1; i < 13; i++)
-           rpp_sci_printf("%5d ", i);
-    rpp_sci_printf("\n");
+       rpp_sci_printf("ADC Inputs Test [0-15]:\r\n");
+       rpp_sci_printf("===============================================================================================\r\n");
 
-    // Calculate wait time in OS ticks
-    static const portTickType freq_ticks = 100 /* ms */ / portTICK_RATE_MS;
-    portTickType last_wake_time = xTaskGetTickCount();
+       for (i = 0; i < 16; i++)
+               rpp_sci_printf("%5d ", i);
+       rpp_sci_printf("\n");
 
-    while(cmd_io->getc(cmd_io) < 0) {
+       // Calculate wait time in OS ticks
+       static const portTickType freq_ticks = 100 /* ms */ / portTICK_RATE_MS;
+       portTickType last_wake_time = xTaskGetTickCount();
 
+       while (cmd_io->getc(cmd_io) < 0) {
         // Update inputs
         rpp_adc_update();
 
-       for (i = 1; i < 13; i++)
-               rpp_sci_printf("%5d ", rpp_adc_get(i));
-       rpp_sci_printf("lsb\n");
-       for (i = 1; i < 13; i++)
-               rpp_sci_printf("%5.2f ", lsb2volts(rpp_adc_get(i)));
-       rpp_sci_printf("V\r\033[A"); /* Cursor up */
+               for (i = 0; i < 16; i++)
+                       rpp_sci_printf("%5d ", rpp_adc_get(i+1));
+               rpp_sci_printf("lsb\n");
+               for (i = 0; i < 16; i++)
+                       rpp_sci_printf("%5.2f ", lsb2volts(rpp_adc_get(i+1)));
+               rpp_sci_printf("V\r\033[A"); /* Cursor up */
 
 
-       vTaskDelayUntil(&last_wake_time, freq_ticks);
-    }
-    rpp_sci_printf("\n\n");
-    return 0;
+               vTaskDelayUntil(&last_wake_time, freq_ticks);
+       }
+       rpp_sci_printf("\n\n");
+       return 0;
 }
 
 
-#endif /* DOCGEN */
+#endif  /* DOCGEN */
 
 /** Descriptor of command for adc port reading */
-cmd_des_t const cmd_des_read_adc1={
-    0, 0,
-    "adcread","Read values from ADC inputs",
-    "### Command syntax ###\n"
-    "\n"
-    "     adcread\n"
-    "\n"
-    "### Description ###\n"
-    "\n"
-    "This command reads values corresponding to analog voltages on ADC\n"
-    "inputs 1-12 and prints them as decimal numbers as well as converted to\n"
-    "Volts.\n"
-    "\n"
-    "### Example ###\n"
-    "\n"
-    "     --> adcread\n"
-    "     ADC1  2332 lsb ~ 11.66 V\n"
-    "     ADC2   107 lsb ~  0.54 V\n"
-    "     ADC3   108 lsb ~  0.54 V\n"
-    "     ADC4   107 lsb ~  0.54 V\n"
-    "     ADC5   108 lsb ~  0.54 V\n"
-    "     ADC6   111 lsb ~  0.56 V\n"
-    "     ADC7   110 lsb ~  0.55 V\n"
-    "     ADC8   109 lsb ~  0.55 V\n"
-    "     ADC9   107 lsb ~  0.54 V\n"
-    "     ADC10  107 lsb ~  0.54 V\n"
-    "     ADC11  110 lsb ~  0.55 V\n"
-    "     ADC12  108 lsb ~  0.54 V\n",
-    CMD_HANDLER(cmd_do_read_adc1_values), (void *)&cmd_list_adc
+cmd_des_t const cmd_des_read_adc1 = {
+       0, 0,
+       "adcread","Read values from ADC inputs",
+       "### Command syntax ###\n"
+       "\n"
+       "     adcread\n"
+       "\n"
+       "### Description ###\n"
+       "\n"
+       "This command reads values corresponding to analog voltages on ADC\n"
+       "inputs 0-15 and prints them as decimal numbers as well as converted to\n"
+       "Volts.\n"
+       "\n"
+       "### Example ###\n"
+       "\n"
+       "     --> adcread\n"
+       "     ADC0  2332 lsb ~ 11.66 V\n"
+       "     ADC1  2332 lsb ~ 11.66 V\n"
+       "     ADC2   107 lsb ~  0.54 V\n"
+       "     ADC3   108 lsb ~  0.54 V\n"
+       "     ADC4   107 lsb ~  0.54 V\n"
+       "     ADC5   108 lsb ~  0.54 V\n"
+       "     ADC6   111 lsb ~  0.56 V\n"
+       "     ADC7   110 lsb ~  0.55 V\n"
+       "     ADC8   109 lsb ~  0.55 V\n"
+       "     ADC9   107 lsb ~  0.54 V\n"
+       "     ADC10  107 lsb ~  0.54 V\n"
+       "     ADC11  110 lsb ~  0.55 V\n"
+       "     ADC12  108 lsb ~  0.54 V\n"
+       "     ADC13  108 lsb ~  0.54 V\n"
+       "     ADC14  108 lsb ~  0.54 V\n"
+       "     ADC15  108 lsb ~  0.54 V\n",
+       CMD_HANDLER(cmd_do_read_adc1_values), (void *)&cmd_list_adc
 };
 
-cmd_des_t const cmd_des_read_adc2={
-    0, 0,
-    "adcread*","Read a value from a single ADC input",
-    "### Command syntax ###\n"
-    "\n"
-    "    adcread<PIN>\n"
-    "\n"
-    "where `<PIN>` is a number in range 1 - 12.\n"
-    "\n"
-    "### Description ###\n"
-    "\n"
-    "This command reads the value corresponding to analog voltage on an ADC\n"
-    "input and prints it as decimal numbers as well as converted to Volts.\n"
-    "\n"
-    "### Example ###\n"
-    "\n"
-    "    --> adcread1\n"
-    "    ADC1  2331 lsb ~ 11.66 V\n",
-    CMD_HANDLER(cmd_do_read_adc1_values), (void *)&cmd_list_adc
+cmd_des_t const cmd_des_read_adc2 = {
+       0, 0,
+       "adcread*","Read a value from a single ADC input",
+       "### Command syntax ###\n"
+       "\n"
+       "    adcread<PIN>\n"
+       "\n"
+       "where `<PIN>` is a number in range 0 - 15.\n"
+       "\n"
+       "### Description ###\n"
+       "\n"
+       "This command reads the value corresponding to analog voltage on an ADC\n"
+       "input and prints it as decimal numbers as well as converted to Volts.\n"
+       "\n"
+       "### Example ###\n"
+       "\n"
+       "    --> adcread1\n"
+       "    ADC1  2331 lsb ~ 11.66 V\n",
+       CMD_HANDLER(cmd_do_read_adc1_values), (void *)&cmd_list_adc
 };
 
-cmd_des_t const cmd_des_adcwatch={
-    0, 0,
-    "adcwatch","Watch the values from ADC inputs",
-    "### Command syntax ###\n"
-    "\n"
-    "    adcwatch\n"
-    "\n"
-    "### Description ###\n"
-    "\n"
-    "This command reads values corresponding to analog voltages on ADC\n"
-    "inputs 1-12 10 times per second and prints them as decimal numbers (in\n"
-    "lsb units) as well as converted to Volts. The command is ended by any\n"
-    "key.\n"
-    "\n"
-    "### Example ###\n"
-    "\n"
-    "    --> adcwatch\n"
-    "    ADC Inputs Test [1-12]:\n"
-    "    =======================================================================\n"
-    "        1     2     3     4     5     6     7     8     9    10    11    12\n"
-    "     2331   107   108   106   107   110   110   109   107   107   110   109 lsb\n"
-    "    11.66  0.54  0.54  0.53  0.54  0.55  0.55  0.55  0.54  0.54  0.55  0.55 V\n",
-    CMD_HANDLER(cmd_do_adc_watch), (void *)&cmd_list_adc
+cmd_des_t const cmd_des_adcwatch = {
+       0, 0,
+       "adcwatch","Watch the values from ADC inputs",
+       "### Command syntax ###\n"
+       "\n"
+       "    adcwatch\n"
+       "\n"
+       "### Description ###\n"
+       "\n"
+       "This command reads values corresponding to analog voltages on ADC\n"
+       "inputs 0-15 10 times per second and prints them as decimal numbers (in\n"
+       "lsb units) as well as converted to Volts. The command is ended by any\n"
+       "key.\n"
+       "\n"
+       "### Example ###\n"
+       "\n"
+       "    --> adcwatch\n"
+       "    ADC Inputs Test [0-15]:\n"
+       "    =========================================================================================\n"
+       "        0     2     3     4     5     6     7     8     9    10    11    12    13    14    15\n"
+       "     2331   107   108   106   107   110   110   109   107   107   110   109   109   109   109 lsb\n"
+       "    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",
+       CMD_HANDLER(cmd_do_adc_watch), (void *)&cmd_list_adc
 };
 
 /** List of commands for adc, defined as external */
-cmd_des_t const *cmd_list_adc[]={
-  &cmd_des_read_adc1,
-  &cmd_des_read_adc2,
-  &cmd_des_adcwatch,
-  NULL
+cmd_des_t const *cmd_list_adc[] = {
+       &cmd_des_read_adc1,
+       &cmd_des_read_adc2,
+       &cmd_des_adcwatch,
+       NULL
 };