Čeština / English
Login

SVN Repository / Prohlížení

Aktuální adresář: FITkit / trunk / apps / demo_msp / voltage_generator / mcu /

main.c

   1  /*******************************************************************************
   2     main: main for 'demo_msp_voltage_generator' app
   3     Copyright (C) 2009 Brno University of Technology,
   4                        Faculty of Information Technology
   5     Author(s): Josef Strnadel <strnadel AT stud.fit.vutbr.cz>
   6  
   7     LICENSE TERMS
   8  
   9     Redistribution and use in source and binary forms, with or without
  10     modification, are permitted provided that the following conditions
  11     are met:
  12     1. Redistributions of source code must retain the above copyright
  13        notice, this list of conditions and the following disclaimer.
  14     2. Redistributions in binary form must reproduce the above copyright
  15        notice, this list of conditions and the following disclaimer in
  16        the documentation and/or other materials provided with the
  17        distribution.
  18     3. All advertising materials mentioning features or use of this software
  19        or firmware must display the following acknowledgement:
  20  
  21          This product includes software developed by the University of
  22          Technology, Faculty of Information Technology, Brno and its
  23          contributors.
  24  
  25     4. Neither the name of the Company nor the names of its contributors
  26        may be used to endorse or promote products derived from this
  27        software without specific prior written permission.
  28  
  29     This software or firmware is provided ``as is'', and any express or implied
  30     warranties, including, but not limited to, the implied warranties of
  31     merchantability and fitness for a particular purpose are disclaimed.
  32     In no event shall the company or contributors be liable for any
  33     direct, indirect, incidental, special, exemplary, or consequential
  34     damages (including, but not limited to, procurement of substitute
  35     goods or services; loss of use, data, or profits; or business
  36     interruption) however caused and on any theory of liability, whether
  37     in contract, strict liability, or tort (including negligence or
  38     otherwise) arising in any way out of the use of this software, even
  39     if advised of the possibility of such damage.
  40  
  41     $Id$
  42  
  43  
  44  *******************************************************************************/
  45  
  46  #include <fitkitlib.h>
  47  #include <lcd/display.h>
  48  
  49  #include <stdio.h>
  50  #include <stdlib.h>
  51  #include <string.h>
  52  
  53  /*
  54   * ----------------------------------------------------------------------------
  55   */
  56  
  57  const int mV_MIN = 0;
  58  const int mV_MAX = 2500;
  59  
  60  int mili_volts = 2500;          // hodnota mV
  61  unsigned char str_tmp[MAX_COMMAND_LEN+1];
  62  void get_data(unsigned char *str, int from);
  63  
  64  /*******************************************************************************
  65   * Vypis uzivatelske napovedy (funkce se vola pri vykonavani prikazu "help")
  66  *******************************************************************************/
  67  void print_user_help(void)
  68  {
  69    term_send_str_crlf("Napoveda pro generator napeti:");
  70    term_send_str_crlf(" mV x ... zmena amplitudy napeti na x [mV]");
  71    term_send_str("      x je mozno zadavat v rozmezi ");
  72    sprintf(str_tmp, "%d (mV_MIN) az %d (mV_MAX)", mV_MIN, mV_MAX);
  73    term_send_str_crlf(str_tmp);
  74    term_send_str_crlf("");
  75    term_send_str_crlf("Napeti je meritelne mezi vyvodem 31 (konektoru JP9) a zemi FITkitu");
  76  }
  77  
  78  /*******************************************************************************
  79   * Dekodovani a vykonani uzivatelskych prikazu
  80  *******************************************************************************/
  81  unsigned char decode_user_cmd(char *UString, char *String)
  82  {
  83    if (strlen(UString)>=4)  // volba napeti [mV]
  84  	{
  85  	   if((UString[0] == 'M') && (UString[1] == 'V') && (UString[2] == ' '))
  86  	   {
  87          get_data(String, 3);  // do str_tmp ulozi UString od 4. znaku dal
  88      	  mili_volts = atoi(str_tmp);
  89  
  90      	  if(mili_volts < mV_MIN)
  91      	  {
  92            term_send_str("Napeti zadano pod dolni mez napeti a proto bylo prenastaveno na jeji hodnotu (mV_MIN = ");
  93            sprintf(str_tmp, "%d [mV])", mV_MIN);
  94            term_send_str_crlf(str_tmp);
  95            mili_volts = mV_MIN;
  96          }
  97          else if(mili_volts > mV_MAX)
  98      	  {
  99            term_send_str("Napeti zadano nad horni mez napeti a proto bylo prenastaveno na jeji hodnotu (mV_MAX = ");
 100            sprintf(str_tmp, "%d [mV])", mV_MAX);
 101            term_send_str_crlf(str_tmp);
 102            mili_volts = mV_MAX;
 103          }
 104  
 105          sprintf(str_tmp, "Napeti: %d mV", mili_volts);
 106          LCD_write_string(str_tmp);
 107          term_send_str_crlf(str_tmp);
 108  
 109          DAC12_0DAT = 4095*((double)mili_volts/(mV_MAX - mV_MIN));   // preved mV na 12-bitovy vzorek
 110      }
 111      else { return (CMD_UNKNOWN); }
 112    }
 113  	else { return (CMD_UNKNOWN); }
 114  
 115    return USER_COMMAND;
 116  }
 117  
 118  /*******************************************************************************
 119   * Inicializace periferii/komponent po naprogramovani FPGA
 120  *******************************************************************************/
 121  void fpga_initialized()
 122  {
 123     LCD_init();
 124     LCD_append_string("Volt-generator");
 125     LCD_send_cmd(LCD_DISPLAY_ON_OFF | LCD_DISPLAY_ON | LCD_CURSOR_OFF, 0);  // vypni kurzor
 126  
 127    term_send_str_crlf("Napeti, ktere chcete generovat, nastavte pomoci prikazu mV (viz help).");
 128    term_send_str_crlf("Napeti je meritelne mezi vyvodem 31 (konektoru JP9) a zemi FITkitu");
 129  }
 130  
 131  
 132  /*******************************************************************************
 133   * Hlavni funkce
 134  *******************************************************************************/
 135  int main(void)
 136  {
 137    initialize_hardware();
 138    WDTCTL = WDTPW + WDTHOLD;	 // zastav watchdog
 139  
 140    // nastaveni DAC
 141    ADC12CTL0 |= 0x0060;    // nastaveni referencniho napeti z ADC na 2,5 V
 142    DAC12_0CTL |= 0x0060;   // nastaveni kontrolniho registru DAC (12-bitovy rezim, medium speed)
 143    DAC12_0CTL |= 0x100;    // referencni napeti nasobit 1x
 144    DAC12_0DAT = 0;         // vynulovani vystupni hodnoty DAC
 145  
 146    // hlavni smycka
 147    while (1)
 148  	{
 149      terminal_idle();      // obsluha terminalu
 150    }
 151  }
 152  
 153  /*******************************************************************************
 154   * Funkce ulozi do str_tmp retezec str od znaku from do konce
 155  *******************************************************************************/
 156  void get_data(unsigned char *str, int from)
 157  {
 158  	int i, j = 0;
 159  	for (i = from; i < strlen(str); i++){	str_tmp[j++] = str[i]; }
 160  	str_tmp[j] = 0;
 161  }
 162  
 163  
Zobrazeno: 595847x Naposledy: 22.1.2022 09:49:21