Changeset 30

Show
Ignore:
Timestamp:
08/14/09 14:29:20 (15 years ago)
Author:
phil
Message:

Gas Meter counting finished, with accumulation timer and debounce timer. Todo: output and locking

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • webserver/example/EnergyMeters/EnergyMeters/ARM7_LPC2368_Rowley/EnergyMeters.hzs

    r28 r30  
    1919  <ProjectSessionItem path="RTOSDemo" name="unnamed" /> 
    2020  <ProjectSessionItem path="RTOSDemo;EnergyMetersEmbedded" name="unnamed" /> 
     21  <ProjectSessionItem path="RTOSDemo;EnergyMetersEmbedded;Demo Source" name="unnamed" /> 
     22  <ProjectSessionItem path="RTOSDemo;EnergyMetersEmbedded;EnergyMeters" name="unnamed" /> 
    2123  <ProjectSessionItem path="RTOSDemo;EnergyMetersEmbedded;System Files" name="unnamed" /> 
     24  <ProjectSessionItem path="RTOSDemo;EnergyMetersEmbedded;uIP Source" name="unnamed" /> 
    2225 </Project> 
    2326 <Register1> 
     
    3841 </TraceWindow> 
    3942 <Watch1> 
    40   <Watches active="0" update="Never" /> 
     43  <Watches active="1" update="Never" > 
     44   <Watchpoint evalMode="2" linenumber="72" numelements="10" evalType="0" radix="-1" name="meterItems" expression="meterItems" filename="d:/energymetersproject/source/energymeters/meters_isrs.c" /> 
     45   <Watchpoint linenumber="64" radix="-1" name="currentTime" expression="currentTime" filename="d:/energymetersproject/source/energymeters/meters_isrs.c" /> 
     46  </Watches> 
    4147 </Watch1> 
    4248 <Watch2> 
     
    4450 </Watch2> 
    4551 <Watch3> 
    46   <Watches active="1" update="Never" > 
     52  <Watches active="0" update="Never" > 
    4753   <Watchpoint evalMode="2" linenumber="0" numelements="10" evalType="0" radix="-1" name="meterItems" expression="meterItems" filename="" /> 
    4854  </Watches> 
     
    5460 </Watch4> 
    5561 <Files> 
    56   <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="C:\Dokumente und Einstellungen\birdy\Lokale Einstellungen\Anwendungsdaten\Rowley Associates Limited\CrossWorks for ARM\packages\targets\Philips_LPC210X\Philips_LPC230X_Startup.s" y="276" path="C:\Dokumente und Einstellungen\birdy\Lokale Einstellungen\Anwendungsdaten\Rowley Associates Limited\CrossWorks for ARM\packages\targets\Philips_LPC210X\Philips_LPC230X_Startup.s" left="0" selected="1" name="unnamed" top="261" /> 
     62  <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="84" debugPath="D:\EnergyMetersProject\Source\EnergyMeters\Meters.c" y="122" path="D:\EnergyMetersProject\Source\EnergyMeters\Meters.c" left="0" selected="0" name="unnamed" top="99" /> 
     63  <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="D:\EnergyMetersProject\EnergyMeters\ARM7_LPC2368_Rowley\main.c" y="113" path="D:\EnergyMetersProject\EnergyMeters\ARM7_LPC2368_Rowley\main.c" left="0" selected="0" name="unnamed" top="101" /> 
     64  <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="D:\EnergyMetersProject\Source\EnergyMeters\Meters_ISRs.c" y="89" path="D:\EnergyMetersProject\Source\EnergyMeters\Meters_ISRs.c" left="0" selected="1" name="unnamed" top="66" /> 
     65  <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="19" debugPath="D:\energymetersproject\source\energymeters\timeConversion.c" y="18" path="D:\energymetersproject\source\energymeters\timeConversion.c" left="0" selected="0" name="unnamed" top="0" /> 
     66  <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="37" debugPath="D:\energymetersproject\source\energymeters\MetersIncludes.h" y="8" path="D:\energymetersproject\source\energymeters\MetersIncludes.h" left="0" selected="0" name="unnamed" top="0" /> 
     67  <SessionOpenFile useTextEdit="1" useBinaryEdit="0" codecName="Latin1" x="0" debugPath="D:\EnergyMetersProject\EnergyMeters\ARM7_LPC2368_Rowley\webserver\httpd-cgi.c" y="0" path="D:\EnergyMetersProject\EnergyMeters\ARM7_LPC2368_Rowley\webserver\httpd-cgi.c" left="0" selected="0" name="unnamed" top="0" /> 
    5768 </Files> 
    5869 <ARMCrossStudioWindow activeProject="EnergyMetersEmbedded" autoConnectTarget="Macraigor Wiggler (20 Pin)" debugSearchFileMap="" fileDialogInitialDirectory="D:\freeRTOSexample\Source\EnergyMeters" fileDialogDefaultFilter="*.c" autoConnectCapabilities="388479" debugSearchPath="" buildConfiguration="ARM Flash Debug" /> 
  • webserver/example/EnergyMeters/Source/EnergyMeters/Meters.c

    r22 r30  
    120120  meterItems[METER_INDEX_GAS].timeLastTick = getEpochTimeWithMs(); /* when did the last tick occur? epoch (seconds) */ 
    121121  meterItems[METER_INDEX_GAS].timeBeforeLastTick = getEpochTimeWithMs(); /* when did the tick before last tick occur? epoch (seconds) */ 
    122   meterItems[METER_INDEX_GAS].valueLastTick = 0;   /* what value did we have at the last tick? */ 
    123   meterItems[METER_INDEX_GAS].valueBeforeLastTick = 1;   /* what value did we have at the tick before the last tick? */ 
     122  meterItems[METER_INDEX_GAS].valueLastTick = 1;   /* what value did we have at the last tick? */ 
     123  meterItems[METER_INDEX_GAS].currentValue = 1; /* same: start value of the meter */ 
     124  meterItems[METER_INDEX_GAS].valueBeforeLastTick = 0;   /* what value did we have at the tick before the last tick? */ 
    124125 
    125126} 
  • webserver/example/EnergyMeters/Source/EnergyMeters/MetersIncludes.h

    r22 r30  
    77#define METER_INDEX_GAS 0 /* index of the gas meter data */ 
    88 
     9#define DEBOUNCE_TICK_THRESHOLD_MS 50 /* when two ticks are less than this time period apart, the second tick is ignored (debouncing) */ 
     10#define ACCUMULATE_TICK_THRESHOLD_SEC 30 /* how long (seconds) should the ticks be accumulated before a new data item is created? */ 
    911 
    1012typedef struct 
     
    1517  portLONG valueLastTick;   /* what value did we have at the last tick? */ 
    1618  portLONG valueBeforeLastTick;   /* what value did we have at the tick before the last tick? */ 
     19  portLONG currentValue;  /* the value of the meter. gets incremented by the ISR */ 
    1720} meterItem; 
    1821 
  • webserver/example/EnergyMeters/Source/EnergyMeters/Meters_ISRs.c

    r22 r30  
    6161void handleGasMeterTick(void) 
    6262{ 
    63   meterItems[METER_INDEX_GAS].timeBeforeLastTick = meterItems[METER_INDEX_GAS].timeLastTick;     /* when did the tick before the last tick occur? */ 
    64   meterItems[METER_INDEX_GAS].timeLastTick = getEpochTimeWithMs(); /* when did the last tick occur? epoch (seconds) */ 
    65   meterItems[METER_INDEX_GAS].valueLastTick = 0;   /* what value did we have at the last tick? */ 
    66   meterItems[METER_INDEX_GAS].valueBeforeLastTick = 1;   /* what value did we have at the tick before the last tick? */ 
     63  unsigned long long currentTime = getEpochTimeWithMs(); /* current epoch time with ms in ms */ 
     64  if (  currentTime > (meterItems[METER_INDEX_GAS].timeLastTick + DEBOUNCE_TICK_THRESHOLD_MS) ) 
     65  { 
     66    /* we have a tick that is not a bounce */ 
     67    meterItems[METER_INDEX_GAS].currentValue++; /* one more tick. always increase the counter */ 
     68 
     69    /* now check if we should accumulate the ticks for this time period so we leave the new data item available long 
     70     * enough on the web page to be read by the server  
     71     */ 
     72    if (  currentTime > ((unsigned long long)meterItems[METER_INDEX_GAS].timeLastTick + ((unsigned long long)ACCUMULATE_TICK_THRESHOLD_SEC * (unsigned long long)1000)) ) 
     73    { 
     74      /* if the last meter tick happened longer than DEBOUNCE_TICK_THRESHOLD_MS ago (i.e. the switch did not just bounce) */ 
     75      meterItems[METER_INDEX_GAS].timeBeforeLastTick = meterItems[METER_INDEX_GAS].timeLastTick;     /* when did the tick before the last tick occur? (epoch in milliseconds) */ 
     76      meterItems[METER_INDEX_GAS].timeLastTick = currentTime; /* when did the last tick occur? (epoch in milliseconds) */ 
     77      meterItems[METER_INDEX_GAS].valueBeforeLastTick = meterItems[METER_INDEX_GAS].valueLastTick;   /* what value did we have at the tick before the last tick? */ 
     78      meterItems[METER_INDEX_GAS].valueLastTick = meterItems[METER_INDEX_GAS].currentValue;   /* what value did we have at the last tick? now one more! */ 
     79      /* at present, valueLastTick and currentValue are the same. This might be different for future versions. */ 
     80    } 
     81    else 
     82    { 
     83      ; /* nothing to do, curentValue was increased already above */ 
     84    } 
     85  } 
     86  else 
     87  { 
     88    ; /* we bounced, ignore this tick */ 
     89  } 
    6790} 
    6891