bangnaga

Marker Beacon AD9850

Jun 3rd, 2017
120
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. const int  tombol1 = 2; // Pushbutton 1
  4. const int  tombol2 = 3; // Pushbutton 2
  5. const int  tombol3 = 4; // Pushbutton 3
  6.  
  7. int status1 = 0;
  8. int status2 = 0;
  9. int status3 = 0;
  10.  
  11. long f = 0;
  12.  
  13.  
  14.  
  15. #define W_CLK 8       // Pin 8 - connect to AD9850 module word load clock pin (CLK)
  16. #define FQ_UD 9       // Pin 9 - connect to freq update pin (FQ)
  17. #define DATA 10       // Pin 10 - connect to serial data load pin (DATA)
  18. #define RESET 11      // Pin 11 - connect to reset pin (RST).
  19.  
  20.  
  21. #define pulseHigh(pin) {digitalWrite(pin, HIGH); digitalWrite(pin, LOW); }
  22. // transfers a byte, a bit at a time, LSB first to the 9850 via serial DATA line
  23. void tfr_byte(byte data)
  24. {
  25.   for (int i=0; i<8; i++, data>>=1) {
  26.   digitalWrite(DATA, data & 0x01);
  27.   pulseHigh(W_CLK);   //after each bit sent, CLK is pulsed high
  28.   }
  29. }
  30.  
  31.  
  32.  
  33. // frequency calc from datasheet page 8 = <sys clock> * <frequency tuning word>/2^32
  34. void sendFrequency(double frequency) {
  35.   int32_t freq = frequency * 4294967295/125000000;  // note 125 MHz clock on 9850
  36.   for (int b=0; b<4; b++, freq>>=8) {
  37.     tfr_byte(freq & 0xFF);
  38.   }
  39.   tfr_byte(0x000);   // Final control byte, all 0 for 9850 chip
  40.   pulseHigh(FQ_UD);  // Done!  Should see output
  41. }
  42.  
  43. void setup()
  44. {
  45.  
  46.  
  47.      
  48.   // configure arduino data pins for output
  49.   pinMode(FQ_UD, OUTPUT);
  50.   pinMode(W_CLK, OUTPUT);
  51.   pinMode(DATA, OUTPUT);
  52.   pinMode(RESET, OUTPUT);
  53.  
  54.   pulseHigh(RESET);
  55.   pulseHigh(W_CLK);
  56.   pulseHigh(FQ_UD);  // this pulse enables serial mode - Datasheet page 12 figure 10
  57.  
  58.   pinMode(tombol1, INPUT);
  59.   pinMode(tombol2, INPUT);
  60.   pinMode(tombol3, INPUT);
  61.  
  62.   Serial.begin(9600);
  63.  
  64.   sendFrequency(400);  // freq
  65.   delay (5000);
  66.   sendFrequency(1300);  // freq
  67.   delay (5000);
  68.   sendFrequency(3000);  // freq
  69.     delay (5000);
  70. }
  71.  
  72. void loop()
  73. {
  74.  
  75.  status1 = digitalRead(tombol1);
  76.  status2 = digitalRead(tombol2);
  77.  status3 = digitalRead(tombol3);
  78.  
  79.   if (status1 == HIGH) {
  80.       outermarker();
  81.       Serial.println ("Outer Marker");
  82.     } else {
  83.         notone();
  84.   }
  85.   if (status2 == HIGH) {
  86.       midlemarker();
  87.       Serial.println ("Midle Marker");
  88.     } else {
  89.         notone();
  90.   }
  91.   if (status3 == HIGH) {
  92.       innermarker();
  93.       Serial.println ("Inner Marker");
  94.     } else {
  95.         notone();
  96.   }
  97.  
  98.  
  99.  
  100.  
  101.  
  102. }
  103.  
  104.  
  105. void notone(){
  106.   sendFrequency(0);  // freq
  107. }
  108. void outermarker(){
  109.    
  110.     sendFrequency(400);  // freq
  111.    
  112.     delay(500);  
  113.     sendFrequency(0);  // freq
  114.     delay(100);
  115.     sendFrequency(400);  // freq
  116. }
  117.  
  118.  
  119. void midlemarker(){
  120.     sendFrequency(1300);  // freq
  121.     delay(200);  
  122.     sendFrequency(0);  // freq
  123.     delay(100);
  124.     sendFrequency(1300);  // freq
  125.     delay(500);  
  126.  
  127. }
  128. void innermarker(){
  129.     sendFrequency(3000);  // freq
  130.     delay(150);  
  131.     sendFrequency(0);  // freq
  132.     delay(150);
  133. }
RAW Paste Data