Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include <math.h>
  2. #include <DueTimer.h>
  3. int r;
  4. float Fs = 10000;
  5. float out = 0;
  6.  
  7. const float BL = 11;
  8. float X[11] = {
  9. 0, 0, 0, 0,
  10. 0, 0, 0, 0,
  11. 0, 0, 0
  12. };
  13. const float B[11] = {
  14. 0.02285587755007, 0.01644493311478, -0.1103146181308, -0.1996653808026,
  15. 0.1052876191363, 0.3774952159645, 0.1052876191363, -0.1996653808026,
  16. -0.1103146181308, 0.01644493311478, 0.02285587755007
  17. };
  18.  
  19. void timerInterrupt(void)
  20. {
  21. X[0] = analogRead(A0);
  22. out = 0;
  23.  
  24. for(int i = 0; i < BL; i++)
  25. {
  26. out += X[i] * B[i];
  27. }
  28.  
  29. X[10] = X[9];
  30.  
  31. for(int i = (BL - 1); i > 0; i--)
  32. {
  33. X[i] = X[i - 1];
  34. }
  35.  
  36. analogWrite(DAC1, out + 1000);
  37. }
  38. void setup() {
  39. analogReadResolution(12);
  40. analogWriteResolution(12);
  41. pinMode(A0,INPUT);
  42. Timer3.attachInterrupt(timerInterrupt);
  43. Timer3.start(100); //10khz sampling
  44. }
  45.  
  46. void loop() {
  47. r++; //do something useless
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement