Charles Young's development fork. Going forward I only want to push mature code to main repository.

Dependencies:   mbed

Fork of GEO_COUNTER_L432KC by Geo Electronics "Geo Counter"

Committer:
Charles David Young
Date:
Fri Sep 14 16:54:32 2018 -0700
Revision:
78:0fd2f71c2d64
Parent:
77:87aac94b235a
Child:
79:5cdbe0d2adbb
trigger count on falling edge

Who changed what in which revision?

UserRevisionLine numberNew contents of line
walter76 2:ac0ed3d84d44 1 // GEO COUNTER V1 firmware
walter76 2:ac0ed3d84d44 2 // This FW provides a basic operation of GEO-COUNTER
walter76 2:ac0ed3d84d44 3 //
walter76 2:ac0ed3d84d44 4 // Latest review: August 27, 2018 - Walter Trovo
walter76 1:75827d765e34 5 //
Charles David Young 72:4838d419f33c 6 // Sep 13, 2018: Charles Young: CNT1 and CNT2 smooth
Charles David Young 68:c2e71a6583dd 7 // Sep 9, 2018: Charles Young: CNT1 and CNT2 accurate except for jumping up
Charles David Young 47:f004b4612069 8 // Sep 6, 2018: Charles Young: Functioning mode selection - modes partially implemented
Charles David Young 25:0161bf1adc81 9 // Sep 5, 2018: Charles Young: Created LED7segDisplay class
charlesdavidyoung 24:db7494389c03 10 // Sep 5, 2018: Charles Young: Still developing mode selection. LEDs turn off
charlesdavidyoung 24:db7494389c03 11 // when not in mode selection. Pressing once enters mode selection.
charlesdavidyoung 24:db7494389c03 12 // Pressing again enters submode. Temporarily the rotary switch
charlesdavidyoung 24:db7494389c03 13 // adjusts the display brightness. This is just for testing.
charlesdavidyoung 24:db7494389c03 14 // Sep 4, 2018: Charles Young: Created RotarySwitch class to manage mode selection
walter76 1:75827d765e34 15 // Feb 14, 2018: initial release aimed to test the counters, the serial port
walter76 1:75827d765e34 16 // the PWM output and the MAX7219 operation.
walter76 1:75827d765e34 17 // Feb 15, 2018: Removed MAX7219 libray (replaced with custom routine).
walter76 1:75827d765e34 18 // Added 74HC595 routine. Added beep. Added Gate_write
walter76 1:75827d765e34 19 //
walter76 2:ac0ed3d84d44 20
walter76 1:75827d765e34 21
walter76 1:75827d765e34 22 // this block includes key libraries
walter76 1:75827d765e34 23 #include <string> // strings management
charlesdavidyoung 24:db7494389c03 24 #include "RotarySwitch.hpp"
Charles David Young 25:0161bf1adc81 25 #include "LED7segDisplay.hpp"
charlesdavidyoung 20:fb73eaaf0894 26
charlesdavidyoung 24:db7494389c03 27 // Everything associated with the rotary switch and the associated LEDs
charlesdavidyoung 24:db7494389c03 28 // is hidden in this class.
charlesdavidyoung 20:fb73eaaf0894 29 RotarySwitch ModeSwitch;
Charles David Young 25:0161bf1adc81 30 LED7segDisplay DigitsDisplay;
walter76 1:75827d765e34 31
Charles David Young 34:10550b327e3d 32 enum Modes {
Charles David Young 34:10550b327e3d 33 CNT1,
Charles David Young 34:10550b327e3d 34 CNT2,
Charles David Young 34:10550b327e3d 35 PROSPECT,
Charles David Young 34:10550b327e3d 36 NULL1,
Charles David Young 37:6f7bb913e08b 37 NULL2,
Charles David Young 38:1642320d83a0 38 VOLTS,
Charles David Young 38:1642320d83a0 39 VOLUME,
Charles David Young 34:10550b327e3d 40 DIM,
Charles David Young 34:10550b327e3d 41 NumberOfModes
Charles David Young 34:10550b327e3d 42 };
Charles David Young 38:1642320d83a0 43 uint8_t currentMode = CNT1;
Charles David Young 38:1642320d83a0 44 uint8_t currentModeToDisplay = CNT1;
Charles David Young 34:10550b327e3d 45
charlesdavidyoung 5:4f90b458dbdf 46 // LED on processor board
charlesdavidyoung 5:4f90b458dbdf 47 DigitalOut led1(LED1);
walter76 1:75827d765e34 48
walter76 1:75827d765e34 49 // definitions of peripherals and devices
Charles David Young 7:9f975e00600c 50
charlesdavidyoung 17:6eed17197004 51 I2C i2c(D4, D5); // I2C port
charlesdavidyoung 17:6eed17197004 52 Ticker SecTenth_Beat; // .1 second ticker
walter76 1:75827d765e34 53 Ticker Sec_Beat; // 1 second ticker
Charles David Young 61:00601fb0a3b9 54
walter76 1:75827d765e34 55 Serial PC(USBTX, USBRX); // Virtual COM via USB (PC connection)
walter76 1:75827d765e34 56 Serial GPS(D1, D0); // Serial port for GPS module
walter76 0:6d1742703713 57
walter76 0:6d1742703713 58 // Global variables
walter76 1:75827d765e34 59 time_t seconds; // Real-Time Clock (RTC) timestamp
walter76 1:75827d765e34 60 unsigned int value = 0; // displayed value on the 6-digits of the display
Charles David Young 44:a26ca542ae5e 61
Charles David Young 61:00601fb0a3b9 62 uint32_t Count1, Count2; // pulse counters (32-bit)
Charles David Young 71:fe799147584b 63 #define CountAvg 4
Charles David Young 71:fe799147584b 64 uint32_t Count1Avg[CountAvg], Count2Avg[CountAvg]; // pulse counters (32-bit)
Charles David Young 72:4838d419f33c 65 uint8_t CountAvgIndex = 0;
Charles David Young 61:00601fb0a3b9 66 uint32_t Count1Save;
Charles David Young 61:00601fb0a3b9 67 uint32_t Count2Save;
Charles David Young 61:00601fb0a3b9 68
Charles David Young 58:d15adb224e5a 69 uint32_t TickerPeriod = 100000;
Charles David Young 53:04999d536e92 70 uint32_t TickerPeriodCount = 0;
Charles David Young 53:04999d536e92 71 const uint32_t TickerPeriodsPerSecond = 1000000/TickerPeriod;
Charles David Young 61:00601fb0a3b9 72 const uint32_t TickerTicksPerSecond = TickerPeriod*TickerPeriodsPerSecond;
Charles David Young 44:a26ca542ae5e 73
walter76 1:75827d765e34 74 char Text[40]=""; // used to send messages over the serial port
walter76 1:75827d765e34 75 uint8_t Disp_mode = 0x01, Disp_unit = 0xA0; // status of 1st row and 2nd rows of LEDs
kd5byb 4:b17c6556cf1f 76 bool Stopped = 0; // status of counting activity
charlesdavidyoung 5:4f90b458dbdf 77 bool StartStopPressed = 0;// status of counting activity
walter76 1:75827d765e34 78 double ADC_val; // used to read ADC value
charlesdavidyoung 24:db7494389c03 79 float direction = 0;
walter76 0:6d1742703713 80
Charles David Young 38:1642320d83a0 81 #define maxVolume 10
Charles David Young 38:1642320d83a0 82 uint8_t volume = maxVolume;
Charles David Young 38:1642320d83a0 83
walter76 1:75827d765e34 84 // ----- Prototypes of routines (defined below the main) -------------------
Charles David Young 16:b2e77eb76ab4 85 void UpdateInput(void); // periodically called by the ticker
Charles David Young 16:b2e77eb76ab4 86 void UpdateOutput(void); // periodically called by the ticker
Charles David Young 53:04999d536e92 87 void UpdateIO(void); // periodically called by the ticker
walter76 1:75827d765e34 88 void Count1_up(void); // called every time an edge is detected on TRIG1 pin
walter76 1:75827d765e34 89 void Count2_up(void); // called every time an edge is detected on TRIG2 pin
walter76 1:75827d765e34 90 void Beep(void); // used to generate a short beep (buzzer)
walter76 0:6d1742703713 91
walter76 0:6d1742703713 92 //==============================================================================
walter76 0:6d1742703713 93 //==============================================================================
walter76 0:6d1742703713 94
walter76 0:6d1742703713 95 int main()
walter76 0:6d1742703713 96 {
walter76 0:6d1742703713 97
Charles David Young 28:c81d00ec28a3 98 PC.baud(115200); // set baud-rate of virtual COM port (PC connection)
Charles David Young 28:c81d00ec28a3 99 PC.printf("\nGEO COUNTER V1 2108");
Charles David Young 28:c81d00ec28a3 100 PC.printf(__DATE__);
Charles David Young 28:c81d00ec28a3 101 PC.printf(" ");
Charles David Young 28:c81d00ec28a3 102 PC.printf(__TIME__);
walter76 1:75827d765e34 103
Charles David Young 28:c81d00ec28a3 104 GPS.baud(9600); // set the baud-rate of the serial port dedicated to the GPS
walter76 0:6d1742703713 105
Charles David Young 28:c81d00ec28a3 106 CS1 = 1; // presets CS of MAX7219
Charles David Young 28:c81d00ec28a3 107 CS2 = 1; // preset CS of 74HC595
walter76 1:75827d765e34 108
Charles David Young 28:c81d00ec28a3 109 DigitsDisplay.Display_6D_write(0x543210);
Charles David Young 28:c81d00ec28a3 110 DigitsDisplay.Display_2D_write(0);
walter76 0:6d1742703713 111
Charles David Young 61:00601fb0a3b9 112 // RTC is supposed to lose time at power down (no backup battery)
Charles David Young 28:c81d00ec28a3 113 // An initialization is performed anyway
Charles David Young 28:c81d00ec28a3 114 set_time(0); // Set time
charlesdavidyoung 24:db7494389c03 115
Charles David Young 28:c81d00ec28a3 116 PWM.period_ms(3); // set the PWM period
Charles David Young 28:c81d00ec28a3 117 PWM.write(0.8); // set the PWM duty-cycle
walter76 1:75827d765e34 118
Charles David Young 28:c81d00ec28a3 119 Beep(); // initial beep
walter76 1:75827d765e34 120
Charles David Young 28:c81d00ec28a3 121 // set the 1 sec ticker to periodically call the Update() routine
Charles David Young 28:c81d00ec28a3 122 // NOTE: this is also the 1-sec time base for counters. A better approach
Charles David Young 28:c81d00ec28a3 123 // would replace the ticker with an interrupt from the RTC (to be implemented)
Charles David Young 53:04999d536e92 124 SecTenth_Beat.attach_us(&UpdateIO, TickerPeriod);
Charles David Young 28:c81d00ec28a3 125 //RTC::attach(&Update, RTC::Second);
Charles David Young 28:c81d00ec28a3 126 //RTC::detach(RTC::Second);
Charles David Young 68:c2e71a6583dd 127
Charles David Young 78:0fd2f71c2d64 128 TRIG1.fall(&Count1_up);
Charles David Young 78:0fd2f71c2d64 129 TRIG2.fall(&Count2_up);
Charles David Young 60:6ae1a2390600 130
Charles David Young 71:fe799147584b 131 for (uint8_t i=0;i<CountAvg;i++)
Charles David Young 71:fe799147584b 132 {
Charles David Young 71:fe799147584b 133 Count1Avg[i] = 0;
Charles David Young 71:fe799147584b 134 Count2Avg[i] = 0;
Charles David Young 71:fe799147584b 135 }
Charles David Young 71:fe799147584b 136
Charles David Young 28:c81d00ec28a3 137 // main loop does nothing as all activities are interrupt driven
Charles David Young 28:c81d00ec28a3 138 while(1)
Charles David Young 28:c81d00ec28a3 139 {
Charles David Young 70:a07ab0091d5a 140 // somehow this makes it worse
Charles David Young 70:a07ab0091d5a 141 // // Manage user I/O outside Ticker interrupt for accuracy
Charles David Young 70:a07ab0091d5a 142 // wait_us(TickerPeriod);
Charles David Young 70:a07ab0091d5a 143 // if (TickerPeriodCount == 0)
Charles David Young 70:a07ab0091d5a 144 // UpdateOutput();
Charles David Young 70:a07ab0091d5a 145 // UpdateInput();
Charles David Young 28:c81d00ec28a3 146 }
walter76 0:6d1742703713 147 }
walter76 0:6d1742703713 148
walter76 0:6d1742703713 149
walter76 1:75827d765e34 150 //-------- END OF MAIN --------------
walter76 0:6d1742703713 151 //==============================================================================
walter76 0:6d1742703713 152
walter76 1:75827d765e34 153 // Definition of routines
walter76 1:75827d765e34 154
walter76 1:75827d765e34 155 //---------------------------------------------------------------------------
walter76 1:75827d765e34 156 // Update values to be displayed
Charles David Young 10:f48cc6be5ae8 157 void logToPC()
Charles David Young 10:f48cc6be5ae8 158 {
Charles David Young 10:f48cc6be5ae8 159 PC.printf("\nADC: %.02f", ADC_val);
Charles David Young 10:f48cc6be5ae8 160 PC.printf(Stopped ? " stopped" : " started");
Charles David Young 10:f48cc6be5ae8 161 // Timestamp to PC (debug)
Charles David Young 10:f48cc6be5ae8 162 seconds = time(NULL); // get current time
Charles David Young 10:f48cc6be5ae8 163 strftime(Text, 50, "%H:%M:%S", localtime(&seconds));
Charles David Young 10:f48cc6be5ae8 164 PC.printf(" RTC: %s, CNT1: %7d CNT2: %7d",Text, Count1, Count2);
charlesdavidyoung 24:db7494389c03 165 PC.printf(" wheel %f", direction);
Charles David Young 10:f48cc6be5ae8 166 }
walter76 1:75827d765e34 167
Charles David Young 53:04999d536e92 168 void UpdateIO()
Charles David Young 53:04999d536e92 169 {
Charles David Young 53:04999d536e92 170 if (++TickerPeriodCount >= TickerPeriodsPerSecond)
Charles David Young 53:04999d536e92 171 {
Charles David Young 61:00601fb0a3b9 172 // Capture the counts early so they will be more accurate
Charles David Young 71:fe799147584b 173 Count1Avg[CountAvgIndex] = Count1;
Charles David Young 71:fe799147584b 174 Count2Avg[CountAvgIndex] = Count2;
Charles David Young 71:fe799147584b 175 CountAvgIndex = ++CountAvgIndex % CountAvg;
Charles David Young 71:fe799147584b 176
Charles David Young 76:6b0d47c3027c 177 // smooth counts while accounting for small roundoff error
Charles David Young 77:87aac94b235a 178 uint32_t Count1Sum = 1, Count2Sum = 1;
Charles David Young 71:fe799147584b 179 for (uint8_t i=0;i<CountAvg;i++)
Charles David Young 71:fe799147584b 180 {
Charles David Young 75:5af098188ebf 181 Count1Sum += Count1Avg[i];
Charles David Young 75:5af098188ebf 182 Count2Sum += Count2Avg[i];
Charles David Young 71:fe799147584b 183 }
Charles David Young 75:5af098188ebf 184 Count1Save = Count1Sum / CountAvg;
Charles David Young 75:5af098188ebf 185 Count2Save = Count2Sum / CountAvg;
Charles David Young 61:00601fb0a3b9 186 Count1 = 0;
Charles David Young 61:00601fb0a3b9 187 Count2 = 0;
Charles David Young 61:00601fb0a3b9 188
Charles David Young 53:04999d536e92 189 TickerPeriodCount = 0;
Charles David Young 61:00601fb0a3b9 190
Charles David Young 70:a07ab0091d5a 191 UpdateOutput();
Charles David Young 53:04999d536e92 192 }
Charles David Young 70:a07ab0091d5a 193 UpdateInput();
Charles David Young 53:04999d536e92 194 }
Charles David Young 53:04999d536e92 195
Charles David Young 53:04999d536e92 196 void UpdateOutput()
charlesdavidyoung 18:ef5678ab1889 197 {
Charles David Young 49:a67f2a3d228a 198 if(Stopped)
Charles David Young 49:a67f2a3d228a 199 {
Charles David Young 49:a67f2a3d228a 200 // disable interrupts on TRIG1 and TRIG2
Charles David Young 78:0fd2f71c2d64 201 TRIG1.fall(NULL);
Charles David Young 78:0fd2f71c2d64 202 TRIG2.fall(NULL);
Charles David Young 49:a67f2a3d228a 203 }
Charles David Young 49:a67f2a3d228a 204
Charles David Young 28:c81d00ec28a3 205 // This must be called periodically to update the LEDs
Charles David Young 28:c81d00ec28a3 206 ModeSwitch.UpdateOutput();
charlesdavidyoung 24:db7494389c03 207
Charles David Young 38:1642320d83a0 208 switch (currentModeToDisplay) {
Charles David Young 34:10550b327e3d 209 case CNT1:
Charles David Young 49:a67f2a3d228a 210 DigitsDisplay.Display_6D_write(Count1Save);
Charles David Young 41:08bf3ea5eba4 211 DigitsDisplay.Display_2D_Blank();
Charles David Young 34:10550b327e3d 212 break;
Charles David Young 34:10550b327e3d 213 case CNT2:
Charles David Young 49:a67f2a3d228a 214 DigitsDisplay.Display_6D_write(Count2Save);
Charles David Young 41:08bf3ea5eba4 215 DigitsDisplay.Display_2D_Blank();
Charles David Young 34:10550b327e3d 216 break;
Charles David Young 34:10550b327e3d 217 case PROSPECT:
Charles David Young 49:a67f2a3d228a 218 if (Count1Save)
Charles David Young 49:a67f2a3d228a 219 DigitsDisplay.Display_6D_write(Count1Save);
Charles David Young 44:a26ca542ae5e 220 else
Charles David Young 49:a67f2a3d228a 221 DigitsDisplay.Display_6D_write(Count2Save);
Charles David Young 41:08bf3ea5eba4 222 DigitsDisplay.Display_2D_Blank();
Charles David Young 34:10550b327e3d 223 break;
Charles David Young 34:10550b327e3d 224 case NULL1:
Charles David Young 34:10550b327e3d 225 DigitsDisplay.Display_6D_write(0);
Charles David Young 41:08bf3ea5eba4 226 DigitsDisplay.Display_2D_Blank();
Charles David Young 34:10550b327e3d 227 break;
Charles David Young 37:6f7bb913e08b 228 case NULL2:
Charles David Young 34:10550b327e3d 229 DigitsDisplay.Display_6D_write(0);
Charles David Young 41:08bf3ea5eba4 230 DigitsDisplay.Display_2D_Blank();
Charles David Young 34:10550b327e3d 231 break;
Charles David Young 38:1642320d83a0 232 case VOLTS:
Charles David Young 34:10550b327e3d 233 DigitsDisplay.Display_6D_write(0);
Charles David Young 41:08bf3ea5eba4 234 DigitsDisplay.Display_2D_Blank();
Charles David Young 34:10550b327e3d 235 break;
Charles David Young 38:1642320d83a0 236 case VOLUME:
Charles David Young 34:10550b327e3d 237 case DIM:
Charles David Young 34:10550b327e3d 238 default:
Charles David Young 34:10550b327e3d 239 break;
Charles David Young 34:10550b327e3d 240 }
Charles David Young 16:b2e77eb76ab4 241 }
Charles David Young 16:b2e77eb76ab4 242
Charles David Young 16:b2e77eb76ab4 243 void UpdateInput()
charlesdavidyoung 24:db7494389c03 244 {
charlesdavidyoung 24:db7494389c03 245 // This must be called periodically to monitor switch input
Charles David Young 38:1642320d83a0 246 direction = ModeSwitch.UpdateInput();
Charles David Young 34:10550b327e3d 247 currentMode = ModeSwitch.GetPosition();
Charles David Young 34:10550b327e3d 248
Charles David Young 34:10550b327e3d 249 switch (currentMode) {
Charles David Young 34:10550b327e3d 250 case CNT1:
Charles David Young 34:10550b327e3d 251 case CNT2:
Charles David Young 44:a26ca542ae5e 252 currentModeToDisplay = currentMode;
Charles David Young 44:a26ca542ae5e 253
Charles David Young 71:fe799147584b 254 if (direction > 0)
Charles David Young 44:a26ca542ae5e 255 {
Charles David Young 44:a26ca542ae5e 256 }
Charles David Young 44:a26ca542ae5e 257 else
Charles David Young 71:fe799147584b 258 if (direction < 0)
Charles David Young 44:a26ca542ae5e 259 {
Charles David Young 44:a26ca542ae5e 260 }
Charles David Young 44:a26ca542ae5e 261 break;
Charles David Young 34:10550b327e3d 262 case PROSPECT:
Charles David Young 34:10550b327e3d 263 case VOLTS:
Charles David Young 38:1642320d83a0 264 currentModeToDisplay = currentMode;
Charles David Young 34:10550b327e3d 265 break;
Charles David Young 34:10550b327e3d 266 case NULL1:
Charles David Young 37:6f7bb913e08b 267 case NULL2:
Charles David Young 34:10550b327e3d 268 break;
Charles David Young 38:1642320d83a0 269 case VOLUME:
Charles David Young 39:dee91966b45c 270 if ( (direction > 0)
Charles David Young 39:dee91966b45c 271 && (volume < maxVolume))
Charles David Young 39:dee91966b45c 272 volume++;
Charles David Young 39:dee91966b45c 273 else
Charles David Young 39:dee91966b45c 274 if ( (direction < 0)
Charles David Young 39:dee91966b45c 275 && (volume > 0))
Charles David Young 39:dee91966b45c 276 volume--;
Charles David Young 39:dee91966b45c 277
Charles David Young 38:1642320d83a0 278 DigitsDisplay.Display_2D_write(volume);
Charles David Young 34:10550b327e3d 279 break;
Charles David Young 34:10550b327e3d 280 case DIM:
Charles David Young 39:dee91966b45c 281 if (direction > 0)
Charles David Young 39:dee91966b45c 282 DigitsDisplay.Display_brightness_up();
Charles David Young 39:dee91966b45c 283 else
Charles David Young 39:dee91966b45c 284 if (direction < 0)
Charles David Young 39:dee91966b45c 285 DigitsDisplay.Display_brightness_down();
Charles David Young 39:dee91966b45c 286
Charles David Young 38:1642320d83a0 287 DigitsDisplay.Display_2D_write(DigitsDisplay.GetBrightness());
Charles David Young 34:10550b327e3d 288 break;
Charles David Young 34:10550b327e3d 289 default:
Charles David Young 34:10550b327e3d 290 break;
charlesdavidyoung 24:db7494389c03 291 }
Charles David Young 34:10550b327e3d 292
Charles David Young 65:5f087e22a9d1 293 // ADC_val = KEYB.read(); // read voltage from keyboard
Charles David Young 65:5f087e22a9d1 294 // if ( (ADC_val<0.1) // START/STOP pushbutton pressed
Charles David Young 65:5f087e22a9d1 295 // && (!StartStopPressed))
Charles David Young 65:5f087e22a9d1 296 // {
Charles David Young 65:5f087e22a9d1 297 // StartStopPressed = true;
Charles David Young 65:5f087e22a9d1 298 // if (Stopped)
Charles David Young 65:5f087e22a9d1 299 // {
Charles David Young 65:5f087e22a9d1 300 // // Enable interrupts on rising edge of digital inputs TRIG1 & TRIG2
Charles David Young 65:5f087e22a9d1 301 // TRIG1.rise(&Count1_up);
Charles David Young 65:5f087e22a9d1 302 // TRIG2.rise(&Count2_up);
Charles David Young 65:5f087e22a9d1 303 // }
Charles David Young 65:5f087e22a9d1 304 // Stopped=!Stopped; // toggle status
Charles David Young 65:5f087e22a9d1 305 // }
Charles David Young 65:5f087e22a9d1 306 // else
Charles David Young 65:5f087e22a9d1 307 // StartStopPressed = false;
charlesdavidyoung 5:4f90b458dbdf 308
Charles David Young 65:5f087e22a9d1 309 // if((ADC_val>0.6)&&(ADC_val<0.7)) // CLEAR pushbutton pressed
Charles David Young 65:5f087e22a9d1 310 // {
Charles David Young 65:5f087e22a9d1 311 // Count1 = 0; // clear counters
Charles David Young 65:5f087e22a9d1 312 // Count2 = 0;
Charles David Young 65:5f087e22a9d1 313 // }
Charles David Young 57:f4215ca747e5 314 //logToPC();
Charles David Young 16:b2e77eb76ab4 315 return;
Charles David Young 16:b2e77eb76ab4 316 }
walter76 1:75827d765e34 317
walter76 0:6d1742703713 318 //---------------------------------------------------------------------------
walter76 1:75827d765e34 319 // Increment CNT1 every time a rising edge is detected on TRIG1 (interrupt)
walter76 1:75827d765e34 320
walter76 1:75827d765e34 321 void Count1_up(void)
walter76 1:75827d765e34 322 {
Charles David Young 33:35e3ab4d5ba7 323 //Beep();
Charles David Young 28:c81d00ec28a3 324 Count1++;
Charles David Young 28:c81d00ec28a3 325 return;
walter76 1:75827d765e34 326 }
walter76 1:75827d765e34 327
walter76 1:75827d765e34 328 //---------------------------------------------------------------------------
walter76 1:75827d765e34 329 // Increment CNT1 every time a rising edge is detected on TRIG2 (interrupt)
walter76 1:75827d765e34 330
walter76 1:75827d765e34 331 void Count2_up(void)
walter76 1:75827d765e34 332 {
Charles David Young 33:35e3ab4d5ba7 333 //Beep();
Charles David Young 28:c81d00ec28a3 334 Count2++;
Charles David Young 28:c81d00ec28a3 335 return;
walter76 1:75827d765e34 336 }
walter76 1:75827d765e34 337
walter76 1:75827d765e34 338
walter76 1:75827d765e34 339 //---------------------------------------------------------------------------
walter76 1:75827d765e34 340 //Generates a short beep via BUZZ
walter76 1:75827d765e34 341
walter76 1:75827d765e34 342 void Beep(void)
walter76 1:75827d765e34 343 {
Charles David Young 28:c81d00ec28a3 344 BUZZ = 1; // turn-on the buzzer
Charles David Young 33:35e3ab4d5ba7 345 wait_us(100); // wait
Charles David Young 28:c81d00ec28a3 346 BUZZ = 0; // turn-off the buzzer
Charles David Young 28:c81d00ec28a3 347 return;
walter76 0:6d1742703713 348 }
walter76 0:6d1742703713 349
walter76 1:75827d765e34 350 //-------- END OF FILE --------------
walter76 1:75827d765e34 351 //==============================================================================