Components and supplies
Arduino UNO
AD9833 - DDS
Apps and platforms
Processing
Project description
Code
Processing Sketch (GUI)
processing
Processing Sketch (GUI)
processing
Arduino Sketch
arduino
1// Interleaved Oscilloscope for Arduino UNO - easily achieve 20kHz wavefunctions 2// Arduino Sketch by Claudio Lenz Cesar(CLC) - Instituto de Fisica - UFRJ (25/July/2020) 3// Based on the osciloscope Sketch by Veldekiaan at https://create.arduino.cc/projecthub/Veldekiaan/sampling-scope-frequency-counter-2e4196 4// Need to Install "Processing" and the new Processing Sketch (added a Save Ch button and comands '<','>' to increase PWM freq.) or use his Processing Sketch (.pde) in the link above 5// and change the first 3 TimebaseSets (lines ~229) to 6/* 7 new TimebaseSet(1, 0.0001, 475, 0.000003), // 0 com Interleaving x5 8 new TimebaseSet(2, 0.0001, 140, 0.000015), 9 new TimebaseSet(5, 0.0001, 350, 0.000015), 10 */ 11// and lines 5 and 7 to: 12/* 13 boolean scope = true; // start with Scope instead of Counter 14 15 static final String SerialPort ="/dev/cu.usbserial-RCBB_4OK6T4"; // Change this to match your Arduino port 16 */ 17// The original Veldekiaan's project triggered (Interrupt) in a PWM port square signal (I changed the port: needed that for the DDS AD9833 control) 18// Here I keep the PWM pin5 but disconnected the trigger input Pin2 (can still use it) 19// I added a trigger Interrupt based on the AnalogComparator (pins6[+] and 7[-]) (lines 215...) 20// FOr this realization, the AC+ = internal reference = 1.1V and the sinewave generated by the AD9833 (at about 3V) is also input in AC-=pin7[-] 21// I increased the clock for the ADC, using Prescaler=04. The conversion then takes about 13,5 cycles = 13,5*(4/16) s= 3,4s 22// Using an interleaving factor of x5 (in the 100s scale only), I set the readings after each trigger to be happen at 15s time interval (timer interrupt) 23// Then, after getting many points in a single AC trigger (single wave), I restart again, but now getting the ADC readings after a time delay of 3s, then again at 6s, and so on 24// Connections: For the AD9833:13=CLK,11=DATA, 10=FSYNC 25// D5=saida PWM, ligada num led+300ohm p/ GND (piscando to rapido que s vemos intensidade mdia) e tambm na A5 para ler no osciloscpio 26// D4=sada do trigger, ligada num LED+300ohm p/ GND = deve ficar piscando 27// pino7 = entrada AIN1 para comparador: ligada na sada do AD9833 ou Onda de Entrada = A0 (entrada analgica) e um cap entre Aref & GND 28// pino6 ser no utilizavel pois vou ligar o AIN0 tenso interna de referncia de 1.1V como nvel de trigger 29// If you do not use a function generator, connect the PWM output (D5) to the AIN- = pin7 input for trigger. 30// 31 32/* Comandos para o AD9833 inseridos aqui: linhas ~36, ~555 -> no Setup 33// Pins for SPI communication with the AD9833 IC 34#include <SPI.h> 35#include <MD_AD9833.h> 36#define DATA 11 ///< SPI Data pin number 37#define CLK 13 ///< SPI Clock pin number 38#define FSYNC 10 ///< SPI Load pin number (FSYNC in AD9833 usage) 39#define CS_DIGIPOT 9 // MCP41010 chip select - digital potentiometer. Not used in this implementation (use default) 40MD_AD9833 AD(FSYNC); // Hardware SPI = AD9833 41unsigned long fnu; // Frequncia da Onda Senoidal do AD9833 (linha 557) 42*/ 43 44/* Veldekiaan's scope: 45 6-channel oscilloscope 46 47 Operation mode: 48 '#': frequency counter 49 '*': oscilloscope 50 '!': reset 51 52 Trigger modes: 53 'E': rising edge 54 'F': falling edge 55 56 Sweep mode: 57 'C': continuous 58 'D': single sweep 59 60 Time base: 61 100, 200, 500 us 62 1, 2, 5 ms 63 10, 20, 50 ms 64 100, 200, 500 ms 65 1, 2, 5 s 66 10, 20, 50 s 67 100, 200 s 68 69 Timebase is identified by characters 'a'-'t' 70 71 Channel: 72 Channels are selected by '0'-'5' 73 74 Counter time base 75 'G': 1 period, clock divider 1024 76 'H': 1 period, clock divider 256 77 'I': 1 period, clock divider 64 78 'J': 10 periods, clock divider 1024 79 ... 80 'U': 10000 periods, clock divider 64 81*/ 82 83#define ScopeMode '*' 84#define CounterMode '#' 85 86#define InitialMode '*' 87 88// Trigger input pin (only 2 or 3) 89#define TriggerPin 2 // digital trigger still available: but use it or AnalogComparator trigger 90 91#define MaxSamples 1000 92 93// Pin to connect an LED showing counter measuring intervals 94// original: #define CounterPin 13 // => save for programing AD9833 95#define CounterPin 4 96// Pin to generate a PWM signal (5 or 6 only) 97#define PwmPin 5 // com o AnalogComp o pino 6 passa a ser o AIN0 e agora a saida PWM ser no pino5 98#define PwmFreq65k 0x1 // 62.5 kHz = 16MHz/(1=prescaler * 256) 99#define PwmFreq7k 0x2 // 7.8125 kHz = 16MHz/(8=prescaler * 256) 100#define PwmFreq976 0x3 // 976.56 Hz = 16MHz/(64=prescaler * 256) 101#define PwmFreq244 0x4 // 244.14 Hz = 16MHz/(256=prescaler * 256) 102#define PwmFreq061 0x5 // 61.035 Hz = 16MHz/(1024=prescaler * 256) 103 104// Timer and interrupt settings para trigger Externo no Pino 2 105#define INTBIT B00000001 106#define TRIGCLR B00000001 107#define TRIGRISE B00000011 108#define TIMERCTCA B00000000 109#define TIMERCTCB B10001000 110#define TIMERCNTA B00000000 111#define TIMERCNTB B00000000 112#define TIMERNOCLK B11111000 113#define TIMERPS0001 B00000001 // clock do timer = clock do Arduino = 16 MHz 114#define TIMERPS0256 B00000100 115#define TIMERPS1024 B00000101 116#define ADCINIT B10000111 // ADEN=1,enable ADC: isso j resolve o Anal.Comp., ADC=0 No Comea Conversao, ADATE=0 (sem AutoTrigger), ADIF=0, ADIE=0, ADSprescaler=111=128 117// o programa no mexe em ADCSRB, portantos bit ADTS2,1,0 so 000 = free runing (to rpido quanto possvel) 118#define ADCSELECT B01100000 // original: 5V 119// #define ADCSELECT B11100000 // CLC: mudar para 1.1V de referncia (aumenta resoluo p/ ondas de pico <1.1V) 120#define ADCSTART B01000000 121#define ADCPSCLR B11111000 122#define ADCPS002 B00000001 // CLC 123#define ADCPS004 B00000010 // CLC 124#define ADCPS008 B00000011 // CLC 125#define ADCPS016 B00000100 // 76.9 kSps ? Tem que mexer tambm em CNT do trigger do contador 126#define ADCPS032 B00000101 127#define ADCPS064 B00000110 128#define ADCPS128 B00000111 129#define ADCREADY B00010000 130#define CLEARADIF B10101111 // Does not do anything ?- na operao ADCSRA &= CLEARADIF, limpa os bits 6(ADC StartConversion) e 4(ADIntFlag) e mantm os outros do ADCSRA 131 132boolean scope = true; 133 134//The interrupt setting depends on the choice of the trigger pin: 2 (INT0) ou 3(INT1) 135byte intBit = (INTBIT << (TriggerPin == 2 ? 0 : 1)); 136 137// Current mode variables 138boolean continuousSweep = true; 139byte currentChannel = 0; 140char currentBase; 141 142// Sample variables 143volatile byte sample[MaxSamples]; 144byte timerPrescaler; 145int samples; 146volatile int index=0; 147volatile int writeIndex; 148 149// Interleaving variables (for the 100s scale: CLC) 150volatile boolean FlagItlvd = false; // Flag whether to use of not interleaving: only made TRUE at 100s/Div 151volatile int itlvdCnt=0; // CLC = interleaved count=0,1,..,4. Vou usar na amostragem mais rpida: 5 leituras com timedelays 152volatile int itlvdCntMax=5; // CLC = 5 interleaved points 153volatile int tdelay=3; // CLC = interleaving delay in microseconds 154volatile int indexWrt; // CLC 155 156// Frequencey counter current ode variables 157int periodCount; 158volatile int periods = 0; 159volatile unsigned long count; 160volatile byte counterDiv = 5; 161 162// PWM output value ("-" and "+" changes this duty cycle) 163unsigned int pwm = 128; 164 165/* Initialize the Analog-Digital Converter */ 166void initAdc() 167{ 168 ADCSRA = ADCINIT; 169 ADMUX = ADCSELECT; 170} 171 172/* Read a sample from the ADC */ 173void readAdc() 174{ 175 unsigned int result = 0; 176 ADCSRA |= ADCSTART; // Start conversion 177 while ((ADCSRA & ADCREADY) == 0); 178 sample[index*(FlagItlvd ? itlvdCntMax : 1)+itlvdCnt+1] = ADCH; // 8-bit sample size for speed 179 index++; 180// ADCSRA &= CLEARADIF; no faz nada 181} 182 183 184/* Trigger Interrupt Service Routine . Pino 2 INT0 e pino 3 INT1 */ 185#if (TriggerPin == 2) 186ISR(INT0_vect) 187#else 188ISR(INT1_vect) 189#endif 190{ 191 if (scope) 192 { 193 EIMSK &= ~intBit; // Disable trigger interrupt first; (zera o INT1 ou INT0) 194 EIFR |= intBit;// Clear pending interrupts (escreve 1 em EIFR(INTFR1 ou INTF0) e assim limpa) 195 196 readAdc(); // Read first sample immediately 197 TCNT1 = 0; // Reset timer 198 TCCR1B |= timerPrescaler; // Start timer now 199 } 200 else 201 { 202 int c = TCNT1; 203 204 TCNT1 = 0; 205 TCCR1B = counterDiv; // Start counter 206 count += c; // Add current timer to total count 207 periods++; // Another period counted 208 if (periods > periodCount) // If all periods counted for a measurment... 209 { 210 TCCR1B = 0; // ... Stop counter 211 writeCount(count); // Report value to PC 212 counterReset(); // Reset counter for next measurement 213 } 214 } 215} 216/* Trigger with the Analog Comparator - CLC */ 217ISR(ANALOG_COMP_vect) { 218 // ACSR |= (1<<ACI); // clear Analog Comparator interrupt 219 if (scope) 220 { 221// EIMSK &= ~intBit; // Disable trigger interrupt first; (zera o INT1 ou INT0) 222// EIFR |= intBit; // Clear pending interrupts (escreve 1 em EIFR(INTFR1 ou INTF0) e assim limpa) 223 bitClear(ACSR,ACIE); // DISABLE ADC interrupt first = CLC 224 bitSet(ACSR,ACI); // Clear Pending Interrupt = CLC 225 digitalWrite(CounterPin, !digitalRead(CounterPin)); // toggle state of Pin 4 226 delayMicroseconds(tdelay*itlvdCnt); // CLC= delay for interleaving 227 readAdc(); // Read first sample immediately 228 TCNT1 = 0; // Reset timer 229 TCCR1B |= timerPrescaler; // Start timer now 230 } 231} 232 233/* Handle the end of a sweep */ 234void stopSweep() 235{ 236 TCCR1B &= TIMERNOCLK; // Set clock select to 0 (no clock) 237 index++; 238 writeData(); // Write sampled data to serial connection 239 if (continuousSweep) 240 { 241 scopeReset(); // Restart automatically in continuous sweep mode 242 } 243} 244 245/* Reset the scope for a new sweep */ 246void scopeReset() 247{ 248 TCCR1B &= TIMERNOCLK; // Stop the timer by setting clock select to 0 (no clock) 249 250 Serial.print((char) 0xFF); // Mark end of sweep to console 251 index = 0; // Reset sweep data 252 itlvdCnt=0; 253 writeIndex = 0; 254 255 // CLC: faz a 1a converso que demora mais. No guarda os dados 256 ADCSRA |= ADCSTART; // Start conversion 257 while ((ADCSRA & ADCREADY) == 0); // espera terminar 258 259 EIFR |= intBit; // Reset trigger interrupt flag 260 EIMSK |= intBit; // Enable interrupts on trigger input 261 262 bitSet(ACSR,ACI); // Clear Pending Interrupt = CLC 263 bitSet(ACSR,ACIE); // ENABLE ADC again = CLC 264 // Wait for trigger signal interrupt 265} 266 267/* Reset the frequency counter to start another measurement */ 268void counterReset() 269{ 270 digitalWrite(CounterPin, HIGH - digitalRead(CounterPin)); // Toggle indicator LED 271 periods = 0; // Reset counted periods 272 count = 0UL; // Reset total timer counts 273 TCNT1 = 0; // Reset timer 274 EIFR != intBit; 275} 276 277/* Interrupt Service Routine for timer OCR compare match : next sampling reading after the usual time delay */ 278ISR(TIMER1_COMPA_vect) 279{ 280 readAdc(); // Read next ADC sample and store it 281 if (index >= samples) // algo tem que ocorrer se pegou toda a sample dessa vez 282 if ((!FlagItlvd) || (itlvdCnt+1 >= itlvdCntMax)) {stopSweep();} // se no tem interleaving: pegou toda a amostra: STOP 283 else { // seno ... vai pro prximo indice de interleaving 284 itlvdCnt++; 285 TCCR1B &= TIMERNOCLK; // tem que parar o clock interrupt: select to 0 (no clock) 286 index=0; // reseta o indice para interleaved e, reabilita e espera novo triger do ADC: 287 bitSet(ACSR,ACI); // Clear Pending Interrupt = CLC 288 bitSet(ACSR,ACIE); // ENABLE AComp interrupt again = CLC 289 // Serial.print("\ 290 Ix,It="); Serial.print(index); Serial.print(itlvdCnt); // debug 291 } 292 } 293 294/* Set the sample time for the selected time base. 295 * The selection is done with a single character 'a'-'t'. 296*/ 297void setSampleTime(char c) 298{ 299 unsigned int cnt; 300 301 currentBase = c; // Store the time base as current 302 303 ADCSRA &= ADCPSCLR; // Clear prescaler 304 // Set ADC prescaler 305 switch (c) 306 { 307 case 'a': 308 case 'b': 309 case 'c': 310 case 'd': 311 ADCSRA |= ADCPS004; //CLC teste = melhor 312 // ADCSRA |= ADCPS008; //CLC teste 313 // ADCSRA |= ADCPS016; // Original 314 break; 315 case 'e': 316 ADCSRA |= ADCPS032; 317 break; 318 case 'f': 319 ADCSRA |= ADCPS064; 320 break; 321 default: 322 ADCSRA |= ADCPS128; 323 break; 324 } 325 326 // Set #samples 327 switch (c) 328 { 329 case 'a': 330 samples = 95; FlagItlvd=true; // Interleaving somente na escala de 100s/div 331// original samples = 48; 332 break; 333 case 'b': 334 samples = 140; FlagItlvd=false; // 200s/div scale 335// samples = 91; 336 break; 337 case 'c': 338// samples = (50 << (c - 'a')); 339 samples = 350; FlagItlvd=false; // 500s/div scale 340 break; 341 case 'd': 342 case 'e': 343 samples = 400; FlagItlvd=false; 344 break; 345 default: 346 samples = (c >= 'o' ? 1000 : 500); FlagItlvd=false; 347 break; 348 } 349 350 // Set timer prescaler 351 timerPrescaler = (c <= 'j' ? TIMERPS0001 : (c <= 'r' ? TIMERPS0256 : TIMERPS1024)); 352 353 // Set counter max value 354 switch (c) 355 { 356 case 'a': 357 cnt = 240; //240=15*16 para 15s de converso (o interleaved entra de 3 em 3 s, itlvdcnt=0,1,2,3,4). 100s/div 358 break; 359 case 'b': 360 case 'c': 361// cnt = 400; // No TIMERPS001 isso daria 400/(16MHz)=25 s; enquanto a converso deve durar 13,5 ciclos de clock do ADC, o que no Prescaler ADCPS008 daria 7s 362// cnt = 336; // ORIGINAL (CLC) 363 cnt = 240; //240=15*16 para 15s de converso . 200s/div and 500s/div 364 break; 365 case 'd': 366 case 'e': 367 case 'f': 368 case 'g': 369 case 'h': 370 cnt = 400 << (c - 'd'); // No TIMERPS001 isso daria 400/(16MHz)=25 s em c='d'e vai dobrando; 1ms/div=25s, 2ms/div=50s, 5ms/div=100s, 10ms/div=200s, 20ms/div=400s 371 break; 372 case 'i': 373 cnt = 16000; // 1ms 374 break; 375 case 'j': 376 cnt = 32000; // 2ms 377 break; 378 case 'k': 379 cnt = 250; // agora TIMERPS0256 => 250/(16M/256) = 4ms 380 break; 381 case 'l': 382 case 'm': 383 case 'n': 384 cnt = 625 << (c - 'l');// 10ms, 20ms, 40ms 385 break; 386 case 'o': 387 case 'p': 388 case 'q': 389 cnt = 3125 << (c - 'o'); //50ms, 0.1s, 0.2s 390 break; 391 case 's': 392 cnt = 15625; // s(prescaler=1024):1s 393 break; 394 case 'r': 395 case 't': 396 cnt = 31250;// r:0.5s, t(prescaler=1024): 2s 397 break; 398 } 399 OCR1A = cnt; 400} 401 402/* Set trigger mode to falling or rising edge no TriggerPin */ 403void setTriggerMode(char c) 404{ 405 if (c == 'F') 406 { 407 EICRA &= ~(TRIGCLR << (TriggerPin == 2 ? 0 : 2)); 408 bitSet(ACSR,ACIS0); // CLC : Analog Comparator 409 } 410 else 411 { 412 EICRA |= TRIGRISE << (TriggerPin == 2 ? 0 : 2); 413 bitClear(ACSR,ACIS0); // CLC : Analog Comparator 414 } 415} 416 417/* Sweep mode (continuous or single) */ 418void setSweepMode(char c) 419{ 420 continuousSweep = (c == 'C'); // 'C' is continuous, 'S' is single 421} 422 423/* Set the channel '1'-'6' */ 424void setChannel(char c) 425{ 426 currentChannel = (c - '1'); // Internally, channels are 0-5 427 ADMUX &= B11110000; 428 ADMUX |= (currentChannel & 0x7); // Switch the ADC multiplexer to the channel pin 429} 430 431/* Start oscilloscope mode */ 432void setScope() 433{ 434 scope = true; 435 digitalWrite(CounterPin, LOW); // Switch off counter indicator 436 TCCR1A = TIMERCTCA; // Use Timer1 in 'match OCR' mode for sampling 437 TCCR1B = TIMERCTCB; // No clock, so no interrupts yet 438 TIMSK1 |= (1 << OCIE1A); // Enable timer1 compare interrupts 439 execute(currentBase); // Set the time base to the last used 440 scopeReset(); // Restart scope 441} 442 443/* Start frequency counter mode */ 444void setCounter() 445{ 446 scope = false; 447 periodCount = 1; 448 digitalWrite(CounterPin, HIGH); // Switch on counter indicator 449 TCCR1A = TIMERCNTA; // Use Timer1 in normal mode for counting 450 TCCR1B = 0; // Hold timer 451 TIMSK1 &= ~(1 << OCIE1A); // Disable timer1 compare interrupts 452 EIFR |= intBit; 453 EIMSK |= intBit; // Enable external interrupt 454 counterReset(); // Restart frequency counter 455} 456 457/* Set the number of periods to count for determining frequency */ 458void setPeriods(char c) 459{ 460 int s = c - 'G'; 461 int p = s / 3; // Period count 1, 10, 100, 1000 or 10000 462 counterDiv = 5 - (s % 3); // Clock divider 64, 256 or 1024 for accuracy 463 periodCount = 1; 464 for (int per = 0; per < p; per++) 465 { 466 periodCount *= 10; 467 } 468} 469 470/* Handle command characters sent from the console */ 471void execute(char c) 472{ 473 switch (c) 474 { 475 case '!': 476 break; 477 case 'E': 478 case 'F': 479 setTriggerMode(c); 480 break; 481 case 'C': 482 case 'D': 483 setSweepMode(c); 484 break; 485 case '#': 486 setCounter(); 487 break; 488 case '*': 489 setScope(); 490 break; 491 case '-': 492 if (pwm > 0) 493 { 494 pwm--; 495 } 496analogWrite(PwmPin, pwm); 497 break; 498 case '+': 499 if (pwm < 255) 500 { 501 pwm++; 502 } 503 analogWrite(PwmPin, pwm); 504 break; 505 case '<': 506 if ((TCCR0B & 0x07) > 0x02) 507 {TCCR0B = (TCCR0B & 0xF8) | ((TCCR0B & 0x07)-0x1);} 508 break; 509 case '>': 510 if ((TCCR0B & 0x07) < 0x05) 511 {TCCR0B = (TCCR0B & 0xF8) | ((TCCR0B & 0x07)+0x1);} 512 break; 513 default: 514 if (c >= '1' && c <= '6') 515 { 516 setChannel(c); 517 } 518 else if (islower(c)) 519 { 520 setSampleTime(c); 521 } 522 else 523 { 524 setPeriods(c); 525 } 526 break; 527 } 528 if (scope) 529 { 530 scopeReset(); 531 } 532 else 533 { 534 counterReset(); 535 } 536} 537 538/* Send all available samples to the console */ 539void writeData() 540{ if (FlagItlvd) {indexWrt=samples*itlvdCntMax+1;} else {indexWrt=index;} 541 for (writeIndex=1; writeIndex < indexWrt; writeIndex++) 542 { 543 Serial.print((char) sample[writeIndex]); // Original= vai o binrio 544// Serial.print("\ 545"); Serial.print(sample[writeIndex]); // aqui vai o nmero em decimal 546 } 547 Serial.print((char) (0xFF)); // Send all ones to mark end of transmission 548} 549 550/* Writes the count value for the defined number of periods in 4 bytes, LSB first */ 551void writeCount(unsigned long cnt) 552{ 553 unsigned long c = cnt; 554 555 for (int d = 0; d < 4; d++) 556 { 557 Serial.print((char) (c & 0xFF)); 558 c >>= 8; 559 } 560 Serial.print((char) (0xFF)); // Send all ones to mark end of transmission 561} 562 563/* Standard set-up */ 564void setup() 565{ 566 // original: Serial.begin(115200); // Fast serial connection 567 Serial.begin(115200); 568 569/* AD9833:Begin 570 AD.begin(); 571 fnu = 2000UL; // 10000UL = 10kHz 572 AD.setFrequency(MD_AD9833::CHAN_0, fnu); 573// AD9833:End 574*/ 575 pinMode(TriggerPin, INPUT_PULLUP); // The trigger input 576 pinMode(CounterPin, OUTPUT); // The frequency counter indicator LED 577 pinMode(PwmPin, OUTPUT); // A PWM source for testing 578 579 TIMSK0 = 0; // Disbable other timer interrupts 580 TIMSK2 = 0; 581 582 /* mudei d0 2o pro 1o abaixo */ 583 // TCCR0B = (TCCR0B & 0xF8) | PwmFreq7k; 584// TCCR0B = (TCCR0B & 0xF8) | PwmFreq976; // Set pin 5/6 PWM frequency 585 TCCR0B = (TCCR0B & 0xF8) | PwmFreq061; // para as contantes de tempo R+C longas!!! 586 587 // External interrupt for trigger signal (in TrigPin =2) 588 EIMSK &= ~intBit; // Disable trigger interrupt first; (zera o INT1 ou INT0) 589 EIFR |= intBit; // Clear pending interrupts (escreve 1 em EIFR(INTFR1 ou INTF0) e assim limpa) 590 EICRA = TRIGRISE << (TriggerPin == 2 ? 0 : 2); // Start with rising edge 591 592 initAdc(); // Set up the analog inputs and the ADC 593 594 // AnalogComparator: Begin (CLC) 595 // ; AIN0=Bandgap=1.1V 596 pinMode(7, INPUT); 597 DIDR1 = B00000011; // disable digital input to AIN1/0 598/* ACSR = 599 (0 << ACD) | // Analog Comparator: Enabled 600 (1 << ACBG) | // ou no:Analog Comparator Bandgap Select: bandgap 1.1V in AIN0 (positive input) 601 (0 << ACO) | // Analog Comparator Output: OFF 602 (1 << ACI) | // Analog Comparator Interrupt Flag: Clear Pending Interrupt 603 (1 << ACIE) | // Analog Comparator Interrupt: Enabled 604 (0 << ACIC) | // Analog Comparator Input Capture: Disabled 605 (1 << ACIS1) | (0 << ACIS0); // Analog Comparator Interrupt Mode: Comparator Interrupt on Rising Output Edge 606*/ 607ACSR = B01011010; // enable AC, AIN0=1.1V, ACO=off, ClearPendindInt, ACintEnable,ACInputCapt=Disabled, falling edge do comparador=rising edge do meu sinal 608// AnalogComparator: End (CLC) 609 610 // Set the default controls 611 execute('E'); // Rising edge trigger 612 execute('C'); // mudei para Single sweep - Continuous sweep 613 execute('1'); // Channel A0 614 /* mudei de 'h' pra 'd'*/ 615 execute('h'); // 616 execute('G'); // Counter time base at 1x/1024 617 618 execute(InitialMode); // Start in selected initial mode 619 620 analogWrite(PwmPin, pwm); // Switch on PWM signal 621} 622 623/* Standard loop */ 624void loop() 625{ 626 if (Serial.available()) // If a command was sent from the console, ... 627 { 628 execute(Serial.read()); // ...handle it here 629 } 630} 631
Downloadable files
Basic Connections for Oscilloscope measuring RC circuits
Basic Connections for Oscilloscope measuring RC circuits
Basic Connections for Oscilloscope measuring RC circuits
Basic Connections for Oscilloscope measuring RC circuits
Comments
Only logged in users can leave comments
claudiolenz
0 Followers
•0 Projects
Table of contents
Intro
3
0