Advertisement
Guest User

Waveform

a guest
Nov 7th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "Waveforms.h"
  2.  
  3. #define oneHzSample 1000000/maxSamplesNum  // sample for the 1Hz signal expressed in microseconds
  4.  
  5.  
  6. int i = 0;
  7. int sample;
  8.  
  9.  
  10. void setup() {
  11.   analogWriteResolution(12);  // set the analog output resolution to 12 bit (4096 levels)
  12.   analogReadResolution(12);   // set the analog input resolution to 12 bit
  13.  
  14. }
  15.  
  16. void loop() {
  17.   // Read the the potentiometer and map the value  between the maximum and the minimum sample available
  18.   // 1 Hz is the minimum freq for the complete wave
  19.   // 170 Hz is the maximum freq for the complete wave. Measured considering the loop and the analogRead() time
  20.   sample = map(analogRead(A0), 0, 4095, 0, oneHzSample);
  21.   sample = constrain(t_sample, 0, oneHzSample);
  22.  
  23.   analogWrite(DAC0, waveformsTable[0][i]);  // write the selected waveform on DAC0
  24.   analogWrite(DAC1, waveformsTable[0][i]);  // write the selected waveform on DAC1
  25.  
  26.   i++;
  27.   if(i == maxSamplesNum)  // Reset the counter to repeat the wave
  28.     i = 0;
  29.  
  30.   delayMicroseconds(sample);  // Hold the sample value for the sample time
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement