• Main Page
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

leds.c

Go to the documentation of this file.
00001 /*@{*//*@}*/
00020 
00021 /******************************************************************************/
00022 /* Includes (#include)                                                        */
00023 #include <avr/io.h>
00024 
00025 /* Own header files */
00026 #include "xtypes.h"
00027 #include "global.h"
00028 
00029 
00030 #include "timer.h"
00031 #include "safety.h"
00032 #include "voltage.h"
00033 #include "current.h"
00034 
00035 #define EXPORT
00036   #include "leds.h"
00037 #undef EXPORT
00038 
00039 /******************************************************************************/
00040 /* Constants (#define)                *//*@{*/
00041 
00042 /* Voltage definitions - don't change this unless you know what you're doing! */
00043 
00045 #define VOLT_10V        448U
00046 
00048 #define VOLT_10V5       472U
00049 
00051 #define VOLT_11V        496U
00052 
00054 #define VOLT_11V5       520U
00055 
00057 #define VOLT_12V        544U
00058 
00059 /* Current definitions - don't change this unless you know what you're doing! */
00060 
00062 #define CURR_20A        75U
00063 
00065 #define CURR_15A        56U
00066 
00068 #define CURR_10A        37U
00069 
00071 #define CURR_5A         17U
00072 
00074 #define CURR_2A         8U
00075 
00077 #define CURR_0A         0U
00078 
00079 /* End: Constants (#define)                                             *//*@}*/
00080 /******************************************************************************/
00081 
00082 /******************************************************************************/
00083 /* Macro definitions (#define)           *//*@{*/
00084 /* End: Macro definitions (#define)                                     *//*@}*/
00085 /******************************************************************************/
00086 
00087 /******************************************************************************/
00088 /* Basic types (typedef)                 *//*@{*/
00089 /* End: Basic types (typedef)                                           *//*@}*/
00090 /******************************************************************************/
00091 
00092 /******************************************************************************/
00093 /* Local constants (const)      *//*@{*/
00094 /* End: Local constants (const)                                         *//*@}*/
00095 /******************************************************************************/
00096 
00097 /******************************************************************************/
00098 /* Local variables              *//*@{*/
00099 /* End: Local variables                                                 *//*@}*/
00100 /******************************************************************************/
00101 
00102 /******************************************************************************/
00103 /* Global variables           *//*@{*/
00104 /* End: Global variables                                                *//*@}*/
00105 /******************************************************************************/
00106 
00107 /******************************************************************************/
00108 /* Prototype declarations                                                     */
00109 /* End: Prototype declarations                                                */
00110 /******************************************************************************/
00111 
00112 /******************************************************************************/
00113 /* Local functions             *//*@{*/
00114 /* End: Local functions                                                 *//*@}*/
00115 /******************************************************************************/
00116 
00117 /******************************************************************************/
00118 /* Global functions          *//*@{*/
00119 
00120 /* ****************************************************************************/
00132 /* ****************************************************************************/
00133 void leds_Init (void)
00134 {
00135   LED1_DDR |= (1U << LED1_BIT);
00136   LED2_DDR |= (1U << LED2_BIT);
00137   LED3_DDR |= (1U << LED3_BIT);
00138   LED4_DDR |= (1U << LED4_BIT);
00139   LED5_DDR |= (1U << LED5_BIT);
00140   
00141   MUX_VOLT_DDR |= (1U << MUX_VOLT_BIT);
00142   MUX_CURR_DDR |= (1U << MUX_CURR_BIT);
00143   
00144   LED1_OFF();
00145   LED2_OFF();
00146   LED3_OFF();
00147   LED4_OFF();
00148   LED5_OFF();
00149   
00150   MUX_VOLT();
00151 }
00152 
00153 
00154 /* ***************************************************************************/
00167 /* ****************************************************************************/
00168 void leds_ShowVoltage(void)
00169 {
00170   UINT16 u16Help;
00171   
00172   u16Help = voltage_GetAvg();
00173   
00174   MUX_VOLT();
00175 
00176   if((safety_GetCondition() & COND_VOLT_ERR) != 0U)
00177   {
00178     /* all LED flashing in case of a voltage error condidtion */
00179     if((timer_GetSystemTime() & 256UL) == 0UL)
00180     {
00181       ALL_LEDS_ON();
00182     }
00183     else
00184     {
00185       ALL_LEDS_OFF();
00186     }
00187   }
00188   else 
00189   {
00190     if(u16Help >= VOLT_10V)
00191     {
00192       LED1_ON();
00193     }
00194     else
00195     {
00196       LED1_OFF();
00197     }
00198     
00199     if(u16Help >= VOLT_10V5)
00200     {
00201       LED2_ON();
00202     }
00203     else
00204     {
00205       LED2_OFF();
00206     }
00207     
00208     if(u16Help >= VOLT_11V)
00209     {
00210       LED3_ON();
00211     }
00212     else
00213     {
00214       LED3_OFF();
00215     }
00216     
00217     if(u16Help >= VOLT_11V5)
00218     {
00219       LED4_ON();
00220     }
00221     else
00222     {
00223       LED4_OFF();
00224     }
00225     
00226     if(u16Help >= VOLT_12V)
00227     {
00228       LED5_ON();
00229     }
00230     else
00231     {
00232       LED5_OFF();
00233     }
00234   }
00235 }
00236 
00237 
00238 /* ***************************************************************************/
00251 /* ****************************************************************************/
00252 void leds_ShowCurrent(void)
00253 {
00254   UINT16 u16Help;
00255   
00256   u16Help = current_GetAvg();
00257   
00258   MUX_CURR();
00259   
00260   if(safety_GetCondition() != COND_OK)
00261   {
00262     if((timer_GetSystemTime() & 256UL) == 0UL)
00263     {
00264       if ((safety_GetCondition() & COND_VOLT_WARN) != 0U)
00265       {
00266         /* LED5 indicates a voltage warning */
00267         LED5_ON();
00268       }
00269       
00270       if ((safety_GetCondition() & COND_VOLT_ERR) != 0U)
00271       {
00272         /* LED5 will also be flashing on voltage error */
00273         LED5_ON();
00274       }
00275       
00276       if ((safety_GetCondition() & COND_CURR_WARN) != 0U)
00277       {
00278         /* LED1 indicates a current warning */
00279         LED5_ON();
00280       }
00281       
00282       if ((safety_GetCondition() & COND_CURR_ERR) != 0U)
00283       {
00284         /* LED2 indicates a current error */
00285         LED2_ON();
00286       }
00287       
00288       if ((safety_GetCondition() & COND_TEMP_WARN) != 0U)
00289       {
00290         /* LED3 indicates a temperature warning */
00291         LED3_ON();
00292       }
00293       
00294       if ((safety_GetCondition() & COND_TEMP_ERR) != 0U)
00295       {
00296         /* LED4 indicates a temperature error */
00297         LED4_ON();
00298       }
00299     }
00300     else
00301     {
00302       ALL_LEDS_OFF();
00303     }
00304   }
00305   else
00306   {
00307     if(u16Help >= CURR_20A)
00308     {
00309       LED5_ON();
00310     }
00311     else
00312     {
00313       LED5_OFF();
00314     }
00315     
00316     if(u16Help >= CURR_15A)
00317     {
00318       LED4_ON();
00319     }
00320     else
00321     {
00322       LED4_OFF();
00323     }
00324     
00325     if(u16Help >= CURR_10A)
00326     {
00327       LED3_ON();
00328     }
00329     else
00330     {
00331       LED3_OFF();
00332     }
00333     
00334     if(u16Help >= CURR_5A)
00335     {
00336       LED2_ON();
00337     }
00338     else
00339     {
00340       LED2_OFF();
00341     }
00342     
00343     if(u16Help > CURR_0A)
00344     {
00345       LED1_ON();
00346     }
00347     else
00348     {
00349       LED1_OFF();
00350     }
00351   }
00352 }
00353 
00354 /* End: Global functions                                                *//*@}*/
00355 /******************************************************************************/
00356 
00357 /**** Last line of code                                                    ****/
00358 
00359 

Generated on Sun Jan 23 2011 14:05:40 for ULA replacement firmware by  doxygen 1.7.2