├── .github └── workflows │ └── TestCompile.yml ├── FrequencyGeneratorPage.h ├── FrequencyGeneratorPage.hpp ├── LICENSE.txt ├── README.md ├── SimpleDSO.ino ├── SimpleDSO_BlueDisplay.h ├── TouchDSOCommon.h ├── TouchDSOGui.hpp ├── Waveforms.cpp ├── Waveforms.h ├── digitalWriteFast.h ├── extras ├── Arduino_Nano_DSO_BT_full.fzz ├── Arduino_Nano_DSO_BT_full_Schaltplan.png ├── Arduino_Nano_DSO_BT_full_Steckplatine.png ├── Arduino_Nano_DSO_BT_simple.fzz ├── Arduino_Nano_DSO_BT_simple_Schaltplan.png ├── Arduino_Nano_DSO_BT_simple_Steckplatine.png ├── Arduino_Nano_DSO_simple.fzz ├── Arduino_Nano_DSO_simple_Schaltplan.png └── Arduino_Nano_DSO_simple_Steckplatine.png └── pictures ├── ArduinoDSO.jpg ├── ArduinoDSO_Closeup.jpg ├── ArduinoDSO_simple.jpg ├── Chart.jpg ├── Chart_Long_Info.jpg ├── DSO+Tablet.jpg ├── Frequency.jpg ├── Linearity_13us_conversion_time.jpg ├── Linearity_26us_conversion_time.jpg ├── Linearity_3us_conversion_time.jpg ├── Linearity_6us5_conversion_time.jpg ├── SettingsBluePill.png ├── Settings_Passive_Attenuator.jpg ├── Settings_simple.jpg └── Welcome.jpg /.github/workflows/TestCompile.yml: -------------------------------------------------------------------------------- 1 | # TestCompile.yml 2 | # Github workflow script to test compile all examples of an Arduino library repository. 3 | # 4 | # Copyright (C) 2020-2023 Armin Joachimsmeyer 5 | # https://github.com/ArminJo/Github-Actions 6 | # 7 | 8 | # This is the name of the workflow, visible on GitHub UI. 9 | name: TestCompile 10 | on: push 11 | jobs: 12 | build: 13 | name: Test compiling examples for Uno 14 | runs-on: ubuntu-latest 15 | steps: 16 | - name: Checkout 17 | uses: actions/checkout@master 18 | 19 | # - name: Checkout new BlueDisplay library 20 | # uses: actions/checkout@master 21 | # with: 22 | # repository: ArminJo/Arduino-BlueDisplay 23 | # ref: master 24 | # path: CustomLibrary_BD # must contain string "Custom" 25 | # # Must remove BlueDisplay from REQUIRED_LIBRARIES 26 | 27 | - name: Compile all examples 28 | uses: ArminJo/arduino-test-compile@master 29 | with: 30 | sketch-names: SimpleDSO.ino 31 | required-libraries: BlueDisplay 32 | -------------------------------------------------------------------------------- /FrequencyGeneratorPage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FrequencyGeneratorPage.h 3 | * 4 | * Copyright (C) 2015 Armin Joachimsmeyer 5 | * Email: armin.joachimsmeyer@gmail.com 6 | * License: GPL v3 (http://www.gnu.org/licenses/gpl.html) 7 | */ 8 | #ifndef _FREQUENCY_GENERATOR_PAGE_H 9 | #define _FREQUENCY_GENERATOR_PAGE_H 10 | 11 | #include "BDButton.h" 12 | 13 | #include 14 | #include 15 | 16 | /** 17 | * From FrequencyGenerator page 18 | */ 19 | void initFrequencyGenerator(void); 20 | void initFrequencyGeneratorPage(void); 21 | void drawFrequencyGeneratorPage(void); 22 | void startFrequencyGeneratorPage(void); 23 | void loopFrequencyGeneratorPage(void); 24 | void stopFrequencyGeneratorPage(void); 25 | 26 | //extern BDButton TouchButtonFrequencyPage; 27 | 28 | extern const char StringStop[] PROGMEM; // "Stop" 29 | 30 | #endif // _FREQUENCY_GENERATOR_PAGE_H 31 | -------------------------------------------------------------------------------- /FrequencyGeneratorPage.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * FrequencyGeneratorPage.hpp 3 | * 4 | * Frequency output from 119 mHz (8.388 second) to 8 MHz square wave on Arduino using timer1. 5 | * Sine waveform output from 7,421 mHz to 7812.5 Hz 6 | * Triangle from 3.725 mHz to 1953.125 Hz 7 | * Sawtooth from 1.866 mHz to 3906.25 Hz 8 | * 9 | * !!!Do not run DSO acquisition and non square wave waveform generation at the same time!!! 10 | * Because of the interrupts at 62 kHz rate, DSO is almost not usable during non square wave waveform generation. 11 | * Waveform frequency is not stable and decreased, since not all TIMER1 OVERFLOW interrupts are handled. 12 | * 13 | * PWM RC-Filter suggestions 14 | * Simple: 2.2 kOhm and 100 nF 15 | * 2nd order (good for sine and triangle): 1 kOhm and 100 nF -> 4.7 kOhm and 22 nF 16 | * 2nd order (better for sawtooth): 1 kOhm and 22 nF -> 4.7 kOhm and 4.7 nF 17 | * 18 | * 19 | * Copyright (C) 2015-2023 Armin Joachimsmeyer 20 | * Email: armin.joachimsmeyer@gmail.com 21 | * 22 | * This file is part of Arduino-Simple-DSO https://github.com/ArminJo/Arduino-Simple-DSO. 23 | * 24 | * Arduino-Simple-DSO is free software: you can redistribute it and/or modify 25 | * it under the terms of the GNU General Public License as published by 26 | * the Free Software Foundation, either version 3 of the License, or 27 | * (at your option) any later version. 28 | * 29 | * This program is distributed in the hope that it will be useful, 30 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 31 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 32 | * See the GNU General Public License for more details. 33 | * 34 | * You should have received a copy of the GNU General Public License 35 | * along with this program. If not, see . 36 | * 37 | */ 38 | #ifndef _FREQUENCY_GENERATOR_PAGE_HPP 39 | #define _FREQUENCY_GENERATOR_PAGE_HPP 40 | 41 | #if defined(__AVR__) 42 | #include "FrequencyGeneratorPage.h" 43 | #endif 44 | 45 | #include "Waveforms.h" 46 | 47 | static void (*sLastRedrawCallback)(void); 48 | 49 | #define COLOR_BACKGROUND_FREQ COLOR16_WHITE 50 | 51 | #if defined(__AVR__) 52 | #define TIMER_PRESCALER_64 0x03 53 | #define TIMER_PRESCALER_MASK 0x07 54 | #endif 55 | 56 | #define NUMBER_OF_FIXED_FREQUENCY_BUTTONS 10 57 | #define NUMBER_OF_FREQUENCY_RANGE_BUTTONS 5 58 | 59 | /* 60 | * Position + size 61 | */ 62 | #define FREQ_SLIDER_SIZE 10 // width of bar / border 63 | #define FREQ_SLIDER_MAX_VALUE 300 // (BlueDisplay1.getDisplayWidth() - 20) = 300 length of bar 64 | #define FREQ_SLIDER_X 5 65 | #define FREQ_SLIDER_Y (4 * TEXT_SIZE_11_HEIGHT + 4) 66 | 67 | /* 68 | * Direct frequency + range buttons 69 | */ 70 | #if defined(__AVR__) 71 | const uint16_t FixedFrequencyButtonCaptions[NUMBER_OF_FIXED_FREQUENCY_BUTTONS] PROGMEM 72 | = { 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000 }; 73 | 74 | // the compiler cannot optimize 2 occurrences of the same PROGMEM string :-( 75 | const char StringmHz[] PROGMEM = "mHz"; 76 | const char StringHz[] PROGMEM = "Hz"; 77 | const char String10Hz[] PROGMEM = "10Hz"; 78 | const char StringkHz[] PROGMEM = "kHz"; 79 | const char StringMHz[] PROGMEM = "MHz"; 80 | 81 | const char *RangeButtonStrings[5] = { StringmHz, StringHz, String10Hz, StringkHz, StringMHz }; 82 | #else 83 | const uint16_t FixedFrequencyButtonCaptions[NUMBER_OF_FIXED_FREQUENCY_BUTTONS] = { 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000 }; 84 | const char *const RangeButtonStrings[5] = { "mHz", "Hz", "10Hz", "kHz", "MHz" }; 85 | const char FrequencyRangeChars[4] = { 'm', ' ', 'k', 'M' }; 86 | struct FrequencyInfoStruct sFrequencyInfo; 87 | 88 | #endif 89 | #define INDEX_OF_10HZ 2 90 | static bool is10HzRange = true; 91 | 92 | static const int BUTTON_INDEX_SELECTED_INITIAL = 2; // select 10Hz Button 93 | 94 | /* 95 | * GUI 96 | */ 97 | BDButton TouchButtonFrequencyRanges[NUMBER_OF_FREQUENCY_RANGE_BUTTONS]; 98 | BDButton ActiveTouchButtonFrequencyRange; // Used to determine which range button is active 99 | 100 | BDButton TouchButtonFrequencyStartStop; 101 | BDButton TouchButtonGetFrequency; 102 | BDButton TouchButtonWaveform; 103 | 104 | #if defined(SUPPORT_LOCAL_DISPLAY) 105 | BDButton TouchButton1; 106 | BDButton TouchButton2; 107 | BDButton TouchButton5; 108 | BDButton TouchButton10; 109 | BDButton TouchButton20; 110 | BDButton TouchButton50; 111 | BDButton TouchButton100; 112 | BDButton TouchButton200; 113 | BDButton TouchButton500; 114 | BDButton TouchButton1k; 115 | BDButton *const TouchButtonFixedFrequency[] = { &TouchButton1, &TouchButton2, &TouchButton5, &TouchButton10, &TouchButton20, 116 | &TouchButton50, &TouchButton100, &TouchButton200, &TouchButton500, &TouchButton1k }; 117 | #else 118 | BDButton TouchButtonFirstFixedFrequency; 119 | #endif 120 | 121 | BDSlider TouchSliderFrequency; 122 | 123 | void initFrequencyGeneratorPageGui(void); 124 | 125 | void doSetFrequencyFromSliderValue(BDSlider *aTheTouchedSlider, uint16_t aFrequencySliderValue); 126 | 127 | void doWaveformMode(BDButton *aTheTouchedButton, int16_t aValue); 128 | void doSetFixedFrequency(BDButton *aTheTouchedButton, int16_t aNormalizedFrequency); 129 | void doSetFrequencyRange(BDButton *aTheTouchedButton, int16_t aInputRangeIndex); 130 | void doFrequencyGeneratorStartStop(BDButton *aTheTouchedButton, int16_t aValue); 131 | void doGetFrequency(BDButton *aTheTouchedButton, int16_t aValue); 132 | 133 | bool setWaveformFrequencyAndPrintValues(); 134 | 135 | void printFrequencyAndPeriod(); 136 | #if defined(__AVR__) 137 | void setWaveformButtonCaption(void); 138 | void initTimer1ForCTC(void); 139 | #endif 140 | 141 | /*********************** 142 | * Code starts here 143 | ***********************/ 144 | 145 | void initFrequencyGenerator(void) { 146 | #if defined(__AVR__) 147 | initTimer1ForCTC(); 148 | #else 149 | Synth_Timer_initialize(4711); 150 | #endif 151 | } 152 | 153 | void initFrequencyGeneratorPage(void) { 154 | initFrequencyGenerator(); 155 | /* 156 | * Initialize frequency and other fields to 200 Hz 157 | */ 158 | sFrequencyInfo.isOutputEnabled = false; 159 | sFrequencyInfo.Waveform = WAVEFORM_SQUARE; 160 | setWaveformFrequency(200); 161 | 162 | sFrequencyInfo.isOutputEnabled = true; // to start output at first display of page 163 | 164 | #if !defined(SUPPORT_LOCAL_DISPLAY) 165 | initFrequencyGeneratorPageGui(); 166 | #endif 167 | } 168 | 169 | void startFrequencyGeneratorPage(void) { 170 | BlueDisplay1.clearDisplay(); 171 | 172 | #if defined(SUPPORT_LOCAL_DISPLAY) 173 | // do it here to enable freeing of button resources in stopFrequencyGeneratorPage() 174 | initFrequencyGeneratorPageGui(); 175 | #endif 176 | 177 | setWaveformFrequencyFromNormalizedValues(); 178 | 179 | drawFrequencyGeneratorPage(); 180 | /* 181 | * save state 182 | */ 183 | sLastRedrawCallback = getRedrawCallback(); 184 | registerRedrawCallback(&drawFrequencyGeneratorPage); 185 | 186 | #if !defined(__AVR__) 187 | Synth_Timer_Start(); 188 | #endif 189 | } 190 | 191 | void loopFrequencyGeneratorPage(void) { 192 | checkAndHandleEvents(); 193 | } 194 | 195 | void stopFrequencyGeneratorPage(void) { 196 | #if defined(SUPPORT_LOCAL_DISPLAY) 197 | // free buttons 198 | for (unsigned int i = 0; i < NUMBER_OF_FIXED_FREQUENCY_BUTTONS; ++i) { 199 | TouchButtonFixedFrequency[i]->deinit(); 200 | } 201 | 202 | for (int i = 0; i < NUMBER_OF_FREQUENCY_RANGE_BUTTONS; ++i) { 203 | TouchButtonFrequencyRanges[i].deinit(); 204 | } 205 | TouchButtonFrequencyStartStop.deinit(); 206 | TouchButtonGetFrequency.deinit(); 207 | TouchSliderFrequency.deinit(); 208 | # if defined(__AVR__) 209 | TouchButtonWaveform.deinit(); 210 | # endif 211 | #endif 212 | /* 213 | * restore previous state 214 | */ 215 | registerRedrawCallback(sLastRedrawCallback); 216 | } 217 | 218 | void initFrequencyGeneratorPageGui() { 219 | // Frequency slider for 1 to 1000 at top of screen 220 | TouchSliderFrequency.init(FREQ_SLIDER_X, FREQ_SLIDER_Y, FREQ_SLIDER_SIZE, FREQ_SLIDER_MAX_VALUE, 221 | FREQ_SLIDER_MAX_VALUE, 0, COLOR16_BLUE, COLOR16_GREEN, FLAG_SLIDER_SHOW_BORDER | FLAG_SLIDER_IS_HORIZONTAL, 222 | &doSetFrequencyFromSliderValue); 223 | 224 | /* 225 | * Fixed frequency buttons next. 226 | * Example of button handling without button objects. 227 | * We rely on button handles / ID's being simple integers and increasing by one for each init. 228 | * We use a start button for initialization, which changes position, value and caption. 229 | * We use the start button ID as start id for drawing all buttons. 230 | */ 231 | uint16_t tXPos = 0; 232 | uint16_t tFrequency; 233 | #if defined(__AVR__) 234 | // captions are in PGMSPACE 235 | const uint16_t *tFrequencyCaptionPtr = &FixedFrequencyButtonCaptions[0]; 236 | for (uint8_t i = 0; i < NUMBER_OF_FIXED_FREQUENCY_BUTTONS; ++i) { 237 | tFrequency = pgm_read_word(tFrequencyCaptionPtr); 238 | sprintf_P(sStringBuffer, PSTR("%u"), tFrequency); 239 | #else 240 | for (uint8_t i = 0; i < NUMBER_OF_FIXED_FREQUENCY_BUTTONS; ++i) { 241 | tFrequency = FixedFrequencyButtonCaptions[i]; 242 | sprintf(sStringBuffer, "%u", tFrequency); 243 | #endif 244 | 245 | #if defined(SUPPORT_LOCAL_DISPLAY) 246 | TouchButtonFixedFrequency[i]->init(tXPos, 96, BUTTON_WIDTH_10, BUTTON_HEIGHT_6, COLOR16_BLUE, sStringBuffer, TEXT_SIZE_11, 247 | 0, tFrequency, &doSetFixedFrequency); 248 | #else 249 | TouchButtonFirstFixedFrequency.init(tXPos, 98, BUTTON_WIDTH_10, BUTTON_HEIGHT_6, COLOR16_BLUE, sStringBuffer, TEXT_SIZE_11, 250 | 0, tFrequency, &doSetFixedFrequency); 251 | #endif 252 | 253 | tXPos += BUTTON_WIDTH_10 + BUTTON_DEFAULT_SPACING_QUARTER; 254 | #if defined(__AVR__) 255 | tFrequencyCaptionPtr++; 256 | #endif 257 | } 258 | #if !defined(SUPPORT_LOCAL_DISPLAY) 259 | TouchButtonFirstFixedFrequency.mButtonHandle -= NUMBER_OF_FIXED_FREQUENCY_BUTTONS - 1; 260 | #endif 261 | 262 | // Range next 263 | tXPos = 0; 264 | int tYPos = DISPLAY_HEIGHT - BUTTON_HEIGHT_4 - BUTTON_HEIGHT_5 - BUTTON_DEFAULT_SPACING; 265 | for (int i = 0; i < NUMBER_OF_FREQUENCY_RANGE_BUTTONS; ++i) { 266 | uint16_t tButtonColor = BUTTON_AUTO_RED_GREEN_FALSE_COLOR; 267 | if (i == BUTTON_INDEX_SELECTED_INITIAL) { 268 | tButtonColor = BUTTON_AUTO_RED_GREEN_TRUE_COLOR; 269 | } 270 | TouchButtonFrequencyRanges[i].init(tXPos, tYPos, BUTTON_WIDTH_5 + BUTTON_DEFAULT_SPACING_HALF, 271 | BUTTON_HEIGHT_5, tButtonColor, reinterpret_cast(RangeButtonStrings[i]), TEXT_SIZE_22, 272 | FLAG_BUTTON_DO_BEEP_ON_TOUCH, i, &doSetFrequencyRange); 273 | 274 | tXPos += BUTTON_WIDTH_5 + BUTTON_DEFAULT_SPACING - 2; 275 | } 276 | 277 | ActiveTouchButtonFrequencyRange = TouchButtonFrequencyRanges[BUTTON_INDEX_SELECTED_INITIAL]; 278 | 279 | TouchButtonFrequencyStartStop.init(0, DISPLAY_HEIGHT - BUTTON_HEIGHT_4, BUTTON_WIDTH_3, BUTTON_HEIGHT_4, 0, F("Start"), 280 | TEXT_SIZE_26, FLAG_BUTTON_DO_BEEP_ON_TOUCH | FLAG_BUTTON_TYPE_TOGGLE_RED_GREEN, sFrequencyInfo.isOutputEnabled, 281 | &doFrequencyGeneratorStartStop); 282 | TouchButtonFrequencyStartStop.setCaptionForValueTrue(F("Stop")); 283 | 284 | TouchButtonGetFrequency.init(BUTTON_WIDTH_3_POS_2, DISPLAY_HEIGHT - BUTTON_HEIGHT_4, BUTTON_WIDTH_3, 285 | BUTTON_HEIGHT_4, COLOR16_BLUE, F("Hz..."), TEXT_SIZE_22, FLAG_BUTTON_DO_BEEP_ON_TOUCH, 0, &doGetFrequency); 286 | 287 | #if defined(__AVR__) 288 | TouchButtonWaveform.init(BUTTON_WIDTH_3_POS_3, DISPLAY_HEIGHT - BUTTON_HEIGHT_4, BUTTON_WIDTH_3, 289 | BUTTON_HEIGHT_4, COLOR16_BLUE, "", TEXT_SIZE_18, FLAG_BUTTON_DO_BEEP_ON_TOUCH, sFrequencyInfo.Waveform, &doWaveformMode); 290 | setWaveformButtonCaption(); 291 | #endif 292 | } 293 | 294 | void drawFrequencyGeneratorPage(void) { 295 | // do not clear screen here since it is called periodically for GUI refresh while DSO is running 296 | BDButton::deactivateAll(); 297 | BDSlider::deactivateAll(); 298 | #if !defined(ARDUINO) 299 | TouchButtonMainHome.drawButton(); 300 | #else 301 | TouchButtonBack.drawButton(); 302 | #endif 303 | TouchSliderFrequency.drawSlider(); 304 | 305 | BlueDisplay1.drawText(TEXT_SIZE_11_WIDTH, FREQ_SLIDER_Y + 3 * FREQ_SLIDER_SIZE + TEXT_SIZE_11_HEIGHT, F("1"), TEXT_SIZE_11, 306 | COLOR16_BLUE, COLOR_BACKGROUND_FREQ); 307 | #if defined(__AVR__) 308 | BlueDisplay1.drawText(DISPLAY_WIDTH - 5 * TEXT_SIZE_11_WIDTH, 309 | FREQ_SLIDER_Y + 3 * FREQ_SLIDER_SIZE + TEXT_SIZE_11_HEIGHT, F("1000"), TEXT_SIZE_11, COLOR16_BLUE, 310 | COLOR_BACKGROUND_FREQ); 311 | #else 312 | BlueDisplay1.drawText(BlueDisplay1.getDisplayWidth() - 5 * TEXT_SIZE_11_WIDTH, 313 | FREQ_SLIDER_Y + 3 * FREQ_SLIDER_SIZE + TEXT_SIZE_11_HEIGHT, ("1000"), TEXT_SIZE_11, COLOR16_BLUE, 314 | COLOR_BACKGROUND_FREQ); 315 | #endif 316 | 317 | // fixed frequency buttons 318 | // we know that the buttons handles are increasing numbers 319 | #if defined(SUPPORT_LOCAL_DISPLAY) 320 | for (uint8_t i = 0; i < NUMBER_OF_FIXED_FREQUENCY_BUTTONS - 1; ++i) { 321 | // Generate strings each time buttons are drawn since only the pointer to caption is stored in button 322 | sprintf(sStringBuffer, "%u", FixedFrequencyButtonCaptions[i]); 323 | TouchButtonFixedFrequency[i]->setCaption(sStringBuffer); 324 | TouchButtonFixedFrequency[i]->drawButton(); 325 | } 326 | // label last button 1k instead of 1000 which is too long 327 | TouchButtonFixedFrequency[NUMBER_OF_FIXED_FREQUENCY_BUTTONS - 1]->setCaption("1k"); 328 | TouchButtonFixedFrequency[NUMBER_OF_FIXED_FREQUENCY_BUTTONS - 1]->drawButton(); 329 | #else 330 | BDButton tButton(TouchButtonFirstFixedFrequency); 331 | for (uint8_t i = 0; i < NUMBER_OF_FIXED_FREQUENCY_BUTTONS; ++i) { 332 | tButton.drawButton(); 333 | tButton.mButtonHandle++; // Simply increment id to get the next button 334 | } 335 | #endif 336 | 337 | for (uint8_t i = 0; i < NUMBER_OF_FREQUENCY_RANGE_BUTTONS; ++i) { 338 | TouchButtonFrequencyRanges[i].drawButton(); 339 | } 340 | 341 | TouchButtonFrequencyStartStop.drawButton(); 342 | TouchButtonGetFrequency.drawButton(); 343 | #if defined(__AVR__) 344 | TouchButtonWaveform.drawButton(); 345 | #endif 346 | 347 | // show values 348 | printFrequencyAndPeriod(); 349 | } 350 | 351 | /* 352 | * Handle the 10HzRange of frequency GUI 353 | */ 354 | void setFrequencyNormalizedForGUI(float aNormalizedFrequency) { 355 | if (is10HzRange) { 356 | // we must dynamically change frequency range 357 | if (aNormalizedFrequency <= 100) { 358 | setNormalizedFrequencyFactorFromRangeIndex(FREQUENCY_RANGE_INDEX_HERTZ); 359 | aNormalizedFrequency *= 10; 360 | } else { 361 | setNormalizedFrequencyFactorFromRangeIndex(FREQUENCY_RANGE_INDEX_KILO_HERTZ); 362 | aNormalizedFrequency /= 100; 363 | } 364 | } 365 | sFrequencyInfo.FrequencyNormalizedTo_1_to_1000 = aNormalizedFrequency; 366 | } 367 | 368 | #pragma GCC diagnostic ignored "-Wunused-parameter" 369 | 370 | /** 371 | * Convert linear slider value to exponential normalized frequency from 1 to 1000 372 | */ 373 | void doSetFrequencyFromSliderValue(BDSlider *aTheTouchedSlider, uint16_t aFrequencySliderValue) { 374 | float tNormalizedFrequencyFloat = aFrequencySliderValue; 375 | tNormalizedFrequencyFloat = tNormalizedFrequencyFloat / (FREQ_SLIDER_MAX_VALUE / 3); // gives 0-3 376 | // 950 byte program memory required for pow() and log10f() 377 | tNormalizedFrequencyFloat = (pow(10, tNormalizedFrequencyFloat)); // normalize value to 1-1000 378 | setFrequencyNormalizedForGUI(tNormalizedFrequencyFloat); 379 | setWaveformFrequencyAndPrintValues(); 380 | } 381 | 382 | /** 383 | * Set frequency to fixed value 1,2,5,10...,1000 384 | */ 385 | void doSetFixedFrequency(BDButton *aTheTouchedButton, int16_t aNormalizedFrequency) { 386 | setFrequencyNormalizedForGUI(aNormalizedFrequency); 387 | // Play error feedback tone, if frequency is not available for this waveform 388 | bool tErrorOrClippingHappend = setWaveformFrequencyAndPrintValues(); 389 | #if defined(SUPPORT_LOCAL_DISPLAY) 390 | LocalTouchButton::playFeedbackTone(tErrorOrClippingHappend); 391 | #else 392 | BDButton::playFeedbackTone(tErrorOrClippingHappend); 393 | #endif 394 | } 395 | 396 | /** 397 | * Sets the frequency range (mHz - MHz) 398 | * Set color for old and new button 399 | */ 400 | void doSetFrequencyRange(BDButton *aTheTouchedButton, int16_t aInputRangeIndex) { 401 | 402 | if (ActiveTouchButtonFrequencyRange != *aTheTouchedButton) { 403 | // Handling of 10 Hz button 404 | // convert input range index to output range index 405 | if (aInputRangeIndex == INDEX_OF_10HZ) { 406 | is10HzRange = true; 407 | } else { 408 | is10HzRange = false; 409 | } 410 | uint8_t tOutputRangeIndex = aInputRangeIndex; 411 | if (aInputRangeIndex >= INDEX_OF_10HZ) { 412 | tOutputRangeIndex = aInputRangeIndex - 1; 413 | } 414 | 415 | // No MHz for PWM waveforms 416 | if (aInputRangeIndex != FREQUENCY_RANGE_INDEX_MEGA_HERTZ || sFrequencyInfo.Waveform == WAVEFORM_SQUARE) { 417 | 418 | // Set color for old and new button 419 | ActiveTouchButtonFrequencyRange.setButtonColorAndDraw( BUTTON_AUTO_RED_GREEN_FALSE_COLOR); 420 | ActiveTouchButtonFrequencyRange = *aTheTouchedButton; 421 | aTheTouchedButton->setButtonColorAndDraw( BUTTON_AUTO_RED_GREEN_TRUE_COLOR); 422 | 423 | setNormalizedFrequencyFactorFromRangeIndex(tOutputRangeIndex); 424 | setWaveformFrequencyAndPrintValues(); 425 | } 426 | } 427 | } 428 | 429 | #if defined(__AVR__) 430 | void setWaveformButtonCaption(void) { 431 | TouchButtonWaveform.setCaption(getWaveformModePGMString(), (DisplayControl.DisplayPage == DSO_PAGE_FREQUENCY)); 432 | } 433 | #endif 434 | 435 | void doWaveformMode(BDButton *aTheTouchedButton, int16_t aValue) { 436 | #if defined(__AVR__) 437 | cycleWaveformMode(); 438 | setWaveformButtonCaption(); 439 | #endif 440 | } 441 | 442 | #if defined(SUPPORT_LOCAL_DISPLAY) 443 | /** 444 | * gets frequency value from numberpad 445 | * @param aTheTouchedButton 446 | * @param aValue 447 | */ 448 | void doGetFrequency(BDButton *aTheTouchedButton, int16_t aValue) { 449 | TouchSliderFrequency.deactivate(); 450 | float tNumber = getNumberFromNumberPad(NUMBERPAD_DEFAULT_X, 0, COLOR16_BLUE); 451 | // check for cancel 452 | if (!isnan(tNumber)) { 453 | sFrequencyInfo.Frequency = tNumber; 454 | } 455 | drawFrequencyGeneratorPage(); 456 | setWaveformFrequencyAndPrintValues(); 457 | } 458 | #else 459 | 460 | /** 461 | * Handler for number receive event - set frequency to float value 462 | */ 463 | void doSetFrequency(float aValue) { 464 | setWaveformFrequency(aValue); 465 | printFrequencyAndPeriod(); 466 | } 467 | 468 | /** 469 | * Request frequency numerical 470 | */ 471 | void doGetFrequency(BDButton *aTheTouchedButton, int16_t aValue) { 472 | BlueDisplay1.getNumberWithShortPrompt(&doSetFrequency, F("frequency [Hz]")); 473 | } 474 | #endif 475 | 476 | void doFrequencyGeneratorStartStop(BDButton *aTheTouchedButton, int16_t aValue) { 477 | sFrequencyInfo.isOutputEnabled = aValue; 478 | if (aValue) { 479 | // Start timer 480 | #if !defined(__AVR__) 481 | Synth_Timer_Start(); 482 | #endif 483 | setWaveformFrequencyAndPrintValues(); 484 | } else { 485 | // Stop timer 486 | #if defined(__AVR__) 487 | stopWaveform(); 488 | #else 489 | Synth_Timer_Stop(); 490 | #endif 491 | } 492 | } 493 | 494 | /* 495 | * Prints frequency and period and sets slider accordingly 496 | */ 497 | void printFrequencyAndPeriod() { 498 | 499 | float tPeriodMicros; 500 | 501 | #if defined(__AVR__) 502 | dtostrf(sFrequencyInfo.FrequencyNormalizedTo_1_to_1000, 9, 3, &sStringBuffer[20]); 503 | sprintf_P(sStringBuffer, PSTR("%s%cHz"), &sStringBuffer[20], FrequencyRangeChars[sFrequencyInfo.FrequencyRangeIndex]); 504 | 505 | #else 506 | snprintf(sStringBuffer, sizeof sStringBuffer, "%9.3f%cHz", sFrequencyInfo.FrequencyNormalizedTo_1_to_1000, 507 | FrequencyRangeChars[sFrequencyInfo.FrequencyRangeIndex]); 508 | #endif 509 | 510 | // print frequency 511 | BlueDisplay1.drawText(FREQ_SLIDER_X + 2 * TEXT_SIZE_22_WIDTH, TEXT_SIZE_22_HEIGHT, sStringBuffer, TEXT_SIZE_22, 512 | COLOR16_RED, COLOR_BACKGROUND_FREQ); 513 | 514 | // output period use float, since we have 1/8 us for square wave 515 | tPeriodMicros = getPeriodMicros(); 516 | 517 | char tUnitChar = '\xB5'; // micro 518 | if (tPeriodMicros > 10000) { 519 | tPeriodMicros /= 1000; 520 | tUnitChar = 'm'; 521 | } 522 | 523 | #if defined(__AVR__) 524 | dtostrf(tPeriodMicros, 10, 3, &sStringBuffer[20]); 525 | sprintf_P(sStringBuffer, PSTR("%s%cs"), &sStringBuffer[20], tUnitChar); 526 | #else 527 | snprintf(sStringBuffer, sizeof sStringBuffer, "%10.3f%cs", tPeriodMicros, tUnitChar); 528 | #endif 529 | BlueDisplay1.drawText(FREQ_SLIDER_X, TEXT_SIZE_22_HEIGHT + 4 + TEXT_SIZE_22_ASCEND, sStringBuffer, TEXT_SIZE_22, 530 | COLOR16_BLUE, COLOR_BACKGROUND_FREQ); 531 | 532 | // 950 byte program memory required for pow() and log10f() 533 | uint16_t tSliderValue; 534 | tSliderValue = log10f(sFrequencyInfo.FrequencyNormalizedTo_1_to_1000) * (FREQ_SLIDER_MAX_VALUE / 3); 535 | if (is10HzRange) { 536 | if (sFrequencyInfo.FrequencyRangeIndex == FREQUENCY_RANGE_INDEX_KILO_HERTZ) { 537 | tSliderValue += 2 * (FREQ_SLIDER_MAX_VALUE / 3); 538 | } else { 539 | tSliderValue -= (FREQ_SLIDER_MAX_VALUE / 3); 540 | } 541 | } 542 | TouchSliderFrequency.setValueAndDrawBar(tSliderValue); 543 | } 544 | 545 | /** 546 | * Computes Autoreload value for synthesizer from 8,381 mHz (0xFFFFFFFF) to 18 MHz (0x02) and prints frequency value 547 | * @param aSetSlider 548 | * @param global variable Frequency 549 | * @return true if error / clipping happened 550 | */ 551 | bool setWaveformFrequencyAndPrintValues() { 552 | bool tErrorOrClippingHappend = setWaveformFrequencyFromNormalizedValues(); 553 | printFrequencyAndPeriod(); 554 | return tErrorOrClippingHappend; 555 | } 556 | 557 | #if !defined(__AVR__) 558 | // content for AVR is in Waveforms.cpp 559 | 560 | #define WAVEFORM_SQUARE 0 561 | #define WAVEFORM_SINE 1 562 | #define WAVEFORM_TRIANGLE 2 563 | #define WAVEFORM_SAWTOOTH 3 564 | 565 | void setNormalizedFrequencyFactorFromRangeIndex(uint8_t aFrequencyRangeIndex) { 566 | sFrequencyInfo.FrequencyRangeIndex = aFrequencyRangeIndex; 567 | uint32_t tNormalizedFactorTimes1000 = 1; 568 | while (aFrequencyRangeIndex > 0) { 569 | tNormalizedFactorTimes1000 *= 1000; 570 | aFrequencyRangeIndex--; 571 | } 572 | sFrequencyInfo.FrequencyNormalizedFactorTimes1000 = tNormalizedFactorTimes1000; 573 | } 574 | 575 | /* 576 | * Set display values sFrequencyNormalized and sFrequencyFactorIndex 577 | * 578 | * Problem is set e.g. value of 1 Hz as "1000mHz" or "1Hz"? 579 | * so we just try to keep the existing range. 580 | * First put value of 1000 to next range, 581 | * then undo if value < 1.00001 and existing range is one lower 582 | */ 583 | void setNormalizedFrequencyAndFactor(float aFrequency) { 584 | uint8_t tFrequencyRangeIndex = 1; 585 | // normalize Frequency to 1 - 1000 and compute FrequencyRangeIndex 586 | if (aFrequency < 1) { 587 | tFrequencyRangeIndex = 0; //mHz 588 | aFrequency *= 1000; 589 | } else { 590 | // 1000.1 to avoid switching to next range because of resolution issues 591 | while (aFrequency >= 1000) { 592 | aFrequency /= 1000; 593 | tFrequencyRangeIndex++; 594 | } 595 | } 596 | 597 | // check if tFrequencyFactorIndex - 1 fits better 598 | if (aFrequency < 1.00001 && sFrequencyInfo.FrequencyRangeIndex == (tFrequencyRangeIndex - 1)) { 599 | aFrequency *= 1000; 600 | tFrequencyRangeIndex--; 601 | } 602 | 603 | setNormalizedFrequencyFactorFromRangeIndex(tFrequencyRangeIndex); 604 | sFrequencyInfo.FrequencyNormalizedTo_1_to_1000 = aFrequency; 605 | } 606 | 607 | bool setWaveformFrequency(float aValue) { 608 | bool hasError = false; 609 | if (sFrequencyInfo.Waveform == WAVEFORM_SQUARE) { 610 | float tDivider = 36000000 / aValue; 611 | uint32_t tDividerInt = tDivider; 612 | if (tDividerInt < 2) { 613 | hasError = true; 614 | tDividerInt = 2; 615 | } 616 | 617 | # if defined(STM32F30X) 618 | Synth_Timer32_SetReloadValue(tDividerInt); 619 | # else 620 | uint32_t tPrescalerValue = (tDividerInt >> 16) + 1; // +1 since at least divider by 1 621 | if (tPrescalerValue > 1) { 622 | //we have prescaler > 1 -> adjust reload value to be less than 0x10001 623 | tDividerInt /= tPrescalerValue; 624 | } 625 | Synth_Timer16_SetReloadValue(tDividerInt, tPrescalerValue); 626 | tDividerInt *= tPrescalerValue; 627 | # endif 628 | sFrequencyInfo.ControlValue.DividerInt = tDividerInt; 629 | // recompute frequency 630 | sFrequencyInfo.Frequency = 36000000 / tDividerInt; 631 | setNormalizedFrequencyAndFactor(sFrequencyInfo.Frequency); 632 | } else { 633 | hasError = true; 634 | } 635 | 636 | return hasError; 637 | } 638 | 639 | bool setWaveformFrequencyFromNormalizedValues() { 640 | return setWaveformFrequency((sFrequencyInfo.FrequencyNormalizedTo_1_to_1000 * sFrequencyInfo.FrequencyNormalizedFactorTimes1000) / 1000); 641 | } 642 | 643 | float getPeriodMicros() { 644 | return sFrequencyInfo.ControlValue.DividerInt / 36.0f; 645 | } 646 | #endif // !defined(__AVR__) 647 | 648 | #endif // _FREQUENCY_GENERATOR_PAGE_HPP 649 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | # [Arduino-Simple-DSO](https://github.com/ArminJo/Arduino-Simple-DSO) 4 | This DSO needs only a standard Arduino-Uno or Arduino-Nano, a HC-05 Bluetooth module or a micro USB OTG cable / adapter, a few resistors and capacitators and this software. 5 | 6 | [![Badge License: GPLv3](https://img.shields.io/badge/License-GPLv3-brightgreen.svg)](https://www.gnu.org/licenses/gpl-3.0) 7 |     8 | [![Badge Version](https://img.shields.io/github/v/release/ArminJo/Arduino-Simple-DSO?include_prereleases&color=yellow&logo=DocuSign&logoColor=white)](https://github.com/ArminJo/Arduino-Simple-DSO/releases/latest) 9 |     10 | [![Badge Commits since latest](https://img.shields.io/github/commits-since/ArminJo/Arduino-Simple-DSO/latest?color=yellow)](https://github.com/ArminJo/Arduino-Simple-DSO/commits/master) 11 |     12 | [![Badge Build Status](https://github.com/ArminJo/Arduino-Simple-DSO/workflows/TestCompile/badge.svg)](https://github.com/ArminJo/Arduino-Simple-DSO/actions) 13 |     14 | ![Badge Hit Counter](https://visitor-badge.laobi.icu/badge?page_id=ArminJo_Arduino-Simple-DSO) 15 |
16 | 17 |
18 | 19 |
20 | 21 | 22 | | Simple DSO with no attenuator on breadboard | DSO Chart screen | 23 | | :-: | :-: | 24 | | ![DSO with passive attenuator on breadboard](https://github.com/ArminJo/Arduino-Simple-DSO/blob/master/pictures/ArduinoDSO_simple.jpg) | ![DSO chart screen](https://github.com/ArminJo/Arduino-Simple-DSO/blob/master/pictures/Chart.jpg) | 25 | 26 | The application is also available as an [example](https://github.com/ArminJo/Arduino-BlueDisplay/tree/master/examples/SimpleTouchScreenDSO) of the 27 | [Arduino BlueDisplay library](https://github.com/ArminJo/Arduino-BlueDisplay) - use *File -> Examples -> Examples from Custom Libraries*. 28 | You can load the library with *Tools -> Manage Libraries...* or *Ctrl+Shift+I*. Use "BlueDisplay" as filter string. 29 | 30 | 31 | ## Features 32 | - 150 kSamples per second with [good quality](#linearity-of-the-atmega328pb-adc-converter). 33 | - 300 kSamples per second with acceptable quality because of internal ADC limitations. 34 | - Full touch screen control of all parameters. 35 | - AC Measurement supported by using (passive) external attenuator circuit (see below). 36 | - Automatic trigger level, range and offset selection. 37 | - Manual trigger level and range select. 38 | - Trigger delay. 39 | - External trigger. 40 | - 1120 byte data buffer - 3.5 times display size. 41 | - Display of min, max, average and peak to peak values. 42 | - Display of period and frequency. 43 | - 3 different types of external attenuator, detected by software. 44 | - no attenuator (pin 8+9 left open). 45 | - passive attenuator with /1, /10, /100 attenuation (pin 8 connected to ground). 46 | - active attenuator (pin 9 connected to ground) - still experimental. 47 | - Using 1.1 volt internal reference. 5 V (VCC) is also selectable and is useful if no attenuator is attached. 48 | 49 | - Integrated frequency generator using 16 bit Timer1. Frequency from 119 mHz (8.388 second) to 8 MHz 50 | - Integrated PWM Waveform generator for sinus, triangle and sawtooth using 16 bit Timer1. Frequency from 1.9 mHz to 7.8 kHz 51 | 52 | ## Bill of material 53 | 1. Arduino Nano 54 | 2. Breadboard 400 points 55 | 3. Resistors 56 | - Resistors for the simple (0-5 V) version: 1x 10 kΩ, 2x 100 k, 1x 4 M or more. 57 | - Resistors for the 3 range (0-110 V) version: 1x 2.2 kΩ, 2x 10 k, 3x 100 k, 2x 220 k, 2x 1 M, 1x 4 M or greater 58 | 4. Capacitors 59 | - Capacitors for the simple version: 1x 100 nF / 10 V (or more) 60 | - Capacitors for the 3 range (0-110 V) version: 4x 100 nF / 100 V (or more), 6.8 µF 61 | 5. Jumper wires 62 | 63 | Optional for Bluetooth connection 64 | 6. HC-05 Bluetooth module 65 | 7. Schottky diode e.g. BAT42 66 | 67 | # INSTRUCTIONS FOR USE 68 | The DSO software has 4 pages. 69 | 1. The start page which shows all the hidden buttons available at the chart page. 70 | 2. The chart page which shows the data and info line(s). 71 | 3. The settings page. 72 | 4. The frequency generator page. 73 | 74 | ## CHART PAGE 75 | | DSO Chart analyze screen | DSO Chart analyze screen with long info | 76 | | :-: | :-: | 77 | | ![DSO chart screen](https://github.com/ArminJo/Arduino-Simple-DSO/blob/master/pictures/Chart.jpg) | ![DSO chart screen with long info](https://github.com/ArminJo/Arduino-Simple-DSO/blob/master/pictures/Chart_Long_Info.jpg) | 78 | 79 | Here you see the current data. This page has two modes, the **acquisition** (measurement running) and the **analyze** (data stored) mode. 80 | The horizontal violet line is the trigger level line and the two light green lines in analyze mode are the maximum and minimum level lines. 81 | On this page you can: 82 | - Start and stop a measurement. 83 | - Start a single one time measurement (**Singleshot**). 84 | - Toggle the history mode. 85 | - Go to the settings page. 86 | - Change **timebase** by **horizontal swiping** in acquisition mode. 87 | - Scroll through the 3 screen data buffer by **horizontal swiping** in analyze mode. 88 | - If manual range selection enabled, change the range by **vertical swiping**. 89 | - Change the info display from short to long to no info by **short touching** on the display. See below for info display reference. 90 | - Display the hidden buttons by doing a **long touch**. 91 | - Touch the **light yellow vertical bar** at the left to enable the voltage picker line (which is drawn destructive). 92 | - If enabled, trigger value can be set by touching the **light violet vertical bar** in the 4. left grid. 93 | If switching info mode, the chart content will be restored. 94 | 95 | ### SHORT INFO LINE REFERENCE 96 | - Arithmetic-average and peak to peak voltage of actual chart (In analyze mode, chart is longer than the display!) 97 | - Frequency 98 | - Timebase for div (31 pixel) 99 | 100 | ### LONG INFO LINE REFERENCE 101 | First line 102 | - Timebase for div (31 pixel) 103 | - Slope of trigger 104 | - Input channel: (0-5), T->AVR-temperature, R->1.1 volt-internal-reference G->internal-ground 105 | - Minimum, arithmetic-average, max and peak to peak voltage of actual chart (In hold mode, chart is longer than display!) 106 | - Trigger level 107 | - Reference used: 5=5 volt, 1=1.1 volt-internal-reference 108 | 109 | Second line 110 | - Frequency 111 | - Period 112 | - first interval (pulse for slope ascending) 113 | - second interval (pause for slope ascending) 114 | 115 | ## SETTINGS PAGE GUI 116 | | DSO settings menu | DSO frequency / waveform generator menu | 117 | | :-: | :-: | 118 | | ![DSO settings menu](https://github.com/ArminJo/Arduino-Simple-DSO/blob/master/pictures/Settings_Passive_Attenuator.jpg) | ![Frequency / waveform generator menu](https://github.com/ArminJo/Arduino-Simple-DSO/blob/master/pictures/Frequency.jpg) | 119 | 120 | On this page you have all buttons to modify the **DSO acquisition mode**, to select the different **ADC channels** and for **page navigation** 121 | above the last button row the minimum stack size, the supply voltage and the internal chip temperature is shown. 122 | The stack size is required for testing different buffer size values during development and the temperature may be quite inaccurate. 123 | - **History** -> **red** history off, **green** history on, i.e. old chart data is not deleted, it stays as a light green trace. This button is also available (invisible) at the chart page. 124 | - Slope - **Slope A** -> trigger on ascending slope, **Slope D** -> trigger on descending slope. 125 | - **Back** -> Back to chart page. 126 | - **Trigger delay** -> Trigger delay can be numerical specified from 4 µs to 64.000.000 µs (64 seconds, if you really want). Microseconds resolution is used for values below 64.000. 127 | - Trigger - the trigger value can be set on the chart page by touching the light violet vertical bar in the 4. left grid. 128 | - **Trigger auto** -> let the DSO compute the trigger value using the average of the last measurement. 129 | - **Trigger man timeout** -> use manual trigger value, but with timeout, i.e. if trigger condition not met, new data is shown after timeout. 130 | This is not really a manual trigger level mode, but it helps to find the right trigger value. 131 | -**Trigger man** -> use manual trigger value, but without timeout, i.e. if trigger condition not met, no new data is shown. 132 | -**Trigger free** means free running trigger, i.e. trigger condition is always met. 133 | -**Trigger ext** uses pin 2 as external trigger source. 134 | 135 | - Input selector 136 | - **%1** -> Pin A0 with no attenuator, only a 10 kΩ protection resistor. 137 | - **%10** -> Pin A1 with an 1 to 10 attenuator. 138 | - **%100** -> Pin A2 with an 1 to 100 attenuator. 139 | - **CH 3** -> sequences through the channels **CH 4**, **Temp** (internal temperature sensor), **VRef** (internal reference). 140 | - **Frequency Generator** -> go to frequency generator page. 141 | - Range - There a 3 ranges, 0-2.5 , 0-5 and 0-10 volt 142 | - **Range auto** -> let the DSO choose the range based on the minimum and maximum values of the last measurement. 143 | - **Range man** -> select the range by **vertical swiping** on the chart page. 144 | - Offset 145 | - **Offset 0V** -> Range starts at 0 volt. 146 | - **Offset auto** -> For small signals with a high DC offset. If range is not the lowest one and the signal has a DC offset, then a lower range is choosen and the display offset is adapted to show the complete signal 147 | - **Offset man** 148 | - **DC** / **AC** 149 | - Since the internal ADC converter has only a DC input, **AC** offsets the inputs DC value to 1/2 reference using Arduino pin A5 and compensates this offset for the display. 150 | Therefore you must apply the signal using a capacitor! 151 | - Reference voltage 152 | - **Ref 1.1V** (recommended if having attenuators) -> uses the internal 1.1 volt reference for the ADC. 153 | - **Ref VCC** -> uses VCC (5 volt supply) as reference for the ADC. 154 | 155 | ## TOUCH 156 | Short touch switches info output, long touch shows active GUI elements. 157 | 158 | ## Waveform PWM output 159 | 160 | |Maximum values | Minimum values| 161 | | :--- | :--- | 162 | |SINE: clip to minimum 8 samples per period => 128 µs / 7812.5 Hz |7,421 mHz| 163 | |SAWTOOTH: clip to minimum 16 samples per period => 256 µs / 3906.25 Hz |3.725 mHz| 164 | |TRIANGLE: clip to minimum 32 samples per period => 512 µs / 1953.125 Hz|1.866 mHz| 165 | 166 | ### RC-Filter suggestions 167 | - Simple: 2.2 kΩ and 100 nF 168 | - 2nd order (good for sine and triangle): 1 kΩ and 100 nF -> 4.7 kΩ and 22 nF 169 | - 2nd order (better for sawtooth): 1 kΩ and 22 nF -> 4.7 kΩ and 4.7 nF 170 | 171 | **Do not run DSO acquisition and non square wave waveform generation at the same time.** 172 | Because of the interrupts at 62 kHz rate, DSO is almost not usable during non square wave waveform generation 173 | and waveform frequency is not stable and decreased, since not all TIMER1 OVERFLOW interrupts are handled. 174 | 175 | # SCREENSHOTS 176 | | DSO start screen | DSO at work | 177 | | :-: | :-: | 178 | | ![DSO start screen](https://github.com/ArminJo/Arduino-Simple-DSO/blob/master/pictures/Welcome.jpg) | ![DSO at work](https://github.com/ArminJo/Arduino-Simple-DSO/blob/master/pictures/DSO+Tablet.jpg) | 179 | | DSO chart screen | DSO chart screen with long info | 180 | | ![DSO chart screen](https://github.com/ArminJo/Arduino-Simple-DSO/blob/master/pictures/Chart.jpg) | ![DSO chart screen with long info](https://github.com/ArminJo/Arduino-Simple-DSO/blob/master/pictures/Chart_Long_Info.jpg) | 181 | 182 | ## Linearity of the ATmega328P(B) ADC converter 183 | The captured signal was generated with a STM32F303 DAC and the DSO input range was chosen to see the LSB of the 10 bit ADC conversion. 184 | 185 | | All ranges including the 1 ms range (up to 30 kSamples per second / 26 µs conversion time) have almost perfect linearity. | In the 50 µs to 10 µs ranges with 300 kSamples per second (3 µs conversion time) the linearity is only acceptable. | 186 | | :-: | :-: | 187 | | ![26 µs conversion](https://github.com/ArminJo/Arduino-Simple-DSO/blob/master/pictures/Linearity_26us_conversion_time.jpg) | ![3 µs conversion](https://github.com/ArminJo/Arduino-Simple-DSO/blob/master/pictures/Linearity_3us_conversion_time.jpg) | 188 | | First small linearity issues can be seen in the 496 µs range with 60 kSamples per second (13 µs conversion time). | And in the 101 µs range with 150 kSamples per second (6.5 µs conversion time). | 189 | | ![13 µs conversion](https://github.com/ArminJo/Arduino-Simple-DSO/blob/master/pictures/Linearity_13us_conversion_time.jpg) | ![6.5 µs conversion](https://github.com/ArminJo/Arduino-Simple-DSO/blob/master/pictures/Linearity_6us5_conversion_time.jpg) | 190 | 191 | # SCHEMATICS 192 | | SIMPLE 1 RANGE VERSION | 3 RANGE VERSION | 193 | | :-: | :-: | 194 | | ![Fritzing schematic](https://github.com/ArminJo/Arduino-Simple-DSO/blob/master/extras/Arduino_Nano_DSO_simple_Schaltplan.png) | ![Fritzing schematic](https://github.com/ArminJo/Arduino-Simple-DSO/blob/master/extras/Arduino_Nano_DSO_BT_full_Schaltplan.png) | 195 | | ![Fritzing breadboard](https://github.com/ArminJo/Arduino-Simple-DSO/blob/master/extras/Arduino_Nano_DSO_simple_Steckplatine.png) | ![Fritzing breadboard](https://github.com/ArminJo/Arduino-Simple-DSO/blob/master/extras/Arduino_Nano_DSO_BT_full_Steckplatine.png) | 196 | | ![DSO with passive attenuator on breadboard](https://github.com/ArminJo/Arduino-Simple-DSO/blob/master/pictures/ArduinoDSO_simple.jpg) | ![DSO with passive attenuator on breadboard](https://github.com/ArminJo/Arduino-Simple-DSO/blob/master/pictures/ArduinoDSO.jpg) | 197 | 198 | # Revision History 199 | ### Version 3.3 - 02/2023 200 | - Compatible to new BlueDisplay library version. 201 | 202 | ### Version 3.2 - 11/2019 203 | - Clear data buffer at start and at switching inputs. 204 | - Multiline button caption. 205 | 206 | ### Version 3.1 207 | - Stop response improved for fast mode. 208 | - Value computation for ultra fast modes fixed. 209 | - millis() timer compensation formula fixed. 210 | - AC/DC button and info line handling improved. 211 | 212 | -------------------------------------------------------------------------------- /SimpleDSO_BlueDisplay.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SimpleDSO_BlueDisplay.h 3 | * 4 | * Copyright (C) 2015-2023 Armin Joachimsmeyer 5 | * Email: armin.joachimsmeyer@gmail.com 6 | * 7 | * This file is part of Arduino-Simple-DSO https://github.com/ArminJo/Arduino-Simple-DSO. 8 | * 9 | * Arduino-Simple-DSO is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 17 | * See the GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #ifndef _SIMPLE_DSO_BLUEDISPLAY_H 24 | #define _SIMPLE_DSO_BLUEDISPLAY_H 25 | 26 | #include "TouchDSOCommon.h" 27 | 28 | // Internal version 29 | #define VERSION_DSO "3.3" 30 | /* 31 | * Version 3.3 - 02/2023 32 | * - Compatible to new BlueDisplay library version. 33 | * 34 | * Version 3.2 - 11/2019 35 | * - Clear data buffer at start and at switching inputs. 36 | * - Multiline button caption. 37 | * 38 | * Version 3.1 39 | * - Stop response improved for fast mode. 40 | * - Value computation for ultra fast modes fixed. 41 | * - millis() timer compensation formula fixed. 42 | * - AC/DC button and info line handling improved. 43 | */ 44 | 45 | /**************************************************************************** 46 | * Change this if you have reprogrammed the hc05 module for other baud rate 47 | ***************************************************************************/ 48 | #if !defined(BLUETOOTH_BAUD_RATE) 49 | //#define BLUETOOTH_BAUD_RATE BAUD_115200 50 | #define BLUETOOTH_BAUD_RATE BAUD_9600 51 | #endif 52 | 53 | #define MILLIS_BETWEEN_INFO_OUTPUT 1000 54 | 55 | #define THOUSANDS_SEPARATOR '.' 56 | 57 | /* 58 | * Pins on port B 59 | */ 60 | #define OUTPUT_MASK_PORTB 0X2C 61 | #define ATTENUATOR_DETECT_PIN_0 8 // PortB0 in INPUT_PULLUP mode 62 | #define ATTENUATOR_DETECT_PIN_1 9 // PortB1 in INPUT_PULLUP mode 63 | #define TIMER_1_OUTPUT_PIN 10 // Frequency generation OC1B TIMER1 64 | #define VEE_PIN 11 // // PortB3 OC2A TIMER2 Square wave for VEE (-5 volt) generation 65 | #define DEBUG_PIN 13 // PortB5 PIN 13 66 | 67 | /* 68 | * Pins on port B 69 | */ 70 | #define OUTPUT_MASK_PORTC 0X20 // PC5 ADC5 71 | #define AC_DC_BIAS_PIN A5 // PC5 ADC5 72 | 73 | /* 74 | * Pins on port D 75 | * AC/DC, attenuator control and external trigger input 76 | * !!! Pin layout only for Atmega328 !!! 77 | */ 78 | #define CONTROL_PORT PORTD 79 | #define CONTROL_DDR DDRD 80 | #define EXTERN_TRIGGER_INPUT_PIN 2// PD2 81 | 82 | // Control 83 | #define ATTENUATOR_SHIFT 4 // Bit 4+5 84 | #define ATTENUATOR_MASK 0x30 // Bit 4+5 85 | #define OUTPUT_MASK_PORTD 0xF0 // Bit 4-7 86 | #define ATTENUATOR_0_PIN 4 // PD4 87 | #define ATTENUATOR_1_PIN 5 // PD5 88 | #define AC_DC_RELAY_PIN 6 // PD6 89 | 90 | // GUI element colors 91 | 92 | #define COLOR_SLIDER RGB(0xD0,0xD0,0xD0) 93 | 94 | // No trigger wait timeout for modes != TRIGGER_DELAY_NONE 95 | #define TRIGGER_DELAY_NONE 0 96 | #define TRIGGER_DELAY_MICROS 1 97 | #define TRIGGER_DELAY_MILLIS 2 98 | 99 | #define TRIGGER_DELAY_MICROS_POLLING_ADJUST_COUNT 1 // estimated value to be subtracted from value because of fast mode initial delay 100 | #define TRIGGER_DELAY_MICROS_ISR_ADJUST_COUNT 4 // estimated value to be subtracted from value because of ISR initial delay 101 | 102 | // States of tTriggerStatus 103 | #define TRIGGER_STATUS_START 0 // No trigger condition met 104 | #define TRIGGER_STATUS_AFTER_HYSTERESIS 1 // slope and hysteresis condition met, wait to go beyond trigger level without hysteresis. 105 | #define TRIGGER_STATUS_FOUND 2 // Trigger condition met - Used for shorten ISR handling 106 | #define TRIGGER_STATUS_FOUND_AND_WAIT_FOR_DELAY 3 // Trigger condition met and waiting for ms delay 107 | 108 | /* 109 | * External attenuator values 110 | */ 111 | #define ATTENUATOR_TYPE_NO_ATTENUATOR 0 // No attenuator at all. Start with aRef = VCC -> see ATTENUATOR_DETECT_PIN_0 112 | #define ATTENUATOR_TYPE_FIXED_ATTENUATOR 1 // Fixed attenuator at Channel0, 1, 2 113 | #define ATTENUATOR_TYPE_ACTIVE_ATTENUATOR 2 // to be developed 114 | #define NUMBER_OF_CHANNEL_WITH_ACTIVE_ATTENUATOR 2 115 | 116 | struct MeasurementControlStruct { 117 | // State 118 | bool isRunning; 119 | bool StopRequested; 120 | // Used to disable trigger timeout and to specify full buffer read with stop after first read. 121 | bool isSingleShotMode; 122 | 123 | float VCC; // Volt of VCC 124 | uint8_t ADCReferenceShifted; // DEFAULT = 1 =VCC INTERNAL = 3 = 1.1 volt 125 | 126 | // Input select 127 | uint8_t ADMUXChannel; 128 | uint8_t AttenuatorType; //ATTENUATOR_TYPE_NO_ATTENUATOR, ATTENUATOR_TYPE_SIMPLE_ATTENUATOR, ATTENUATOR_TYPE_ACTIVE_ATTENUATOR 129 | bool ChannelHasActiveAttenuator; 130 | 131 | // AC / DC Switch 132 | bool ChannelHasAC_DCSwitch; // has AC / DC switch - only for channels with active or passive attenuators. Is at least false for TEMP and REF channels 133 | bool ChannelIsACMode; // AC Mode for actual channel 134 | bool isACMode; // storage for user AC mode setting used to restore AC mode when switching back from channel without AC capabilities. 135 | uint16_t RawDSOReadingACZero; 136 | 137 | // Trigger 138 | bool TriggerSlopeRising; 139 | uint16_t RawTriggerLevel; 140 | uint16_t RawTriggerLevelHysteresis; // The RawTriggerLevel +/- hysteresis depending on slope (- for TriggerSlopeRising) - Used for computeMicrosPerPeriod() 141 | uint16_t RawHysteresis; // quarter of peak to peak value 142 | uint16_t ValueBeforeTrigger; 143 | 144 | uint32_t TriggerDelayMillisEnd; // value of millis() at end of milliseconds trigger delay 145 | uint16_t TriggerDelayMillisOrMicros; 146 | uint8_t TriggerDelayMode; // TRIGGER_DELAY_NONE 0, TRIGGER_DELAY_MICROS 1, TRIGGER_DELAY_MILLIS 2. Threshold is UINT16_MAX 147 | 148 | // Using type TriggerMode instead of uint8_t increases program size by 76 bytes 149 | uint8_t TriggerMode; // adjust values automatically 150 | uint8_t OffsetMode; //OFFSET_MODE_0_VOLT, OFFSET_MODE_AUTOMATIC, OFFSET_MODE_MANUAL 151 | uint8_t TriggerStatus; //TRIGGER_STATUS_START 0, TRIGGER_STATUS_BEFORE_THRESHOLD 1, TRIGGER_STATUS_OK 2 152 | uint8_t TriggerSampleCountPrecaler; // for dividing sample count by 256 - to avoid 32bit variables in ISR 153 | uint16_t TriggerSampleCountDividedBy256; // for trigger timeout 154 | uint16_t TriggerTimeoutSampleCount; // ISR max samples before trigger timeout. Used only for trigger modes with timeout. 155 | 156 | // Statistics (for info and auto trigger) 157 | uint16_t RawValueMin; 158 | uint16_t RawValueMax; 159 | uint16_t ValueMinForISR; 160 | uint16_t ValueMaxForISR; 161 | uint16_t ValueAverage; 162 | uint32_t IntegrateValueForAverage; 163 | uint32_t PeriodMicros; 164 | uint32_t PeriodFirst; // Length of first pulse or pause 165 | uint32_t PeriodSecond; // Length of second pulse or pause 166 | uint32_t FrequencyHertz; 167 | 168 | // Timebase 169 | bool AcquisitionFastMode; 170 | uint8_t TimebaseIndex; 171 | uint8_t TimebaseHWValue; 172 | 173 | bool RangeAutomatic; // RANGE_MODE_AUTOMATIC, MANUAL 174 | 175 | // Shift and scale 176 | uint16_t OffsetValue; 177 | uint8_t AttenuatorValue; // 0 for direct input or channels without attenuator, 1 -> factor 10, 2 -> factor 100, 3 -> input shortcut 178 | uint8_t ShiftValue; // shift (division) value (0-2) for different voltage ranges 179 | uint16_t HorizontalGridSizeShift8; // depends on shift for 5 volt reference 0,02 -> 41 other -> 51.2 180 | float HorizontalGridVoltage; // voltage per grid for offset etc. 181 | int8_t OffsetGridCount; // number of bottom line for offset != 0 volt. 182 | uint32_t TimestampLastRangeChange; 183 | }; 184 | 185 | extern struct MeasurementControlStruct MeasurementControl; 186 | 187 | // values for DisplayPage 188 | // using enums increases code size by 120 bytes for Arduino 189 | #define DSO_PAGE_START 0 // Start GUI 190 | #define DSO_PAGE_CHART 1 // Chart in analyze and running mode 191 | #define DSO_PAGE_SETTINGS 2 192 | #define DSO_PAGE_FREQUENCY 3 193 | #ifndef AVR 194 | #define DSO_PAGE_MORE_SETTINGS 4 195 | #define DSO_PAGE_SYST_INFO 5 196 | #endif 197 | 198 | #define DSO_SUB_PAGE_MAIN 0 199 | #define DSO_SUB_PAGE_FFT 1 200 | 201 | // modes for showInfoMode 202 | #define INFO_MODE_NO_INFO 0 203 | #define INFO_MODE_SHORT_INFO 1 204 | #define INFO_MODE_LONG_INFO 2 205 | struct DisplayControlStruct { 206 | uint8_t TriggerLevelDisplayValue; // For clearing old line of manual trigger level setting 207 | int8_t XScale; // Factor for X Data expansion(>0) 0 = no scale, 2->display 1 value 2 times etc. 208 | 209 | uint8_t DisplayPage; // START, CHART, SETTINGS, MORE_SETTINGS 210 | uint8_t DisplaySubPage; // DSO_SUB_PAGE_FFT 211 | 212 | bool DrawWhileAcquire; 213 | uint8_t showInfoMode; 214 | 215 | bool showHistory; 216 | uint16_t EraseColor; 217 | }; 218 | extern DisplayControlStruct DisplayControl; 219 | 220 | /* 221 | * Data buffer 222 | */ 223 | struct DataBufferStruct { 224 | uint8_t DisplayBuffer[DISPLAY_WIDTH]; 225 | uint8_t * DataBufferNextInPointer; 226 | uint8_t * DataBufferNextDrawPointer; // pointer to DataBuffer - for draw-while-acquire mode 227 | uint16_t DataBufferNextDrawIndex; // index in DisplayBuffer - for draw-while-acquire mode 228 | // to detect end of acquisition in interrupt service routine 229 | uint8_t * DataBufferEndPointer; 230 | // Used to synchronize ISR with main loop 231 | bool DataBufferFull; 232 | // AcqusitionSize is DISPLAY_WIDTH except on last acquisition before stop then it is DATABUFFER_SIZE 233 | uint16_t AcquisitionSize; 234 | // Pointer for horizontal scrolling 235 | uint8_t * DataBufferDisplayStart; 236 | uint8_t DataBuffer[DATABUFFER_SIZE]; // contains also display values i.e. (DISPLAY_VALUE_FOR_ZERO - 8BitValue) 237 | }; 238 | extern DataBufferStruct DataBufferControl; 239 | 240 | // Utility section 241 | uint16_t getInputRawFromDisplayValue(uint8_t aDisplayValue); 242 | float getFloatFromDisplayValue(uint8_t aDisplayValue); 243 | void printSingleshotMarker(); 244 | void clearSingleshotMarker(); 245 | extern "C" void INT0_vect(); 246 | 247 | // for printf etc. 248 | #if defined(__AVR__) 249 | #define SIZEOF_STRINGBUFFER 50 250 | #else 251 | #define SIZEOF_STRINGBUFFER 240 252 | #endif 253 | extern char sStringBuffer[SIZEOF_STRINGBUFFER]; 254 | 255 | extern BDButton TouchButtonBack; 256 | // global flag for page control. Is evaluated by calling loop or page and set by buttonBack handler 257 | extern bool sBackButtonPressed; 258 | 259 | #endif // _SIMPLE_DSO_BLUEDISPLAY_H 260 | -------------------------------------------------------------------------------- /TouchDSOCommon.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TouchDSOCommon.h 3 | * 4 | * Declarations for AVR and ARM common section 5 | * 6 | * Copyright (C) 2017-2023 Armin Joachimsmeyer 7 | * Email: armin.joachimsmeyer@gmail.com 8 | * 9 | * This file is part of Arduino-Simple-DSO https://github.com/ArminJo/Arduino-Simple-DSO. 10 | * 11 | * Arduino-Simple-DSO is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 19 | * See the GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | * 24 | */ 25 | 26 | #ifndef _TOUCH_DSO_COMMON_H 27 | #define _TOUCH_DSO_COMMON_H 28 | 29 | #if defined(__AVR__) 30 | // Data buffer size (must be small enough to leave appr. 7 % (144 Byte) for stack 31 | #define DATABUFFER_SIZE (3*DISPLAY_WIDTH) //960 32 | #else 33 | #if defined(STM32F303xC) 34 | #define DATABUFFER_SIZE_FACTOR 9 35 | #else 36 | #define DATABUFFER_SIZE_FACTOR 7 37 | #endif 38 | #endif 39 | 40 | #define DISPLAY_VALUE_FOR_ZERO (DISPLAY_HEIGHT - 1) 41 | //#define DISPLAY_VALUE_FOR_ZERO (DISPLAY_HEIGHT - 2) // Zero line is not exactly at bottom of display to improve readability 42 | 43 | /* 44 | * CHANNEL 45 | */ 46 | #define MAX_ADC_EXTERNAL_CHANNEL 4 // 5 channels 0-4, since ADC5/PC5 is used for AC/DC switching 47 | #if defined(__AVR__) 48 | #define ADC_CHANNEL_COUNT ((MAX_ADC_EXTERNAL_CHANNEL + 1) + 2) // The number of external and internal ADC channels 49 | #else 50 | #define START_ADC_CHANNEL_INDEX 0 // see also ChannelSelectButtonString 51 | #if defined(STM32F303xC) 52 | #define ADC_CHANNEL_COUNT 6 // The number of ADC channels 53 | #else 54 | #define ADC_CHANNEL_COUNT 6 // The number of ADC channels 55 | #endif 56 | extern uint8_t const ADCInputMUXChannels[ADC_CHANNEL_COUNT]; 57 | #endif 58 | #define NUMBER_OF_CHANNELS_WITH_FIXED_ATTENUATOR 3 // Channel0 = /1, Ch1= /10, Ch2= /100 59 | 60 | extern const char *const ADCInputMUXChannelStrings[]; 61 | extern const char *const ChannelDivByButtonStrings[]; 62 | 63 | /* 64 | * Trigger values 65 | */ 66 | #define TRIGGER_MODE_AUTOMATIC 0 67 | #define TRIGGER_MODE_MANUAL_TIMEOUT 1 68 | #define TRIGGER_MODE_MANUAL 2 // without timeout 69 | #define TRIGGER_MODE_FREE 3 // waits at least 23 ms (255 samples) for trigger 70 | #define TRIGGER_MODE_EXTERN 4 71 | #define TRIGGER_HYSTERESIS_FOR_MODE_MANUAL 4 72 | 73 | #if defined(__AVR__) 74 | /***************************** 75 | * Timebase stuff 76 | *****************************/ 77 | #define TIMEBASE_INDEX_START_VALUE 7 // 2 ms - shows 50 Hz 78 | 79 | // ADC HW prescaler values 80 | #define ADC_PRESCALE4 2 // is noisy 81 | #define ADC_PRESCALE8 3 // is reasonable 82 | #define ADC_PRESCALE16 4 83 | #define ADC_PRESCALE32 5 84 | #define ADC_PRESCALE64 6 85 | #define ADC_PRESCALE128 7 86 | 87 | #define ADC_PRESCALE_MAX_VALUE ADC_PRESCALE128 88 | #define ADC_PRESCALE_START_VALUE ADC_PRESCALE128 89 | #define ADC_PRESCALE_FOR_TRIGGER_SEARCH ADC_PRESCALE8 90 | 91 | #define TIMER0_PRESCALE0 1 92 | #define TIMER0_PRESCALE8 2 93 | #define TIMER0_PRESCALE64 3 94 | #define TIMER0_PRESCALE256 4 95 | #define TIMER0_PRESCALE1024 5 96 | 97 | /* 98 | * Since prescaler PRESCALE4 gives bad quality, use PRESCALE8 for 201 us range and display each value twice. 99 | * PRESCALE8 has pretty good quality, but PRESCALE16 (496 us/div) performs slightly better. 100 | * 101 | * Different Acquisition modes depending on Timebase: 102 | * Mode ultrafast 10-50 us - ADC free running with PRESCALE4 - one loop for read and store 10 bit => needs double buffer space - interrupts blocked for duration of loop 103 | * Mode fast 101-201 us - ADC free running with PRESCALE8 - one loop for read but pre process 10 -> 8 Bit and store - interrupts blocked for duration of loop 104 | * mode ISR >= 496 us - ADC generates Interrupts. Waits free running with PRESCALE16 for trigger then switch to timer0 based timebase 105 | */ 106 | 107 | #define HORIZONTAL_GRID_COUNT 6 108 | /** 109 | * Formula for Grid Height is: 110 | * 5 volt Reference, 10 bit Resolution => 1023/5 = 204.6 Pixel per volt 111 | * 1 volt per Grid -> 204,6 pixel. With scale (shift) 2 => 51.15 pixel. 112 | * 0.5 volt -> 102.3 pixel with scale (shift) 1 => 51.15 pixel 113 | * 0.2 volt -> 40.96 pixel 114 | * 1.1 volt Reference 1023/1.1 = 930 Pixel per volt 115 | * 0.2 volt -> 186 pixel with scale (shift) 2 => 46.5 pixel 116 | * 0.1 volt -> 93 pixel with scale (shift) 1 => 46.5 pixel 117 | * 0.05 volt -> 46.5 pixel 118 | */ 119 | 120 | #define HORIZONTAL_GRID_HEIGHT_1_1V_SHIFT8 11904 // 46.5*256 for 0.05 to 0.2 volt/div for 6 divs per screen 121 | #define HORIZONTAL_GRID_HEIGHT_2V_SHIFT8 6554 // 25.6*256 for 0.05 to 0.2 volt/div for 10 divs per screen 122 | #define ADC_CYCLES_PER_CONVERSION 13 123 | #define TIMING_GRID_WIDTH 31 // with 31 instead of 32 the values fit better to 1-2-5 timebase scale 124 | #define TIMEBASE_NUMBER_OF_ENTRIES 15 // the number of different timebases provided 125 | #define TIMEBASE_NUMBER_OF_FAST_PRESCALE 8 // the number of prescale values not equal slowest possible prescale (PRESCALE128) 126 | #define TIMEBASE_NUMBER_OF_FAST_MODES 5 // first 5 timebase (10 - 201) are fast free running modes with polling instead of ISR using PRESCALE4 + PRESCALE8 127 | #define TIMEBASE_INDEX_ULTRAFAST_MODES 2 // first 3 timebase (10 - 50) using PRESCALE4 is ultra fast polling without preprocessing and therefore needs double buffer size 128 | #define TIMEBASE_NUMBER_OF_XSCALE_CORRECTION 4 // number of timebase which are simulated by display XSale factor. Since PRESCALE4 gives bad quality, use PRESCALE8 and XScale for 201 us range 129 | #define TIMEBASE_INDEX_MILLIS 6 // min index to switch to ms instead of us display 130 | #define TIMEBASE_INDEX_DRAW_WHILE_ACQUIRE 11 // min index where chart is drawn while buffer is filled (11 => 50 ms) 131 | #else 132 | /* 133 | * TIMEBASE 134 | */ 135 | #define TIMEBASE_INDEX_START_VALUE 12 136 | 137 | #define CHANGE_REQUESTED_TIMEBASE_FLAG 0x01 138 | 139 | #define TIMEBASE_NUMBER_OF_ENTRIES 21 // the number of different timebase provided - 1. entry is not uses until interleaved acquisition is implemented 140 | #define TIMEBASE_NUMBER_OF_EXCACT_ENTRIES 8 // the number of exact float value for timebase because of granularity of clock division 141 | #define TIMEBASE_FAST_MODES 7 // first modes are fast DMA modes 142 | #define TIMEBASE_INDEX_DRAW_WHILE_ACQUIRE 17 // min index where chart is drawn while buffer is filled 143 | #define TIMEBASE_INDEX_CAN_USE_OVERSAMPLING 11 // min index where Min/Max oversampling is enabled 144 | #if defined(STM32F303xC) 145 | #define TIMEBASE_NUMBER_START 1 // first reasonable Timebase to display - 0 if interleaving is realized 146 | #define TIMEBASE_NUMBER_OF_XSCALE_CORRECTION 5 // number of timebase which are simulated by display XSale factor 147 | #else 148 | #define TIMEBASE_NUMBER_START 3 // first reasonable Timebase to display - we have only 0.8 MSamples 149 | #define TIMEBASE_NUMBER_OF_XSCALE_CORRECTION 7 // number of timebase which are simulated by display XSale factor 150 | #endif 151 | #define TIMEBASE_INDEX_MILLIS 11 // min index to switch to ms instead of ns display 152 | #define TIMEBASE_INDEX_MICROS 2 // min index to switch to us instead of ns display 153 | #endif 154 | 155 | extern const float TimebaseExactDivValuesMicros[] PROGMEM; 156 | #define HORIZONTAL_LINE_LABELS_CAPION_X (DISPLAY_WIDTH - TEXT_SIZE_11_WIDTH * 4) 157 | /* 158 | * OFFSET 159 | */ 160 | #define OFFSET_MODE_0_VOLT 0 161 | #define OFFSET_MODE_AUTOMATIC 1 162 | #define OFFSET_MODE_MANUAL 2 // not implemented for AVR Implies range mode manual. 163 | 164 | /* 165 | * COLORS 166 | */ 167 | #define COLOR_BACKGROUND_DSO COLOR16_WHITE 168 | #define COLOR_INFO_BACKGROUND COLOR16(0xC8,0xC8,0x00) // background for info lines or elements 169 | 170 | // Data colors 171 | #define COLOR_DATA_RUN COLOR16_BLUE 172 | #define COLOR_DATA_HOLD COLOR16_RED 173 | // to see old chart values 174 | #define COLOR_DATA_HISTORY COLOR16(0x20,0xFF,0x20) 175 | 176 | // Button colors 177 | #define COLOR_GUI_CONTROL COLOR16_RED 178 | #define COLOR_GUI_TRIGGER COLOR16_BLUE 179 | #define COLOR_GUI_SOURCE_TIMEBASE COLOR16(0x00,0xE0,0x00) 180 | 181 | // Line colors 182 | #define COLOR_VOLTAGE_PICKER COLOR16_YELLOW 183 | #define COLOR_VOLTAGE_PICKER_SLIDER COLOR16(0xFF,0XFF,0xD0) // Light Yellow 184 | #define COLOR_TRIGGER_LINE COLOR16_PURPLE 185 | #define COLOR_TRIGGER_SLIDER COLOR16(0xFF,0XE8,0xFF) // light Magenta 186 | #define COLOR_HOR_REF_LINE_LABEL COLOR16_BLUE 187 | #define COLOR_MAX_MIN_LINE COLOR16_GREEN 188 | #define COLOR_GRID_LINES COLOR16(0x00,0x98,0x00) 189 | 190 | // Label colors 191 | #define COLOR_HOR_GRID_LINE_LABEL COLOR16_BLUE 192 | #define COLOR_HOR_GRID_LINE_LABEL_NEGATIVE COLOR16_RED 193 | 194 | /* 195 | * GUI LAYOUT, POSITIONS + SIZES 196 | */ 197 | #define INFO_UPPER_MARGIN (1 + TEXT_SIZE_11_ASCEND) 198 | #define INFO_LEFT_MARGIN 0 199 | 200 | #if defined(__AVR__) 201 | #define FONT_SIZE_INFO_SHORT TEXT_SIZE_18 // for 1 line info 202 | #define FONT_SIZE_INFO_LONG TEXT_SIZE_11 // for 2 lines info 203 | #define FONT_SIZE_INFO_SHORT_ASC TEXT_SIZE_18_ASCEND 204 | #define FONT_SIZE_INFO_LONG_ASC TEXT_SIZE_11_ASCEND 205 | #define FONT_SIZE_INFO_LONG_WIDTH TEXT_SIZE_11_WIDTH 206 | 207 | #define SLIDER_BAR_WIDTH 24 208 | #define SLIDER_VPICKER_POS_X 0 // Position of slider 209 | #define SLIDER_VPICKER_INFO_X (SLIDER_VPICKER_POS_X + SLIDER_BAR_WIDTH) 210 | #define SLIDER_VPICKER_INFO_SHORT_Y (FONT_SIZE_INFO_SHORT + FONT_SIZE_INFO_SHORT_ASC) 211 | #define SLIDER_VPICKER_INFO_LONG_Y (2 * FONT_SIZE_INFO_LONG + FONT_SIZE_INFO_SHORT_ASC) // since font size is always 18 212 | 213 | #define SLIDER_TLEVEL_POS_X (14 * FONT_SIZE_INFO_LONG_WIDTH) // Position of slider 214 | #define TRIGGER_LEVEL_INFO_SHORT_X (SLIDER_TLEVEL_POS_X + SLIDER_BAR_WIDTH) 215 | #define TRIGGER_LEVEL_INFO_LONG_X (INFO_LEFT_MARGIN + (36 * FONT_SIZE_INFO_LONG_WIDTH)) 216 | #define TRIGGER_LEVEL_INFO_SHORT_Y (FONT_SIZE_INFO_SHORT + FONT_SIZE_INFO_SHORT_ASC) 217 | #define TRIGGER_LEVEL_INFO_LONG_Y FONT_SIZE_INFO_LONG_ASC 218 | 219 | #define SETTINGS_PAGE_ROW_INCREMENT BUTTON_HEIGHT_5_256_LINE_2 220 | #define SETTINGS_PAGE_BUTTON_HEIGHT BUTTON_HEIGHT_5_256 221 | #define START_PAGE_ROW_INCREMENT BUTTON_HEIGHT_4_256_LINE_2 222 | #define START_PAGE_BUTTON_HEIGHT BUTTON_HEIGHT_4_256 223 | 224 | #define SINGLESHOT_PPRINT_VALUE_X (DISPLAY_WIDTH - TEXT_SIZE_11_WIDTH) 225 | #define SETTINGS_PAGE_INFO_Y (BUTTON_HEIGHT_5_256_LINE_5 - (TEXT_SIZE_11_DECEND + 1)) 226 | #else 227 | #if defined(SUPPORT_LOCAL_DISPLAY) 228 | #define FONT_SIZE_INFO_SHORT TEXT_SIZE_11 // for 1 line info 229 | #define FONT_SIZE_INFO_LONG TEXT_SIZE_11 // for 3 lines info 230 | #define FONT_SIZE_INFO_SHORT_ASC TEXT_SIZE_11_ASCEND // for 3 lines info 231 | #define FONT_SIZE_INFO_LONG_ASC TEXT_SIZE_11_ASCEND // for 3 lines info 232 | #define FONT_SIZE_INFO_LONG_WIDTH TEXT_SIZE_11_WIDTH // for 3 lines info 233 | #else 234 | #define FONT_SIZE_INFO_SHORT TEXT_SIZE_16 // for 1 line info 235 | #define FONT_SIZE_INFO_LONG TEXT_SIZE_14 // for 3 lines info 236 | #define FONT_SIZE_INFO_SHORT_ASC TEXT_SIZE_16_ASCEND // for 3 lines info 237 | #define FONT_SIZE_INFO_LONG_ASC TEXT_SIZE_14_ASCEND // for 3 lines info 238 | #define FONT_SIZE_INFO_LONG_WIDTH TEXT_SIZE_14_WIDTH // for 3 lines info 239 | #endif 240 | 241 | #define SLIDER_BAR_WIDTH 24 242 | #define SLIDER_VPICKER_POS_X 0 // Position of slider 243 | #define SLIDER_VPICKER_INFO_X (SLIDER_VPICKER_POS_X + SLIDER_BAR_WIDTH) 244 | #define SLIDER_VPICKER_INFO_SHORT_Y (FONT_SIZE_INFO_SHORT + FONT_SIZE_INFO_SHORT_ASC) 245 | #define SLIDER_VPICKER_INFO_LONG_Y (3 * FONT_SIZE_INFO_LONG + FONT_SIZE_INFO_SHORT_ASC) // since font size is always 18 246 | 247 | #define SLIDER_TLEVEL_POS_X (14 * FONT_SIZE_INFO_LONG_WIDTH) // Position of slider 248 | #define TRIGGER_LEVEL_INFO_SHORT_X (SLIDER_TLEVEL_POS_X + SLIDER_BAR_WIDTH) 249 | #if defined(SUPPORT_LOCAL_DISPLAY) 250 | #define TRIGGER_LEVEL_INFO_LONG_X (11 * FONT_SIZE_INFO_LONG_WIDTH) 251 | #else 252 | #define TRIGGER_LEVEL_INFO_LONG_X (11 * FONT_SIZE_INFO_LONG_WIDTH +1) // +1 since we have a special character in the string before 253 | #endif 254 | #define TRIGGER_LEVEL_INFO_SHORT_Y (FONT_SIZE_INFO_SHORT + FONT_SIZE_INFO_SHORT_ASC) 255 | #define TRIGGER_LEVEL_INFO_LONG_Y (2 * FONT_SIZE_INFO_LONG + FONT_SIZE_INFO_LONG_ASC) 256 | 257 | #define TRIGGER_HIGH_DISPLAY_OFFSET 7 // for trigger state line 258 | #define SETTINGS_PAGE_ROW_INCREMENT BUTTON_HEIGHT_5_LINE_2 259 | #define SETTINGS_PAGE_BUTTON_HEIGHT BUTTON_HEIGHT_5 260 | #define START_PAGE_ROW_INCREMENT BUTTON_HEIGHT_4_LINE_2 261 | #define START_PAGE_BUTTON_HEIGHT BUTTON_HEIGHT_4 262 | #endif 263 | 264 | extern uint8_t sLastPickerValue; 265 | 266 | #if defined(__AVR__) 267 | extern BDButton TouchButtonADCReference; 268 | #else 269 | extern BDButton TouchButtonFFT; 270 | extern BDButton TouchButtonShowPretriggerValuesOnOff; 271 | extern BDButton TouchButtonDSOMoreSettings; 272 | extern BDButton TouchButtonCalibrateVoltage; 273 | extern BDButton TouchButtonMinMaxMode; 274 | extern BDButton TouchButtonDrawModeTriggerLine; 275 | #endif 276 | #if defined(SUPPORT_LOCAL_DISPLAY) 277 | extern BDButton TouchButtonDrawModeLinePixel; 278 | extern BDButton TouchButtonADS7846TestOnOff; 279 | extern BDSlider TouchSliderBacklight; 280 | #endif // SUPPORT_LOCAL_DISPLAY 281 | 282 | extern BDButton TouchButtonSingleshot; 283 | extern BDButton TouchButtonStartStopDSOMeasurement; 284 | 285 | extern BDButton TouchButtonSlope; 286 | extern BDButton TouchButtonTriggerMode; 287 | extern BDButton TouchButtonTriggerDelay; 288 | extern BDButton TouchButtonChartHistoryOnOff; 289 | extern BDButton TouchButtonSlope; 290 | extern BDButton TouchButtonAcDc; 291 | extern BDButton TouchButtonChannels[]; 292 | extern BDButton TouchButtonChannelSelect; 293 | extern BDButton TouchButtonChannelMode; 294 | extern BDButton TouchButtonAutoOffsetMode; 295 | extern const char AutoOffsetButtonStringMan[]; 296 | extern const char AutoOffsetButtonStringAuto[]; 297 | extern const char AutoOffsetButtonString0[]; 298 | extern BDButton TouchButtonAutoRangeOnOff; 299 | extern BDButton TouchButtonSettingsPage; 300 | extern BDButton TouchButtonFrequencyPage; 301 | 302 | extern char SlopeButtonString[]; 303 | // the index of the slope indicator in char array 304 | #define SLOPE_STRING_INDEX 6 305 | 306 | extern BDButton TouchButtonTriggerMode; 307 | extern const char TriggerModeButtonStringAuto[] PROGMEM; 308 | extern const char TriggerModeButtonStringManualTimeout[] PROGMEM; 309 | extern const char TriggerModeButtonStringManual[] PROGMEM; 310 | extern const char TriggerModeButtonStringFree[] PROGMEM; 311 | extern const char TriggerModeButtonStringExtern[] PROGMEM; 312 | 313 | extern BDButton TouchButtonAutoRangeOnOff; 314 | extern const char AutoRangeButtonStringAuto[] PROGMEM; 315 | extern const char AutoRangeButtonStringManual[] PROGMEM; 316 | 317 | extern BDSlider TouchSliderTriggerLevel; 318 | extern BDSlider TouchSliderVoltagePicker; 319 | 320 | // Measurement section 321 | void startAcquisition(void); 322 | void prepareForStart(void); 323 | void setChannel(uint8_t aChannel); 324 | void clearDataBuffer(); 325 | 326 | // Stack info 327 | void initStackFreeMeasurement(void); 328 | uint16_t getStackUnusedBytes(void); 329 | void printFreeStack(void); 330 | 331 | // Data analysis section 332 | void computeMinMax(void); 333 | void computePeriodFrequency(void); 334 | void setTriggerLevelAndHysteresis(int aRawTriggerValue, int aRawTriggerHysteresis); 335 | 336 | // Logic section 337 | void resetOffset(void); 338 | void setOffsetAutomatic(bool aNewState); 339 | void setACMode(bool aNewACMode); 340 | int changeOffsetGridCount(int aValue); 341 | 342 | #if defined(__AVR__) 343 | uint8_t changeRange(int8_t aChangeAmount); 344 | uint8_t changeTimeBaseValue(int8_t aChangeValue); 345 | #else 346 | int changeDisplayRangeAndAdjustOffsetGridCount(int aValue); 347 | int changeTimeBaseValue(int aChangeValue); 348 | bool changeXScale(int aValue); 349 | #endif 350 | 351 | // Output and draw section 352 | void initDSOGUI(void); 353 | 354 | void redrawDisplay(void); 355 | void drawStartPage(void); 356 | void drawDSOSettingsPage(void); 357 | void drawDSOMoreSettingsPage(void); 358 | 359 | void drawGridLinesWithHorizLabelsAndTriggerLine(); 360 | void clearHorizontalLineAndRestoreGrid(int aYposition); 361 | void drawTriggerLine(void); 362 | void drawMinMaxLines(void); 363 | void clearTriggerLine(uint8_t aTriggerLevelDisplayValue); 364 | void drawRunningOnlyPartOfGui(void); 365 | void activateChartGui(void); 366 | #if defined(__AVR__) 367 | bool scrollChart(int aValue); 368 | uint8_t getDisplayFromRawInputValue(uint16_t aRawValue); 369 | void drawDataBuffer(uint8_t *aByteBuffer, uint16_t aColor, uint16_t aClearBeforeColor); 370 | #else 371 | int scrollChart(int aValue); 372 | int getDisplayFromRawInputValue(int aAdcValue); 373 | void drawDataBuffer(uint16_t *aDataBufferPointer, int aLength, color16_t aColor, color16_t aClearBeforeColor, int aDrawMode, 374 | bool aDrawAlsoMin); 375 | void startSystemInfoPage(void); 376 | #endif 377 | 378 | // Text output section 379 | void printfTriggerDelay(char *aDataBufferPtr, uint16_t aTriggerDelayMillisOrMicros); 380 | void printVCCAndTemperature(void); 381 | void clearInfo(uint8_t aOldMode); 382 | void printInfo(bool aRecomputeValues = true); 383 | void printTriggerInfo(void); 384 | 385 | // GUI event handler section 386 | void doSwitchInfoModeOnTouchUp(struct TouchEvent *const aTouchPosition); 387 | void doLongTouchDownDSO(struct TouchEvent *const aTouchPosition); 388 | void doSwipeEndDSO(struct Swipe *const aSwipeInfo); 389 | void doSetTriggerDelay(float aValue); 390 | 391 | // Button handler section 392 | #if defined(__AVR__) 393 | void doADCReference(BDButton *aTheTouchedButton, int16_t aValue); 394 | #else 395 | void doShowPretriggerValuesOnOff(BDButton * aTheTouchedButton, int16_t aValue); 396 | void doShowFFT(BDButton * aTheTouchedButton, int16_t aValue); 397 | void doMinMaxMode(BDButton * aTheTouchedButton, int16_t aValue); 398 | void doShowMoreSettingsPage(BDButton * aTheTouchedButton, int16_t aValue); 399 | void doShowSystemInfoPage(BDButton * aTheTouchedButton, int16_t aValue); 400 | void doVoltageCalibration(BDButton * aTheTouchedButton, int16_t aValue); 401 | void doDrawModeTriggerLine(BDButton * aTheTouchedButton, int16_t aValue); 402 | #endif 403 | void doStartStopDSO(BDButton *aTheTouchedButton, int16_t aValue); 404 | void doDefaultBackButton(BDButton *aTheTouchedButton, int16_t aValue); 405 | void doShowFrequencyPage(BDButton *aTheTouchedButton, int16_t aValue); 406 | void doShowSettingsPage(BDButton *aTheTouchedButton, int16_t aValue); 407 | void doTriggerSlope(BDButton *aTheTouchedButton, int16_t aValue); 408 | void doStartSingleshot(BDButton *aTheTouchedButton, int16_t aValue); 409 | void doTriggerMode(BDButton *aTheTouchedButton, int16_t aValue); 410 | void doRangeMode(BDButton *aTheTouchedButton, int16_t aValue); 411 | void doChartHistory(BDButton *aTheTouchedButton, int16_t aValue); 412 | void doPromptForTriggerDelay(BDButton *aTheTouchedButton, int16_t aValue); 413 | void doChannelSelect(BDButton *aTheTouchedButton, int16_t aValue); 414 | void doOffsetMode(BDButton *aTheTouchedButton, int16_t aValue); 415 | void doAcDcMode(BDButton *aTheTouchedButton, int16_t aValue); 416 | 417 | #if defined(SUPPORT_LOCAL_DISPLAY) 418 | void readADS7846Channels(void); 419 | void doADS7846TestOnOff(BDButton * aTheTouchedButton, int16_t aValue); 420 | void doDrawMode(BDButton * aTheTouchedButton, int16_t aValue); 421 | #endif // SUPPORT_LOCAL_DISPLAY 422 | 423 | // Slider handler section 424 | void doTriggerLevel(BDSlider *aTheTouchedSlider, uint16_t aValue); 425 | void doVoltagePicker(BDSlider *aTheTouchedSlider, uint16_t aValue); 426 | 427 | // Button caption section 428 | #if defined(__AVR__) 429 | #else 430 | void setMinMaxModeButtonCaption(void); 431 | #endif 432 | 433 | void setSlopeButtonCaption(void); 434 | void setTriggerModeButtonCaption(void); 435 | void setAutoRangeModeAndButtonCaption(bool aNewAutoRangeMode); 436 | void setChannelButtonsCaption(void); 437 | void setReferenceButtonCaption(void); 438 | void setACModeButtonCaption(void); 439 | void setTriggerDelayCaption(void); 440 | void setAutoOffsetButtonCaption(void); 441 | 442 | uint32_t getMicrosFromHorizontalDisplayValue(uint16_t aDisplayValueHorizontal, uint8_t aNumberOfPeriods); 443 | 444 | #if defined(__AVR__) 445 | #else 446 | #endif 447 | #if !defined(__AVR__) 448 | #endif 449 | 450 | #endif // _TOUCH_DSO_COMMON_H 451 | -------------------------------------------------------------------------------- /Waveforms.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Waveforms.cpp 3 | * 4 | * Code uses 16 bit AVR Timer1 and generates a 62.5 kHz PWM signal with 8 Bit resolution. 5 | * After every PWM cycle an interrupt handler sets a new PWM value, resulting in a sine, triangle or sawtooth output. 6 | * New value is taken by a rolling index from a table for sine, or directly computed from that index for triangle and sawtooth waveforms. 7 | * 8 | * Maximum values: Minimum values: 9 | * SINE: clip to minimum 8 samples per period => 128 us / 7812.5 Hz 7,421 mHz 10 | * SAWTOOTH: clip to minimum 16 samples per period => 256 us / 3906.25 Hz 3.725 mHz 11 | * TRIANGLE: clip to minimum 32 samples per period => 512 us / 1953.125 Hz 1.866 mHz 12 | * By using a "floating point" index increment, every frequency lower than these maximum values can be generated. 13 | * 14 | * In CTC Mode Timer1 generates square wave from 0.119 Hz up to 8 MHz (full range of Timer1). 15 | * Timer1 is used by Arduino for Servo Library. For 8 bit resolution it may also be possible to use Timer2 which is used for Arduino tone(). 16 | * 17 | * Output is at PIN 10 18 | * 19 | * PWM RC-Filter suggestions 20 | * Simple: 2.2 kOhm and 100 nF 21 | * 2nd order (good for sine and triangle): 1 kOhm and 100 nF -> 4.7 kOhm and 22 nF 22 | * 2nd order (better for sawtooth): 1 kOhm and 22 nF -> 4.7 kOhm and 4.7 nF 23 | * 24 | * Copyright (C) 2017-2023 Armin Joachimsmeyer 25 | * Email: armin.joachimsmeyer@gmail.com 26 | * 27 | * This file is part of Arduino-Simple-DSO https://github.com/ArminJo/Arduino-Simple-DSO. 28 | * 29 | * Arduino-Simple-DSO is free software: you can redistribute it and/or modify 30 | * it under the terms of the GNU General Public License as published by 31 | * the Free Software Foundation, either version 3 of the License, or 32 | * (at your option) any later version. 33 | * 34 | * This program is distributed in the hope that it will be useful, 35 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 36 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 37 | * See the GNU General Public License for more details. 38 | * 39 | * You should have received a copy of the GNU General Public License 40 | * along with this program. If not, see . 41 | * 42 | */ 43 | 44 | #include 45 | #if defined(__AVR__) && defined(TCCR1A) 46 | 47 | #include "Waveforms.h" 48 | 49 | #define TIMER_PRESCALER_MASK 0x07 50 | 51 | struct FrequencyInfoStruct sFrequencyInfo; 52 | 53 | /* 54 | * Sine table from 0 to 90 degree including 0 AND 90 degree therefore we have an odd number 55 | * Contains values from 128 to 255 (or if inverted: 1 to 128) 56 | */ 57 | #define SIZE_OF_SINE_TABLE_QUARTER 32 58 | const uint8_t sSineTableQuarter128[SIZE_OF_SINE_TABLE_QUARTER + 1] PROGMEM = { 128, 135, 141, 147, 153, 159, 165, 171, 177, 182, 59 | 188, 193, 199, 204, 209, 213, 218, 222, 226, 230, 234, 237, 240, 243, 245, 248, 250, 251, 253, 254, 254, 255, 255 }; 60 | // Base period, for which exact one next value from table/computation is taken at every interrupt 61 | // 8 Bit PWM resolution gives 488.28125 Hz sine base frequency: 1/16 us * 256 * 128 = 16*128 = 2048 us = 488.28125 Hz 62 | #define BASE_PERIOD_MICROS_FOR_SINE_TABLE 2048UL // ((1/F_CPU) * PWM_RESOLUTION) * (SIZE_OF_SINE_TABLE_QUARTER * 4) 63 | #define BASE_PERIOD_MICROS_FOR_TRIANGLE 8176UL // (1/F_CPU) * PWM_RESOLUTION * (256+255) Values -> 122.3092 Hz 64 | #define BASE_PERIOD_MICROS_FOR_SAWTOOTH 4096UL // (1/F_CPU) * PWM_RESOLUTION * 256 Values -> 244.140625 Hz 65 | 66 | const char FrequencyRangeChars[4] = { 'm', ' ', 'k', 'M' }; 67 | 68 | /* 69 | * 8-bit PWM Output at PIN 10 70 | * Overflow interrupt is generated every cycle -> this is used to generate the waveforms 71 | */ 72 | void initTimer1For8BitPWM() { 73 | DDRB |= _BV(DDB2); // set pin OC1B = PortB2 -> PIN 10 to output direction 74 | 75 | TCCR1A = _BV(COM1B1) | _BV(WGM10); // Clear OC1B on Compare Match. With WGM12 Waveform Generation Mode 5 - Fast PWM 8-bit, 76 | // TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(WGM11); // With WGM12 Waveform Generation Mode 6 - Fast PWM, 9-bit 77 | // TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(WGM11) | _BV(WGM10); // With WGM12 Waveform Generation Mode 7 - Fast PWM, 10-bit 78 | TCCR1B = _BV(WGM12); // set OC1A/OC1B at BOTTOM (non-inverting mode) - no clock (prescaler) -> timer disabled now 79 | 80 | OCR1A = UINT8_MAX; // output DC - HIGH 81 | OCR1B = UINT8_MAX; // output DC - HIGH 82 | TCNT1 = 0; // init counter 83 | TIMSK1 = _BV(TOIE1); // Enable Overflow Interrupt 84 | } 85 | 86 | /* 87 | * CTC output at PIN 10 88 | */ 89 | void initTimer1ForCTC(void) { 90 | DDRB |= _BV(DDB2); // set pin OC1B = PortB2 -> PIN 10 to output direction 91 | 92 | TIMSK1 = 0; // no interrupts 93 | 94 | TCCR1A = _BV(COM1B0); // Toggle OC1B on compare match / CTC mode 95 | TCCR1B = _BV(WGM12); // CTC with OCR1A - no clock->timer disabled 96 | OCR1A = 125 - 1; // set compare match register for 1 kHz 97 | TCNT1 = 0; // init counter 98 | } 99 | 100 | void setWaveformMode(uint8_t aNewMode) { 101 | aNewMode &= WAVEFORM_MASK; 102 | sFrequencyInfo.Waveform = aNewMode; 103 | if (aNewMode == WAVEFORM_SQUARE) { 104 | initTimer1ForCTC(); 105 | } else { 106 | initTimer1For8BitPWM(); 107 | } 108 | // start timer if not already done 109 | startWaveform(); 110 | // recompute values 111 | setWaveformFrequencyFromNormalizedValues(); 112 | } 113 | 114 | void cycleWaveformMode() { 115 | setWaveformMode(sFrequencyInfo.Waveform + 1); 116 | } 117 | 118 | const __FlashStringHelper* cycleWaveformModePGMString() { 119 | cycleWaveformMode(); 120 | return getWaveformModePGMString(); 121 | } 122 | 123 | const __FlashStringHelper* getWaveformModePGMString() { 124 | const __FlashStringHelper *tResultString; 125 | tResultString = F("Square"); 126 | if (sFrequencyInfo.Waveform == WAVEFORM_SINE) { 127 | tResultString = F("Sine"); 128 | } else if (sFrequencyInfo.Waveform == WAVEFORM_TRIANGLE) { 129 | tResultString = F("Triangle"); 130 | } else if (sFrequencyInfo.Waveform == WAVEFORM_SAWTOOTH) { 131 | tResultString = F("Sawtooth"); 132 | } 133 | return tResultString; 134 | } 135 | 136 | float getPeriodMicros() { 137 | // output period use float, since we have 1/8 us for square wave 138 | float tPeriodMicros; 139 | if (sFrequencyInfo.Waveform == WAVEFORM_SQUARE) { 140 | // use better resolution here 141 | tPeriodMicros = sFrequencyInfo.ControlValue.DividerInt; 142 | tPeriodMicros /= 8; 143 | } else { 144 | tPeriodMicros = sFrequencyInfo.PeriodMicros; 145 | } 146 | return tPeriodMicros; 147 | } 148 | 149 | void setNormalizedFrequencyFactorFromRangeIndex(uint8_t aFrequencyRangeIndex) { 150 | sFrequencyInfo.FrequencyRangeIndex = aFrequencyRangeIndex; 151 | uint32_t tFactor = 1; 152 | while (aFrequencyRangeIndex >= 1) { 153 | tFactor *= 1000; 154 | aFrequencyRangeIndex--; 155 | } 156 | sFrequencyInfo.FrequencyNormalizedFactorTimes1000 = tFactor; 157 | } 158 | 159 | /* 160 | * Convert the effective frequency for display purposes to 161 | * a normalized value between 1 and 100 and a factor, so that 162 | * aEffectiveFrequency = FrequencyNormalizedTo_1_to_1000 * (FrequencyNormalizedFactorTimes1000 / 1000) 163 | */ 164 | void setNormalizedFrequencyAndFactor(float aFrequency) { 165 | uint8_t tFrequencyRangeIndex = 1; 166 | 167 | /* 168 | * Normalize Frequency to 1 - 1000 and compute FrequencyRangeIndex 169 | */ 170 | if (aFrequency < 1) { 171 | tFrequencyRangeIndex = 0; // mHz 172 | aFrequency *= 1000; 173 | } else { 174 | while (aFrequency >= 1000) { 175 | aFrequency /= 1000; 176 | tFrequencyRangeIndex++; 177 | } 178 | } 179 | 180 | /* 181 | * One problem is, to decide to set the value of e.g. 1 Hz as 1000 mHz or 1 Hz. 182 | * So we just try to keep the existing range. 183 | */ 184 | // Check if tFrequencyRangeIndex - 1 fits better. 1000.1 to avoid switching to next range because of resolution issues 185 | if (aFrequency < 1.00001 && sFrequencyInfo.FrequencyRangeIndex == (tFrequencyRangeIndex - 1)) { 186 | aFrequency *= 1000; 187 | tFrequencyRangeIndex--; 188 | } 189 | 190 | setNormalizedFrequencyFactorFromRangeIndex(tFrequencyRangeIndex); 191 | sFrequencyInfo.FrequencyNormalizedTo_1_to_1000 = aFrequency; 192 | } 193 | 194 | bool setWaveformFrequencyFromNormalizedValues() { 195 | return setWaveformFrequency( 196 | (sFrequencyInfo.FrequencyNormalizedTo_1_to_1000 * sFrequencyInfo.FrequencyNormalizedFactorTimes1000) / 1000); 197 | } 198 | 199 | /* 200 | * SINE: clip to minimum 8 samples per period => 128 us / 7812.5 Hz 201 | * SAWTOOTH: clip to minimum 16 samples per period => 256 us / 3906.25 Hz 202 | * Triangle: clip to minimum 32 samples per period => 512 us / 1953.125 Hz 203 | * return true if clipping occurs 204 | */ 205 | bool setWaveformFrequency(float aFrequency) { 206 | bool hasError = false; 207 | if (sFrequencyInfo.Waveform == WAVEFORM_SQUARE) { 208 | // need initialized sFrequencyInfo structure 209 | hasError = setSquareWaveFrequency(aFrequency); 210 | } else { 211 | // use shift 16 to increase resolution but avoid truncation 212 | long tBasePeriodShift16 = (BASE_PERIOD_MICROS_FOR_SINE_TABLE << 16); 213 | if (sFrequencyInfo.Waveform == WAVEFORM_TRIANGLE) { 214 | tBasePeriodShift16 = (BASE_PERIOD_MICROS_FOR_TRIANGLE << 16); 215 | } else if (sFrequencyInfo.Waveform == WAVEFORM_SAWTOOTH) { 216 | tBasePeriodShift16 = (BASE_PERIOD_MICROS_FOR_SAWTOOTH << 16); 217 | } 218 | uint32_t tPeriodMicros = 1000000UL / aFrequency; 219 | uint32_t tBaseFrequencyFactorShift16 = tBasePeriodShift16 / tPeriodMicros; 220 | if (tBaseFrequencyFactorShift16 > (16L << 16)) { 221 | // Clip at factor 16 (taking every 16th value) and recompute values 222 | tBaseFrequencyFactorShift16 = (16L << 16); 223 | tPeriodMicros = (tBasePeriodShift16 >> 16) / 16; 224 | hasError = true; 225 | } else if (tBaseFrequencyFactorShift16 < 1) { 226 | tBaseFrequencyFactorShift16 = 1; 227 | tPeriodMicros = tBasePeriodShift16; 228 | hasError = true; 229 | } 230 | // recompute values 231 | sFrequencyInfo.Frequency = 1000000.0 / tPeriodMicros; 232 | sFrequencyInfo.PeriodMicros = tPeriodMicros; 233 | sFrequencyInfo.ControlValue.BaseFrequencyFactorShift16 = tBaseFrequencyFactorShift16; 234 | 235 | sFrequencyInfo.PrescalerRegisterValueBackup = 1; 236 | if (sFrequencyInfo.isOutputEnabled) { 237 | // start Timer1 for PWM generation 238 | TCCR1B &= ~TIMER_PRESCALER_MASK; 239 | TCCR1B |= _BV(CS10); // set prescaler to 1 -> gives 16 us / 62.5 kHz PWM 240 | } 241 | } 242 | setNormalizedFrequencyAndFactor(sFrequencyInfo.Frequency); 243 | return hasError; 244 | } 245 | 246 | bool setSquareWaveFrequency(float aFrequency) { 247 | bool hasError = false; 248 | float tFrequency = aFrequency; 249 | /* 250 | * Timer runs in toggle mode and has 8 MHz / 0.125 us maximum frequency 251 | * Divider = (F_CPU/2) / sFrequency 252 | * Divider= 1, prescaler= 1 => 8 MHz 253 | * Divider= 16348 * prescaler= 1024 = 0x200000000 => 8,388,608 us => 0.119209 Hz 254 | */ 255 | uint32_t tDividerInteger = (F_CPU / 2) / tFrequency; 256 | if (tDividerInteger == 0) { 257 | if (tFrequency < 1) { 258 | // for very small frequencies (F_CPU / 2) / tFrequency gives NaN which results in 0 259 | tDividerInteger = 0x10000 * 1024; // maximum divider 260 | } else { 261 | // 8 MHz / 0.125 us is maximum 262 | hasError = true; 263 | tDividerInteger = 1; 264 | tFrequency = 8; 265 | } 266 | } 267 | 268 | /* 269 | * Determine prescaler and PrescalerRegisterValue from tDividerInteger value, 270 | * in order to get an tDividerInteger value <= 0x10000 (register value is tDividerInteger-1) 271 | */ 272 | uint16_t tPrescaler = 1; // direct clock 273 | uint8_t tPrescalerRegisterValue = 1; 274 | if (tDividerInteger > 0x10000) { 275 | tDividerInteger >>= 3; 276 | if (tDividerInteger <= 0x10000) { 277 | tPrescaler = 8; 278 | tPrescalerRegisterValue = 2; 279 | } else { 280 | tDividerInteger >>= 3; 281 | if (tDividerInteger <= 0x10000) { 282 | tPrescaler = 64; 283 | tPrescalerRegisterValue = 3; 284 | } else { 285 | tDividerInteger >>= 2; 286 | if (tDividerInteger <= 0x10000) { 287 | tPrescaler = 256; 288 | tPrescalerRegisterValue = 4; 289 | } else { 290 | tDividerInteger >>= 2; 291 | tPrescaler = 1024; 292 | tPrescalerRegisterValue = 5; 293 | if (tDividerInteger > 0x10000) { 294 | // clip to 16 bit value 295 | tDividerInteger = 0x10000; 296 | } 297 | } 298 | } 299 | } 300 | } 301 | sFrequencyInfo.PrescalerRegisterValueBackup = tPrescalerRegisterValue; 302 | if (sFrequencyInfo.isOutputEnabled) { 303 | // set values to timer register 304 | TCCR1B &= ~TIMER_PRESCALER_MASK; 305 | TCCR1B |= tPrescalerRegisterValue; 306 | } 307 | OCR1A = tDividerInteger - 1; // set compare match register 308 | 309 | /* 310 | * recompute exact period and frequency for eventually changed 16 bit period 311 | * Frequency = (F_CPU/2) / (DividerInt * Prescaler) 312 | */ 313 | tDividerInteger *= tPrescaler; 314 | 315 | tFrequency = ((float) (F_CPU / 2)) / tDividerInteger; 316 | /* 317 | * Save values 318 | */ 319 | sFrequencyInfo.Frequency = tFrequency; 320 | sFrequencyInfo.ControlValue.DividerInt = tDividerInteger; 321 | sFrequencyInfo.PeriodMicros = tDividerInteger / 8; 322 | return hasError; 323 | } 324 | 325 | void stopWaveform() { 326 | // set prescaler choice to 0 -> timer stops 327 | TCCR1B &= ~TIMER_PRESCALER_MASK; 328 | } 329 | 330 | void startWaveform() { 331 | TCCR1B &= ~TIMER_PRESCALER_MASK; 332 | TCCR1B |= sFrequencyInfo.PrescalerRegisterValueBackup; 333 | } 334 | 335 | //Timer1 overflow interrupt vector handler 336 | ISR(TIMER1_OVF_vect) { 337 | 338 | static int8_t sSineTableIndex = 0; 339 | static uint8_t sNumberOfQuadrant = 0; 340 | static uint8_t sNextOcrbValue = 0; 341 | 342 | // output value at start of ISR to avoid jitter 343 | OCR1B = sNextOcrbValue; 344 | /* 345 | * Increase index by sBaseFrequencyFactor. 346 | * In order to avoid floating point arithmetic in ISR, use sBaseFrequencyFactorShift16 and handle resulting residual. 347 | */ 348 | int8_t tIndexDelta = sFrequencyInfo.ControlValue.BaseFrequencyFactorShift16 >> 16; 349 | // handle fraction of frequency factor 350 | sFrequencyInfo.BaseFrequencyFactorAccumulator += sFrequencyInfo.ControlValue.BaseFrequencyFactorShift16 & 0xFFFF; 351 | if (sFrequencyInfo.BaseFrequencyFactorAccumulator > 0x8000) { 352 | /* 353 | * Accumulated fraction is bigger than "half" so increase index 354 | */ 355 | tIndexDelta++; 356 | sFrequencyInfo.BaseFrequencyFactorAccumulator -= 0x10000; 357 | } 358 | if (tIndexDelta > 0) { 359 | uint8_t tNumberOfQuadrant = sNumberOfQuadrant; 360 | if (sFrequencyInfo.Waveform == WAVEFORM_SINE) { 361 | uint8_t tQuadrantIncrease = 0; 362 | switch (tNumberOfQuadrant) { 363 | case 0: // [0,90) Degree, including 0, not including 90 Degree 364 | case 2: // [180,270) Degree 365 | sSineTableIndex += tIndexDelta; 366 | if (sSineTableIndex >= SIZE_OF_SINE_TABLE_QUARTER) { 367 | sSineTableIndex = SIZE_OF_SINE_TABLE_QUARTER - (sSineTableIndex - SIZE_OF_SINE_TABLE_QUARTER); 368 | tQuadrantIncrease = 1; 369 | } 370 | break; 371 | case 1: // [90,180) Degree 372 | case 3: // [270,360) Degree 373 | sSineTableIndex -= tIndexDelta; 374 | if (sSineTableIndex <= 0) { 375 | sSineTableIndex = -sSineTableIndex; 376 | tQuadrantIncrease = 1; 377 | } 378 | break; 379 | } 380 | if (tNumberOfQuadrant & 0x02) { 381 | // case 2 and 3 -128 -> 128 ; -255 -> 1 382 | sNextOcrbValue = -(pgm_read_byte(&sSineTableQuarter128[sSineTableIndex])); 383 | } else { 384 | sNextOcrbValue = pgm_read_byte(&sSineTableQuarter128[sSineTableIndex]); 385 | } 386 | 387 | tNumberOfQuadrant = (tNumberOfQuadrant + tQuadrantIncrease) & 0x03; 388 | 389 | /* 390 | * the same as loop with variable delay 391 | */ 392 | // // [0,90) 393 | // for (int i = 0; i < SIZE_OF_SINE_TABLE_QUARTER; ++i) { 394 | // OCR1B = sSineTableQuarter128[i]; 395 | // delayMicroseconds(sDelay); 396 | // } 397 | // // [90,180) 398 | // for (int i = SIZE_OF_SINE_TABLE_QUARTER; i > 0; i--) { 399 | // OCR1B = sSineTableQuarter128[i]; 400 | // delayMicroseconds(sDelay); 401 | // } 402 | // // [180,270) 403 | // for (int i = 0; i < SIZE_OF_SINE_TABLE_QUARTER; ++i) { 404 | // OCR1B = -(sSineTableQuarter128[i]); 405 | // delayMicroseconds(sDelay); 406 | // } 407 | // // [270,360) 408 | // for (int i = SIZE_OF_SINE_TABLE_QUARTER; i > 0; i--) { 409 | // OCR1B = -(sSineTableQuarter128[i]); 410 | // delayMicroseconds(sDelay); 411 | // } 412 | } else if (sFrequencyInfo.Waveform == WAVEFORM_TRIANGLE) { 413 | /* 414 | * Values 0 and FF are half as often as other values, so special treatment required 415 | * One period from 0 to 0 consists of 256 + 255 values! 416 | */ 417 | uint8_t tOldOcrbValue = sNextOcrbValue; 418 | if (tNumberOfQuadrant == 0) { 419 | // Value from 1 to FF 420 | // increasing value 421 | sNextOcrbValue += tIndexDelta; 422 | // detect overflow (value > UINT8_MAX) 423 | if (sNextOcrbValue < tOldOcrbValue) { 424 | tNumberOfQuadrant = 1; 425 | // 0->FE, 1->FD 426 | sNextOcrbValue = (~sNextOcrbValue) - 1; 427 | } 428 | } else { 429 | // decreasing value Value from FE to 0 430 | sNextOcrbValue -= tIndexDelta; 431 | // detect underflow 432 | if (sNextOcrbValue > tOldOcrbValue) { 433 | tNumberOfQuadrant = 0; 434 | // FF -> 1, FE -> 2 435 | sNextOcrbValue = -sNextOcrbValue; 436 | } 437 | } 438 | 439 | } else if (sFrequencyInfo.Waveform == WAVEFORM_SAWTOOTH) { 440 | sNextOcrbValue += tIndexDelta; 441 | } 442 | sNumberOfQuadrant = tNumberOfQuadrant; 443 | 444 | } 445 | } 446 | 447 | /* 448 | * Use it if you need a different size of table e.g. to generate different frequencies or increase accuracy for low frequencies 449 | */ 450 | void computeSineTableValues(uint8_t aSineTable[], unsigned int aNumber) { 451 | // 452 | float tRadianDelta = (M_PI * 2) / aNumber; 453 | float tRadian = 0.0; 454 | // (i <= aNumber) in order to include value for 360 degree 455 | for (unsigned int i = 0; i < aNumber; ++i) { 456 | float tSineFloat = (sin(tRadian) * 127) + 128; 457 | aSineTable[i] = (tSineFloat + 0.5); 458 | tRadian += tRadianDelta; 459 | } 460 | } 461 | #endif // defined(__AVR__) && defined(TCCR1A) 462 | -------------------------------------------------------------------------------- /Waveforms.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Waveforms.h 3 | * 4 | * Copyright (C) 2017-2023 Armin Joachimsmeyer 5 | * Email: armin.joachimsmeyer@gmail.com 6 | * 7 | * This file is part of Arduino-Simple-DSO https://github.com/ArminJo/Arduino-Simple-DSO. 8 | * 9 | * Arduino-Simple-DSO is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 17 | * See the GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #ifndef _WAVEFORMS_H 24 | #define _WAVEFORMS_H 25 | 26 | #define WAVEFORM_SQUARE 0 27 | #define WAVEFORM_SINE 1 28 | #define WAVEFORM_TRIANGLE 2 29 | #define WAVEFORM_SAWTOOTH 3 30 | #define WAVEFORM_MASK 0x03 31 | 32 | #define FREQUENCY_RANGE_INDEX_MILLI_HERTZ 0 33 | #define FREQUENCY_RANGE_INDEX_HERTZ 1 34 | #define FREQUENCY_RANGE_INDEX_KILO_HERTZ 2 35 | #define FREQUENCY_RANGE_INDEX_MEGA_HERTZ 3 36 | 37 | struct FrequencyInfoStruct { 38 | union { 39 | uint32_t DividerInt; // Only for square wave and for info - may be (divider * prescaler) - resolution is 1/8 us 40 | uint32_t BaseFrequencyFactorShift16; // Value used by ISR - only for NON square wave 41 | } ControlValue; 42 | uint32_t PeriodMicros; // only for display purposes 43 | float Frequency; // use float, since we have mHz. 44 | 45 | uint8_t Waveform; // 0 to WAVEFORM_MAX 46 | bool isOutputEnabled; 47 | 48 | /* 49 | * Normalized frequency variables for display 50 | * The effective frequency is FrequencyNormalizedTo_1_to_1000 * (FrequencyNormalizedFactorTimes1000 / 1000) 51 | */ 52 | float FrequencyNormalizedTo_1_to_1000; // Frequency values from 1 to 1000 for slider 53 | uint32_t FrequencyNormalizedFactorTimes1000; // factor for mHz/Hz/kHz/MHz - times 1000 because of mHz handling - 1 -> 1 mHz, 1000 -> 1 Hz, 1000000 -> 1 kHz 54 | uint8_t FrequencyRangeIndex; // index for FrequencyRangeChars[]. 0->mHz, 1->Hz, 2->kHz, 3->MHz 55 | 56 | /* 57 | * Internal (private) values 58 | */ 59 | int32_t BaseFrequencyFactorAccumulator; // Value used by ISR - used to handle fractions of BaseFrequencyFactorShift16 60 | 61 | uint8_t PrescalerRegisterValueBackup; // backup of old value for start/stop of square wave 62 | }; 63 | extern struct FrequencyInfoStruct sFrequencyInfo; 64 | 65 | extern const char FrequencyRangeChars[4]; // see FrequencyRangeIndex above 66 | 67 | void setWaveformMode(uint8_t aNewMode); 68 | void cycleWaveformMode(); 69 | const __FlashStringHelper* cycleWaveformModePGMString(); 70 | const __FlashStringHelper* getWaveformModePGMString(); 71 | float getPeriodMicros(); 72 | 73 | void setNormalizedFrequencyAndFactor(float aFrequency); 74 | void setNormalizedFrequencyFactorFromRangeIndex(uint8_t aFrequencyRangeIndex); 75 | 76 | void initTimer1For8BitPWM(); 77 | bool setWaveformFrequencyFromNormalizedValues(); 78 | bool setWaveformFrequency(float aFrequency); 79 | bool setSquareWaveFrequency(float aFrequency); 80 | 81 | void stopWaveform(); 82 | void startWaveform(); 83 | 84 | // utility Function 85 | void computeSineTableValues(uint8_t aSineTable[], unsigned int aNumber); 86 | 87 | #endif // _WAVEFORMS_H 88 | -------------------------------------------------------------------------------- /digitalWriteFast.h: -------------------------------------------------------------------------------- 1 | /* 2 | * digitalWriteFast.h 3 | * 4 | * Optimized digital functions for AVR microcontrollers 5 | * by Watterott electronic (www.watterott.com) 6 | * based on https://code.google.com/p/digitalwritefast 7 | * 8 | * License: BSD 3-Clause License (https://opensource.org/licenses/BSD-3-Clause) 9 | */ 10 | 11 | #ifndef __digitalWriteFast_h_ 12 | #define __digitalWriteFast_h_ 1 13 | 14 | //#define SANGUINO_PINOUT // define for Sanguino pinout 15 | 16 | // general macros/defines 17 | #if !defined(BIT_READ) 18 | # define BIT_READ(value, bit) ((value) & (1UL << (bit))) 19 | #endif 20 | #if !defined(BIT_SET) 21 | # define BIT_SET(value, bit) ((value) |= (1UL << (bit))) 22 | #endif 23 | #if !defined(BIT_CLEAR) 24 | # define BIT_CLEAR(value, bit) ((value) &= ~(1UL << (bit))) 25 | #endif 26 | #if !defined(BIT_WRITE) 27 | # define BIT_WRITE(value, bit, bitvalue) (bitvalue ? BIT_SET(value, bit) : BIT_CLEAR(value, bit)) 28 | #endif 29 | 30 | #include // declarations for the fallback to digitalWrite(), digitalRead() etc. 31 | 32 | // --- Arduino Mega and ATmega128x/256x based boards --- 33 | #if (defined(ARDUINO_AVR_MEGA) || \ 34 | defined(ARDUINO_AVR_MEGA1280) || \ 35 | defined(ARDUINO_AVR_MEGA2560) || \ 36 | defined(__AVR_ATmega1280__) || \ 37 | defined(__AVR_ATmega1281__) || \ 38 | defined(__AVR_ATmega2560__) || \ 39 | defined(__AVR_ATmega2561__)) 40 | 41 | #define __digitalPinToPortReg(P) \ 42 | (((P) >= 22 && (P) <= 29) ? &PORTA : \ 43 | ((((P) >= 10 && (P) <= 13) || ((P) >= 50 && (P) <= 53)) ? &PORTB : \ 44 | (((P) >= 30 && (P) <= 37) ? &PORTC : \ 45 | ((((P) >= 18 && (P) <= 21) || (P) == 38) ? &PORTD : \ 46 | ((((P) <= 3) || (P) == 5) ? &PORTE : \ 47 | (((P) >= 54 && (P) <= 61) ? &PORTF : \ 48 | ((((P) >= 39 && (P) <= 41) || (P) == 4) ? &PORTG : \ 49 | ((((P) >= 6 && (P) <= 9) || (P) == 16 || (P) == 17) ? &PORTH : \ 50 | (((P) == 14 || (P) == 15) ? &PORTJ : \ 51 | (((P) >= 62 && (P) <= 69) ? &PORTK : &PORTL)))))))))) 52 | 53 | #define __digitalPinToDDRReg(P) \ 54 | (((P) >= 22 && (P) <= 29) ? &DDRA : \ 55 | ((((P) >= 10 && (P) <= 13) || ((P) >= 50 && (P) <= 53)) ? &DDRB : \ 56 | (((P) >= 30 && (P) <= 37) ? &DDRC : \ 57 | ((((P) >= 18 && (P) <= 21) || (P) == 38) ? &DDRD : \ 58 | ((((P) <= 3) || (P) == 5) ? &DDRE : \ 59 | (((P) >= 54 && (P) <= 61) ? &DDRF : \ 60 | ((((P) >= 39 && (P) <= 41) || (P) == 4) ? &DDRG : \ 61 | ((((P) >= 6 && (P) <= 9) || (P) == 16 || (P) == 17) ? &DDRH : \ 62 | (((P) == 14 || (P) == 15) ? &DDRJ : \ 63 | (((P) >= 62 && (P) <= 69) ? &DDRK : &DDRL)))))))))) 64 | 65 | #define __digitalPinToPINReg(P) \ 66 | (((P) >= 22 && (P) <= 29) ? &PINA : \ 67 | ((((P) >= 10 && (P) <= 13) || ((P) >= 50 && (P) <= 53)) ? &PINB : \ 68 | (((P) >= 30 && (P) <= 37) ? &PINC : \ 69 | ((((P) >= 18 && (P) <= 21) || (P) == 38) ? &PIND : \ 70 | ((((P) <= 3) || (P) == 5) ? &PINE : \ 71 | (((P) >= 54 && (P) <= 61) ? &PINF : \ 72 | ((((P) >= 39 && (P) <= 41) || (P) == 4) ? &PING : \ 73 | ((((P) >= 6 && (P) <= 9) || (P) == 16 || (P) == 17) ? &PINH : \ 74 | (((P) == 14 || (P) == 15) ? &PINJ : \ 75 | (((P) >= 62 && (P) <= 69) ? &PINK : &PINL)))))))))) 76 | 77 | #define __digitalPinToBit(P) \ 78 | (((P) >= 7 && (P) <= 9) ? (P) - 3 : \ 79 | (((P) >= 10 && (P) <= 13) ? (P) - 6 : \ 80 | (((P) >= 22 && (P) <= 29) ? (P) - 22 : \ 81 | (((P) >= 30 && (P) <= 37) ? 37 - (P) : \ 82 | (((P) >= 39 && (P) <= 41) ? 41 - (P) : \ 83 | (((P) >= 42 && (P) <= 49) ? 49 - (P) : \ 84 | (((P) >= 50 && (P) <= 53) ? 53 - (P) : \ 85 | (((P) >= 54 && (P) <= 61) ? (P) - 54 : \ 86 | (((P) >= 62 && (P) <= 69) ? (P) - 62 : \ 87 | (((P) == 0 || (P) == 15 || (P) == 17 || (P) == 21) ? 0 : \ 88 | (((P) == 1 || (P) == 14 || (P) == 16 || (P) == 20) ? 1 : \ 89 | (((P) == 19) ? 2 : \ 90 | (((P) == 5 || (P) == 6 || (P) == 18) ? 3 : \ 91 | (((P) == 2) ? 4 : \ 92 | (((P) == 3 || (P) == 4) ? 5 : 7))))))))))))))) 93 | 94 | 95 | // --- Arduino MightyCore standard pinout --- 96 | #elif (defined(__AVR_ATmega1284P__) || \ 97 | defined(__AVR_ATmega1284__) || \ 98 | defined(__AVR_ATmega644P__) || \ 99 | defined(__AVR_ATmega644A__) || \ 100 | defined(__AVR_ATmega644__) || \ 101 | defined(__AVR_ATmega324PB__) || \ 102 | defined(__AVR_ATmega324PA__) || \ 103 | defined(__AVR_ATmega324P__) || \ 104 | defined(__AVR_ATmega324A__) || \ 105 | defined(__AVR_ATmega164P__) || \ 106 | defined(__AVR_ATmega164A__) || \ 107 | defined(__AVR_ATmega32__) || \ 108 | defined(__AVR_ATmega16__) || \ 109 | defined(__AVR_ATmega8535__)) && \ 110 | !defined(BOBUINO_PINOUT) 111 | 112 | #if defined(__AVR_ATmega324PB__) 113 | #define __digitalPinToPortReg(P) \ 114 | (((P) <= 7) ? &PORTB : (((P) >= 8 && (P) <= 15) ? &PORTD : (((P) >= 16 && (P) <= 23) ? &PORTC : (((P) >= 24 && (P) <= 31) ? &PORTA : &PORTE)))) 115 | #define __digitalPinToDDRReg(P) \ 116 | (((P) <= 7) ? &DDRB : (((P) >= 8 && (P) <= 15) ? &DDRD : (((P) >= 16 && (P) <= 23) ? &DDRC : (((P) >= 24 && (P) <= 31) ? &DDRA : &DDRE)))) 117 | #define __digitalPinToPINReg(P) \ 118 | (((P) <= 7) ? &PINB : (((P) >= 8 && (P) <= 15) ? &PIND : (((P) >= 16 && (P) <= 23) ? &PINC : (((P) >= 24 && (P) <= 31) ? &PINA : &PINE)))) 119 | # if defined(SANGUINO_PINOUT) 120 | #define __digitalPinToBit(P) \ 121 | (((P) <= 7) ? (P) : (((P) >= 8 && (P) <= 15) ? (P) - 8 : (((P) >= 16 && (P) <= 23) ? (P) - 16 : (((P) >= 16 && (P) <= 23) ? (7 - ((P) - 24)) : (P) - 32)))) 122 | # else //MightyCore Pinout 123 | #define __digitalPinToBit(P) \ 124 | (((P) <= 7) ? (P) : (((P) >= 8 && (P) <= 15) ? (P) - 8 : (((P) >= 16 && (P) <= 23) ? (P) - 16 : (((P) >= 16 && (P) <= 23) ? (P) - 24 : (P) - 32)))) 125 | # endif 126 | #elif defined(PORTA) 127 | #define __digitalPinToPortReg(P) \ 128 | (((P) <= 7) ? &PORTB : (((P) >= 8 && (P) <= 15) ? &PORTD : (((P) >= 16 && (P) <= 23) ? &PORTC : &PORTA))) 129 | #define __digitalPinToDDRReg(P) \ 130 | (((P) <= 7) ? &DDRB : (((P) >= 8 && (P) <= 15) ? &DDRD : (((P) >= 16 && (P) <= 23) ? &DDRC : &DDRA))) 131 | #define __digitalPinToPINReg(P) \ 132 | (((P) <= 7) ? &PINB : (((P) >= 8 && (P) <= 15) ? &PIND : (((P) >= 16 && (P) <= 23) ? &PINC : &PINA))) 133 | # if defined(SANGUINO_PINOUT) 134 | #define __digitalPinToBit(P) \ 135 | (((P) <= 7) ? (P) : (((P) >= 8 && (P) <= 15) ? (P) - 8 : (((P) >= 16 && (P) <= 23) ? (P) - 16 : (7 - ((P) - 24))))) 136 | # else //MightyCore Pinout 137 | #define __digitalPinToBit(P) \ 138 | (((P) <= 7) ? (P) : (((P) >= 8 && (P) <= 15) ? (P) - 8 : (((P) >= 16 && (P) <= 23) ? (P) - 16 : (P) - 24))) 139 | # endif 140 | #else 141 | #define __digitalPinToPortReg(P) \ 142 | (((P) <= 7) ? &PORTB : (((P) >= 8 && (P) <= 15) ? &PORTD : &PORTC)) 143 | #define __digitalPinToDDRReg(P) \ 144 | (((P) <= 7) ? &DDRB : (((P) >= 8 && (P) <= 15) ? &DDRD : &DDRC)) 145 | #define __digitalPinToPINReg(P) \ 146 | (((P) <= 7) ? &PINB : (((P) >= 8 && (P) <= 15) ? &PIND : &PINC)) 147 | # if defined(SANGUINO_PINOUT) 148 | #define __digitalPinToBit(P) \ 149 | (((P) <= 7) ? (P) : (((P) >= 8 && (P) <= 15) ? (P) - 8 : (((P) >= 16 && (P) <= 23) ? (P) - 16 : (7 - ((P) - 24))))) 150 | # else //MightyCore Pinout 151 | #define __digitalPinToBit(P) \ 152 | (((P) <= 7) ? (P) : (((P) >= 8 && (P) <= 15) ? (P) - 8 : (((P) >= 16 && (P) <= 23) ? (P) - 16 : (P) - 24))) 153 | # endif 154 | #endif 155 | 156 | 157 | // --- Arduino Leonardo and ATmega16U4/32U4 based boards --- 158 | #elif (defined(ARDUINO_AVR_LEONARDO) || \ 159 | defined(__AVR_ATmega16U4__) || \ 160 | defined(__AVR_ATmega32U4__)) 161 | # if defined(TEENSYDUINO) 162 | 163 | #define __digitalPinToPortReg(P) \ 164 | ((((P) <= 4) || ((P) >= 13 && (P) <= 15)) ? &PORTB : (((P) == 9 || (P) == 10) ? &PORTC : (((P) >= 16 && (P) <= 21)) ? &PORTF : &PORTD)) 165 | #define __digitalPinToDDRReg(P) \ 166 | ((((P) <= 4) || ((P) >= 13 && (P) <= 15)) ? &DDRB : (((P) == 9 || (P) == 10) ? &DDRC : (((P) >= 16 && (P) <= 21)) ? &DDRF : &DDRD)) 167 | #define __digitalPinToPINReg(P) \ 168 | ((((P) <= 4) || ((P) >= 13 && (P) <= 15)) ? &PINB : (((P) == 9 || (P) == 10) ? &PINC : (((P) >= 16 && (P) <= 21)) ? &PINF : &PIND)) 169 | #define __digitalPinToBit(P) \ 170 | (((P) <= 3) ? (P) : \ 171 | (((P) == 4 || (P) == 12) ? 7 : \ 172 | (((P) <= 8) ? (P) - 5 : \ 173 | (((P) <= 10) ? (P) - 3 : \ 174 | (((P) == 11) ? 6 : \ 175 | (((P) <= 15) ? (P) - 9 : \ 176 | (((P) <= 19) ? 23 - (P) : \ 177 | (((P) <= 21) ? 21 - (P) : (P) - 18)))))))) 178 | # else 179 | 180 | #define __digitalPinToPortReg(P) \ 181 | ((((P) <= 4) || (P) == 6 || (P) == 12 || (P) == 24 || (P) == 25 || (P) == 29) ? &PORTD : (((P) == 5 || (P) == 13) ? &PORTC : (((P) >= 18 && (P) <= 23)) ? &PORTF : (((P) == 7) ? &PORTE : &PORTB))) 182 | #define __digitalPinToDDRReg(P) \ 183 | ((((P) <= 4) || (P) == 6 || (P) == 12 || (P) == 24 || (P) == 25 || (P) == 29) ? &DDRD : (((P) == 5 || (P) == 13) ? &DDRC : (((P) >= 18 && (P) <= 23)) ? &DDRF : (((P) == 7) ? &DDRE : &DDRB))) 184 | #define __digitalPinToPINReg(P) \ 185 | ((((P) <= 4) || (P) == 6 || (P) == 12 || (P) == 24 || (P) == 25 || (P) == 29) ? &PIND : (((P) == 5 || (P) == 13) ? &PINC : (((P) >= 18 && (P) <= 23)) ? &PINF : (((P) == 7) ? &PINE : &PINB))) 186 | #define __digitalPinToBit(P) \ 187 | (((P) >= 8 && (P) <= 11) ? (P) - 4 : \ 188 | (((P) >= 18 && (P) <= 21) ? 25 - (P) : \ 189 | (((P) == 0) ? 2 : (((P) == 1) ? 3 : (((P) == 2) ? 1 : (((P) == 3) ? 0 : (((P) == 4) ? 4 : (((P) == 6) ? 7 : (((P) == 13) ? 7 : \ 190 | (((P) == 14) ? 3 : (((P) == 15) ? 1 : (((P) == 16) ? 2 : (((P) == 17) ? 0 : (((P) == 22) ? 1 : (((P) == 23) ? 0 : \ 191 | (((P) == 24) ? 4 : (((P) == 25) ? 7 : (((P) == 26) ? 4 : (((P) == 27) ? 5 : 6 ))))))))))))))))))) 192 | # endif 193 | 194 | // --- Arduino Uno and ATmega168/328 based boards --- 195 | #elif (defined(ARDUINO_AVR_UNO) || \ 196 | defined(ARDUINO_AVR_DUEMILANOVE) || \ 197 | defined(__AVR_ATmega8__) || \ 198 | defined(__AVR_ATmega48__) || \ 199 | defined(__AVR_ATmega48P__) || \ 200 | defined(__AVR_ATmega48PB__) || \ 201 | defined(__AVR_ATmega88P__) || \ 202 | defined(__AVR_ATmega88PB__) || \ 203 | defined(__AVR_ATmega168__) || \ 204 | defined(__AVR_ATmega168PA__) || \ 205 | defined(__AVR_ATmega168PB__) || \ 206 | defined(__AVR_ATmega328__) || \ 207 | defined(__AVR_ATmega328P__) || \ 208 | defined(__AVR_ATmega328PB__)) 209 | 210 | #if defined(__AVR_ATmega48PB__) || defined(__AVR_ATmega88PB__) || defined(__AVR_ATmega168PB__) || defined(__AVR_ATmega328PB__) 211 | #define __digitalPinToPortReg(P) \ 212 | (((P) <= 7) ? &PORTD : (((P) >= 8 && (P) <= 13) ? &PORTB : (((P) >= 14 && (P) <= 19) ? &PORTC : &PORTE))) 213 | #define __digitalPinToDDRReg(P) \ 214 | (((P) <= 7) ? &DDRD : (((P) >= 8 && (P) <= 13) ? &DDRB : (((P) >= 14 && (P) <= 19) ? &DDRC : &DDRE))) 215 | #define __digitalPinToPINReg(P) \ 216 | (((P) <= 7) ? &PIND : (((P) >= 8 && (P) <= 13) ? &PINB : (((P) >= 14 && (P) <= 19) ? &PINC : &PINE))) 217 | #define __digitalPinToBit(P) \ 218 | (((P) <= 7) ? (P) : (((P) >= 8 && (P) <= 13) ? (P) - 8 : (((P) >= 14 && (P) <= 19) ? (P) - 14 : (((P) >= 20 && (P) <= 21) ? (P) - 18 : (P) - 22)))) 219 | #else 220 | #define __digitalPinToPortReg(P) \ 221 | (((P) <= 7) ? &PORTD : (((P) >= 8 && (P) <= 13) ? &PORTB : &PORTC)) 222 | #define __digitalPinToDDRReg(P) \ 223 | (((P) <= 7) ? &DDRD : (((P) >= 8 && (P) <= 13) ? &DDRB : &DDRC)) 224 | #define __digitalPinToPINReg(P) \ 225 | (((P) <= 7) ? &PIND : (((P) >= 8 && (P) <= 13) ? &PINB : &PINC)) 226 | #define __digitalPinToBit(P) \ 227 | (((P) <= 7) ? (P) : (((P) >= 8 && (P) <= 13) ? (P) - 8 : (P) - 14)) 228 | #endif 229 | 230 | // --- Arduino Uno WiFi Rev 2, Nano Every --- 231 | #elif defined(__AVR_ATmega4809__) 232 | 233 | #define __digitalPinToPortReg(P) \ 234 | (((P) == 2 || (P) == 7 ) ? &VPORTA.OUT : ((P) == 5 || (P) == 9 || (P) == 10) ? &VPORTB.OUT : ((P) == 4) ? &VPORTC.OUT : (((P) >= 14 && (P) <= 17) || (P) == 20 || (P) == 21) ? &VPORTD.OUT : ((P) == 8 || (P) == 11 || (P) == 12 || (P) == 13) ? &VPORTE.OUT : &VPORTF.OUT) 235 | #define __digitalPinToDDRReg(P) \ 236 | (((P) == 2 || (P) == 7 ) ? &VPORTA.DIR : ((P) == 5 || (P) == 9 || (P) == 10) ? &VPORTB.DIR : ((P) == 4) ? &VPORTC.DIR : (((P) >= 14 && (P) <= 17) || (P) == 20 || (P) == 21) ? &VPORTD.DIR : ((P) == 8 || (P) == 11 || (P) == 12 || (P) == 13) ? &VPORTE.DIR : &VPORTF.DIR) 237 | #define __digitalPinToPINReg(P) \ 238 | (((P) == 2 || (P) == 7 ) ? &VPORTA.IN : ((P) == 5 || (P) == 9 || (P) == 10) ? &VPORTB.IN : ((P) == 4) ? &VPORTC.IN : (((P) >= 14 && (P) <= 17) || (P) == 20 || (P) == 21) ? &VPORTD.IN : ((P) == 8 || (P) == 11 || (P) == 12 || (P) == 13) ? &VPORTE.IN : &VPORTF.IN) 239 | #define __digitalPinToBit(P) \ 240 | (((P) == 2 || (P) == 9 || (P) == 11 || (P) == 17) ? 0 : ((P) == 7 || (P) == 10 || (P) == 12 || (P) == 16) ? 1 : ((P) == 5 || (P) == 13 || (P) == 15 || (P) == 18) ? 2 : ((P) == 9 || (P) == 14 || (P) == 19) ? 3 : ((P) == 6 || (P) == 20) ? 4 : ((P) == 3 || (P) == 21) ? 5 : 6 ) 241 | 242 | 243 | // TinyCore 244 | // https://raw.githubusercontent.com/xukangmin/TinyCore/master/avr/package/package_tinycore_index.json 245 | // https://docs.tinycore.dev/en/latest/ 246 | #elif defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) 247 | #define __digitalPinToPortReg(P) ((P) <= 5 ? &VPORTB.OUT : ((P) <= 9 ? &VPORTC.OUT : ((P) <= 16 ? &VPORTA.OUT : ((P) <= 18 ? &VPORTB.OUT : &VPORTC.OUT)))) 248 | #define __digitalPinToDDRReg(P) ((P) <= 5 ? &VPORTB.DIR : ((P) <= 9 ? &VPORTC.DIR : ((P) <= 16 ? &VPORTA.DIR : ((P) <= 18 ? &VPORTB.DIR : &VPORTC.DIR)))) 249 | #define __digitalPinToPINReg(P) ((P) <= 5 ? &VPORTB.IN : ((P) <= 9 ? &VPORTC.IN : ((P) <= 16 ? &VPORTA.IN : ((P) <= 18 ? &VPORTB.IN : &VPORTC.IN)))) 250 | #define __digitalPinToBit(P) ( (P) <= 3 ? (3 - P) : ((P) <= 5 ? (P) : ((P) <= 9 ? (P - 6) : ((P) <= 16 ? ((P) - 9) : ((P) <= 18 ? ((P) - 11) : ((P) - 15))))) ) 251 | 252 | #elif defined(__AVR_ATtiny1614__) 253 | #define __digitalPinToPortReg(P) ((P) <= 3 ? &VPORTA.OUT : ((P) <= 7 ? &VPORTB.OUT : &VPORTA.OUT)) 254 | #define __digitalPinToDDRReg(P) ((P) <= 3 ? &VPORTA.DIR : ((P) <= 7 ? &VPORTB.DIR : &VPORTA.DIR)) 255 | #define __digitalPinToPINReg(P) ((P) <= 3 ? &VPORTA.IN : ((P) <= 7 ? &VPORTB.IN : &VPORTA.IN)) 256 | #define __digitalPinToBit(P) ( (P) <= 3 ? (P + 4) : ((P) <= 7 ? (7 - P) : ((P) <= 10 ? (P - 7) : (P) - 11)) ) 257 | 258 | #elif defined(__AVR_ATtiny816__) 259 | // https://github.com/Arduino-IRremote/Arduino-IRremote/discussions/1029 260 | #define __digitalPinToPortReg(P) ((P) <= 3 ? &VPORTA.OUT : ((P) <= 9 ? &VPORTB.OUT : ((P) <= 13 ? &VPORTC.OUT : ((P) <= 17 ? &VPORTA.OUT : &VPORTC.OUT)))) 261 | #define __digitalPinToDDRReg(P) ((P) <= 3 ? &VPORTA.DIR : ((P) <= 9 ? &VPORTB.DIR : ((P) <= 13 ? &VPORTC.DIR : ((P) <= 17 ? &VPORTA.DIR : &VPORTC.DIR)))) 262 | #define __digitalPinToPINReg(P) ((P) <= 3 ? &VPORTA.IN : ((P) <= 9 ? &VPORTB.IN : ((P) <= 13 ? &VPORTC.IN : ((P) <= 17 ? &VPORTA.IN : &VPORTC.IN)))) 263 | #define __digitalPinToBit(P) ( (P) <= 3 ? (P + 4) : ((P) <= 9 ? (9 - P) : ((P) <= 13 ? (P - 10) : ((P) <= 16 ? (P - 13) : ((P) - 17)))) ) 264 | 265 | // --- ATtinyX5 --- 266 | #elif defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) 267 | // we have only PORTB 268 | #define __digitalPinToPortReg(P) (&PORTB) 269 | #define __digitalPinToDDRReg(P) (&DDRB) 270 | #define __digitalPinToPINReg(P) (&PINB) 271 | #define __digitalPinToBit(P) (((P) <= 7) ? (P) : (((P) >= 8 && (P) <= 13) ? (P) - 8 : (P) - 14)) 272 | 273 | 274 | // --- ATtiny88 --- 275 | #elif defined(__AVR_ATtiny88__) 276 | # if defined(ARDUINO_AVR_DIGISPARKPRO) 277 | #define __digitalPinToPortReg(P) ((P) <= 7 ? &PORTD : ((P) <= 14 ? &PORTB : ((P) <= 18 ? &PORTA : &PORTC))) 278 | #define __digitalPinToDDRReg(P) ((P) <= 7 ? &DDRD : ((P) <= 14 ? &DDRB : ((P) <= 18 ? &DDRA : &DDRC))) 279 | #define __digitalPinToPINReg(P) ((P) <= 7 ? &PIND : ((P) <= 14 ? &PINB : ((P) <= 18 ? &PINA : &PINC))) 280 | #define __digitalPinToBit(P) ( (P) <= 7 ? (P) : ((P) <= 13 ? ((P) - 8) : ((P) == 14 ? 7 : ((P) <= 16 ? ((P) - 14) : ((P) <= 18 ? ((P) - 17) : ((P) == 25 ? 7 : ((P) - 19)))))) ) 281 | # else 282 | #define __digitalPinToPortReg(P) ((P) <= 7 ? &PORTD : ((P) <= 15 ? &PORTB : ((P) <= 22 ? &PORTC : ((P) <= 26 ? &PORTA : &PORTC)))) 283 | #define __digitalPinToDDRReg(P) ((P) <= 7 ? &DDRD : ((P) <= 15 ? &DDRB : ((P) <= 22 ? &DDRC : ((P) <= 26 ? &DDRA : &DDRC)))) 284 | #define __digitalPinToPINReg(P) ((P) <= 7 ? &PIND : ((P) <= 15 ? &PINB : ((P) <= 22 ? &PINC : ((P) <= 26 ? &PINA : &PINC)))) 285 | #define __digitalPinToBit(P) ((P) <= 15 ? ((P) & 0x7) : ((P) == 16 ? (7) : ((P) <= 22 ? ((P) - 17) : ((P) == 27 ? (6) : ((P) - 23))))) 286 | # endif 287 | 288 | 289 | // --- ATtinyX4 + ATtinyX7 --- 290 | #elif defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) \ 291 | || defined(__AVR_ATtiny441__) || defined(__AVR_ATtiny841__) || defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) 292 | # if defined(ARDUINO_AVR_DIGISPARKPRO) || PIN_PA7 == 5 293 | // Strange enumeration of pins on Digispark board and core library 294 | #define __digitalPinToPortReg(P) (((P) <= 4) ? &PORTB : &PORTA) 295 | #define __digitalPinToDDRReg(P) (((P) <= 4) ? &DDRB : &DDRA) 296 | #define __digitalPinToPINReg(P) (((P) <= 4) ? &PINB : &PINA) 297 | #define __digitalPinToBit(P) (((P) <= 2) ? (P) : (((P) == 3) ? 6 : (((P) == 4) ? 3 : (((P) == 5) ? 7 : (P) - 6 )))) 298 | # else 299 | // ATtinyX4: PORTA for 0 to 7, PORTB for 8 to 11 300 | // ATtinyX7: PORTA for 0 to 7, PORTB for 8 to 15 301 | #define __digitalPinToPortReg(P) (((P) <= 7) ? &PORTA : &PORTB) 302 | #define __digitalPinToDDRReg(P) (((P) <= 7) ? &DDRA : &DDRB) 303 | #define __digitalPinToPINReg(P) (((P) <= 7) ? &PINA : &PINB) 304 | # endif 305 | # if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny441__) || defined(__AVR_ATtiny841__) 306 | // https://github.com/SpenceKonde/ATTinyCore/blob/v2.0.0-devThis-is-the-head-submit-PRs-against-this/avr/variants/tinyx41_cw/pins_arduino.h#L334 307 | // Clockwise layout 308 | #define __digitalPinToBit(P) (((P) <= 7) ? (P) : ((P) == 11 ? (3) : 10 - (P))) 309 | # else 310 | #define __digitalPinToBit(P) (((P) <= 7) ? (P) : (P) - 8 ) 311 | # endif 312 | 313 | #endif 314 | 315 | 316 | void NonConstantsUsedForPinModeFast( void ) __attribute__ (( error("Parameter for pinModeFast() function is not constant") )); 317 | void NonConstantsUsedForDigitalWriteFast( void ) __attribute__ (( error("Parameter for digitalWriteFast() function is not constant") )); 318 | void NonConstantsUsedForDigitalToggleFast( void ) __attribute__ (( error("Parameter for digitalToggleFast() function is not constant") )); 319 | int NonConstantsUsedForDigitalReadFast( void ) __attribute__ (( error("Parameter for digitalReadFast() function is not constant") )); 320 | 321 | #if !defined(digitalWriteFast) 322 | # if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) && defined(__digitalPinToPortReg) 323 | # if defined(THROW_ERROR_IF_NOT_FAST) 324 | #define digitalWriteFast(P, V) \ 325 | if (__builtin_constant_p(P)) { \ 326 | BIT_WRITE(*__digitalPinToPortReg(P), __digitalPinToBit(P), (V)); \ 327 | } else { \ 328 | NonConstantsUsedForDigitalWriteFast(); \ 329 | } 330 | # else 331 | #define digitalWriteFast(P, V) \ 332 | if (__builtin_constant_p(P)) { \ 333 | BIT_WRITE(*__digitalPinToPortReg(P), __digitalPinToBit(P), (V)); \ 334 | } else { \ 335 | digitalWrite((P), (V)); \ 336 | } 337 | # endif // defined(THROW_ERROR_IF_NOT_FAST) 338 | # else 339 | #define digitalWriteFast digitalWrite 340 | # endif 341 | #endif 342 | 343 | #if !defined(pinModeFast) 344 | # if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) && defined(__digitalPinToPortReg) 345 | # if defined(THROW_ERROR_IF_NOT_FAST) 346 | #define pinModeFast(P, V) \ 347 | if (__builtin_constant_p(P) && __builtin_constant_p(V)) { \ 348 | if (V == INPUT_PULLUP) {\ 349 | BIT_CLEAR(*__digitalPinToDDRReg(P), __digitalPinToBit(P)); \ 350 | BIT_SET(*__digitalPinToPortReg(P), __digitalPinToBit(P)); \ 351 | } else { \ 352 | BIT_WRITE(*__digitalPinToDDRReg(P), __digitalPinToBit(P), (V)); \ 353 | } \ 354 | } else { \ 355 | NonConstantsUsedForPinModeFast(); \ 356 | } 357 | # else 358 | #define pinModeFast(P, V) \ 359 | if (__builtin_constant_p(P) && __builtin_constant_p(V)) { \ 360 | if (V == INPUT_PULLUP) {\ 361 | BIT_CLEAR(*__digitalPinToDDRReg(P), __digitalPinToBit(P)); \ 362 | BIT_SET(*__digitalPinToPortReg(P), __digitalPinToBit(P)); \ 363 | } else { \ 364 | BIT_WRITE(*__digitalPinToDDRReg(P), __digitalPinToBit(P), (V)); \ 365 | } \ 366 | } else { \ 367 | pinMode((P), (V)); \ 368 | } 369 | # endif // defined(THROW_ERROR_IF_NOT_FAST) 370 | # else 371 | #define pinModeFast pinMode 372 | # endif 373 | #endif // !defined(pinModeFast) 374 | 375 | #if !defined(digitalReadFast) 376 | # if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) && defined(__digitalPinToPINReg) 377 | # if defined(THROW_ERROR_IF_NOT_FAST) 378 | #define digitalReadFast(P) ( (int) __digitalReadFast((P)) ) 379 | // since we have return values, it is easier to implement it by ?: 380 | #define __digitalReadFast(P ) \ 381 | (__builtin_constant_p(P) ) ? \ 382 | (( BIT_READ(*__digitalPinToPINReg(P), __digitalPinToBit(P))) ? HIGH:LOW ) : \ 383 | NonConstantsUsedForDigitalReadFast() 384 | # else 385 | #define digitalReadFast(P) ( (int) __digitalReadFast((P)) ) 386 | // since we have return values, it is easier to implement it by ?: 387 | #define __digitalReadFast(P ) \ 388 | (__builtin_constant_p(P) ) ? \ 389 | (( BIT_READ(*__digitalPinToPINReg(P), __digitalPinToBit(P))) ? HIGH:LOW ) : \ 390 | digitalRead((P)) 391 | # endif // defined(THROW_ERROR_IF_NOT_FAST) 392 | # else 393 | #define digitalReadFast digitalRead 394 | # endif 395 | #endif // !defined(digitalReadFast) 396 | 397 | #if !defined(digitalToggleFast) 398 | # if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) && defined(__digitalPinToPINReg) 399 | # if defined(THROW_ERROR_IF_NOT_FAST) 400 | #define digitalToggleFast(P) \ 401 | if (__builtin_constant_p(P)) { \ 402 | BIT_SET(*__digitalPinToPINReg(P), __digitalPinToBit(P)); \ 403 | } else { \ 404 | NonConstantsUsedForDigitalToggleFast(); \ 405 | } 406 | # else 407 | #define digitalToggleFast(P) \ 408 | if (__builtin_constant_p(P)) { \ 409 | BIT_SET(*__digitalPinToPINReg(P), __digitalPinToBit(P)); \ 410 | } else { \ 411 | digitalWrite(P, ! digitalRead(P)); \ 412 | } 413 | # endif // defined(THROW_ERROR_IF_NOT_FAST) 414 | # else 415 | #define digitalToggleFast(P) digitalWrite(P, ! digitalRead(P)) 416 | # endif 417 | #endif // !defined(digitalToggleFast) 418 | 419 | #endif //__digitalWriteFast_h_ 420 | -------------------------------------------------------------------------------- /extras/Arduino_Nano_DSO_BT_full.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-Simple-DSO/bdcbf9de6674cb9bfa9e04b37a6b91971eb8738b/extras/Arduino_Nano_DSO_BT_full.fzz -------------------------------------------------------------------------------- /extras/Arduino_Nano_DSO_BT_full_Schaltplan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-Simple-DSO/bdcbf9de6674cb9bfa9e04b37a6b91971eb8738b/extras/Arduino_Nano_DSO_BT_full_Schaltplan.png -------------------------------------------------------------------------------- /extras/Arduino_Nano_DSO_BT_full_Steckplatine.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-Simple-DSO/bdcbf9de6674cb9bfa9e04b37a6b91971eb8738b/extras/Arduino_Nano_DSO_BT_full_Steckplatine.png -------------------------------------------------------------------------------- /extras/Arduino_Nano_DSO_BT_simple.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-Simple-DSO/bdcbf9de6674cb9bfa9e04b37a6b91971eb8738b/extras/Arduino_Nano_DSO_BT_simple.fzz -------------------------------------------------------------------------------- /extras/Arduino_Nano_DSO_BT_simple_Schaltplan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-Simple-DSO/bdcbf9de6674cb9bfa9e04b37a6b91971eb8738b/extras/Arduino_Nano_DSO_BT_simple_Schaltplan.png -------------------------------------------------------------------------------- /extras/Arduino_Nano_DSO_BT_simple_Steckplatine.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-Simple-DSO/bdcbf9de6674cb9bfa9e04b37a6b91971eb8738b/extras/Arduino_Nano_DSO_BT_simple_Steckplatine.png -------------------------------------------------------------------------------- /extras/Arduino_Nano_DSO_simple.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-Simple-DSO/bdcbf9de6674cb9bfa9e04b37a6b91971eb8738b/extras/Arduino_Nano_DSO_simple.fzz -------------------------------------------------------------------------------- /extras/Arduino_Nano_DSO_simple_Schaltplan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-Simple-DSO/bdcbf9de6674cb9bfa9e04b37a6b91971eb8738b/extras/Arduino_Nano_DSO_simple_Schaltplan.png -------------------------------------------------------------------------------- /extras/Arduino_Nano_DSO_simple_Steckplatine.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-Simple-DSO/bdcbf9de6674cb9bfa9e04b37a6b91971eb8738b/extras/Arduino_Nano_DSO_simple_Steckplatine.png -------------------------------------------------------------------------------- /pictures/ArduinoDSO.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-Simple-DSO/bdcbf9de6674cb9bfa9e04b37a6b91971eb8738b/pictures/ArduinoDSO.jpg -------------------------------------------------------------------------------- /pictures/ArduinoDSO_Closeup.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-Simple-DSO/bdcbf9de6674cb9bfa9e04b37a6b91971eb8738b/pictures/ArduinoDSO_Closeup.jpg -------------------------------------------------------------------------------- /pictures/ArduinoDSO_simple.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-Simple-DSO/bdcbf9de6674cb9bfa9e04b37a6b91971eb8738b/pictures/ArduinoDSO_simple.jpg -------------------------------------------------------------------------------- /pictures/Chart.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-Simple-DSO/bdcbf9de6674cb9bfa9e04b37a6b91971eb8738b/pictures/Chart.jpg -------------------------------------------------------------------------------- /pictures/Chart_Long_Info.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-Simple-DSO/bdcbf9de6674cb9bfa9e04b37a6b91971eb8738b/pictures/Chart_Long_Info.jpg -------------------------------------------------------------------------------- /pictures/DSO+Tablet.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-Simple-DSO/bdcbf9de6674cb9bfa9e04b37a6b91971eb8738b/pictures/DSO+Tablet.jpg -------------------------------------------------------------------------------- /pictures/Frequency.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-Simple-DSO/bdcbf9de6674cb9bfa9e04b37a6b91971eb8738b/pictures/Frequency.jpg -------------------------------------------------------------------------------- /pictures/Linearity_13us_conversion_time.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-Simple-DSO/bdcbf9de6674cb9bfa9e04b37a6b91971eb8738b/pictures/Linearity_13us_conversion_time.jpg -------------------------------------------------------------------------------- /pictures/Linearity_26us_conversion_time.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-Simple-DSO/bdcbf9de6674cb9bfa9e04b37a6b91971eb8738b/pictures/Linearity_26us_conversion_time.jpg -------------------------------------------------------------------------------- /pictures/Linearity_3us_conversion_time.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-Simple-DSO/bdcbf9de6674cb9bfa9e04b37a6b91971eb8738b/pictures/Linearity_3us_conversion_time.jpg -------------------------------------------------------------------------------- /pictures/Linearity_6us5_conversion_time.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-Simple-DSO/bdcbf9de6674cb9bfa9e04b37a6b91971eb8738b/pictures/Linearity_6us5_conversion_time.jpg -------------------------------------------------------------------------------- /pictures/SettingsBluePill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-Simple-DSO/bdcbf9de6674cb9bfa9e04b37a6b91971eb8738b/pictures/SettingsBluePill.png -------------------------------------------------------------------------------- /pictures/Settings_Passive_Attenuator.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-Simple-DSO/bdcbf9de6674cb9bfa9e04b37a6b91971eb8738b/pictures/Settings_Passive_Attenuator.jpg -------------------------------------------------------------------------------- /pictures/Settings_simple.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-Simple-DSO/bdcbf9de6674cb9bfa9e04b37a6b91971eb8738b/pictures/Settings_simple.jpg -------------------------------------------------------------------------------- /pictures/Welcome.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-Simple-DSO/bdcbf9de6674cb9bfa9e04b37a6b91971eb8738b/pictures/Welcome.jpg --------------------------------------------------------------------------------