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:
Thu Sep 13 15:05:08 2018 -0700
Revision:
71:fe799147584b
Parent:
70:a07ab0091d5a
Child:
72:4838d419f33c
Smooth counts

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