daily pastebin goal
83%
SHARE
TWEET

Untitled

a guest Jun 13th, 2018 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <si5351.h>
  2. #include "Wire.h"
  3.  
  4. Si5351 si5351;
  5.  
  6. uint16_t varicode[] =
  7. {
  8.   0b1010101011000000,  // 0 NUL
  9.   0b1011011011000000,  // 1 SOH
  10.   0b1011101101000000,  // 2 STX
  11.   0b1101110111000000,  // 3 ETX
  12.   0b1011101011000000,  // 4 EOT
  13.   0b1101011111000000,  // 5 ENQ
  14.   0b1011101111000000,  // 6 ACK
  15.   0b1011111101000000,  // 7 BEL
  16.   0b1011111111000000,  // 8 BS
  17.   0b1110111100000000,  // 9 HT
  18.   0b1110100000000000,  // 10 LF
  19.   0b1101101111000000,  // 11 VT
  20.   0b1011011101000000,  // 12 FF
  21.   0b1111100000000000,  // 13 CR
  22.   0b1101110101000000,  // 14 SO
  23.   0b1110101011000000,  // 15 SI
  24.   0b1011110111000000,  // 16 DLE
  25.   0b1011110101000000,  // 17 DC1
  26.   0b1110101101000000,  // 18 DC2
  27.   0b1110101111000000,  // 19 DC3
  28.   0b1101011011000000,  // 20 DC4
  29.   0b1101101011000000,  // 21 NAK
  30.   0b1101101101000000,  // 22 SYN
  31.   0b1101010111000000,  // 23 ETB
  32.   0b1101111011000000,  // 24 CAN
  33.   0b1101111101000000,  // 25 EM
  34.   0b1110110111000000,  // 26 SUB
  35.   0b1101010101000000,  // 27 ESC
  36.   0b1101011101000000,  // 28 FS
  37.   0b1110111011000000,  // 29 GS
  38.   0b1011111011000000,  // 30 RS
  39.   0b1101111111000000,  // 31 US
  40.   0b1000000000000000,  // 32 SP
  41.   0b1111111110000000,  // 33 !
  42.   0b1010111110000000,  // 34 "
  43.   0b1111101010000000,  // 35 #
  44.   0b1110110110000000,  // 36 $
  45.   0b1011010101000000,  // 37 %
  46.   0b1010111011000000,  // 38 &
  47.   0b1011111110000000,  // 39 '
  48.   0b1111101100000000,  // 40 (
  49.   0b1111011100000000,  // 41 )
  50.   0b1011011110000000,  // 42 *
  51.   0b1110111110000000,  // 43 +
  52.   0b1110101000000000,  // 44 ,
  53.   0b1101010000000000,  // 45 -
  54.   0b1010111000000000,  // 46 .
  55.   0b1101011110000000,  // 47 /
  56.   0b1011011100000000,  // 48 0
  57.   0b1011110100000000,  // 49 1
  58.   0b1110110100000000,  // 50 2
  59.   0b1111111100000000,  // 51 3
  60.   0b1011101110000000,  // 52 4
  61.   0b1010110110000000,  // 53 5
  62.   0b1011010110000000,  // 54 6
  63.   0b1101011010000000,  // 55 7
  64.   0b1101010110000000,  // 56 8
  65.   0b1101101110000000,  // 57 9
  66.   0b1111010100000000,  // 58 :
  67.   0b1101111010000000,  // 59 ;
  68.   0b1111011010000000,  // 60 <
  69.   0b1010101000000000,  // 61 =
  70.   0b1110101110000000,  // 62 >
  71.   0b1010101111000000,  // 63 ?
  72.   0b1010111101000000,  // 64 @
  73.   0b1111101000000000,  // 65 A
  74.   0b1110101100000000,  // 66 B
  75.   0b1010110100000000,  // 67 C
  76.   0b1011010100000000,  // 68 D
  77.   0b1110111000000000,  // 69 E
  78.   0b1101101100000000,  // 70 F
  79.   0b1111110100000000,  // 71 G
  80.   0b1010101010000000,  // 72 H
  81.   0b1111111000000000,  // 73 I
  82.   0b1111111010000000,  // 74 J
  83.   0b1011111010000000,  // 75 K
  84.   0b1101011100000000,  // 76 L
  85.   0b1011101100000000,  // 77 M
  86.   0b1101110100000000,  // 78 N
  87.   0b1010101100000000,  // 79 O
  88.   0b1101010100000000,  // 80 P
  89.   0b1110111010000000,  // 81 Q
  90.   0b1010111100000000,  // 82 R
  91.   0b1101111000000000,  // 83 S
  92.   0b1101101000000000,  // 84 T
  93.   0b1010101110000000,  // 85 U
  94.   0b1101101010000000,  // 86 V
  95.   0b1010111010000000,  // 87 W
  96.   0b1011101010000000,  // 88 X
  97.   0b1011110110000000,  // 89 Y
  98.   0b1010101101000000,  // 90 Z
  99.   0b1111101110000000,  // 91 [
  100.   0b1111011110000000,  // 92 backslash
  101.   0b1111110110000000,  // 93 ]
  102.   0b1010111111000000,  // 94 ^
  103.   0b1011011010000000,  // 95 _
  104.   0b1011011111000000,  // 96 `
  105.   0b1011000000000000,  // 97 a
  106.   0b1011111000000000,  // 98 b
  107.   0b1011110000000000,  // 99 c
  108.   0b1011010000000000,  // 100 d
  109.   0b1100000000000000,  // 101 e
  110.   0b1111010000000000,  // 102 f
  111.   0b1011011000000000,  // 103 g
  112.   0b1010110000000000,  // 104 h
  113.   0b1101000000000000,  // 105 i
  114.   0b1111010110000000,  // 106 j
  115.   0b1011111100000000,  // 107 k
  116.   0b1101100000000000,  // 108 l
  117.   0b1110110000000000,  // 109 m
  118.   0b1111000000000000,  // 110 n
  119.   0b1110000000000000,  // 111 o
  120.   0b1111110000000000,  // 112 p
  121.   0b1101111110000000,  // 113 q
  122.   0b1010100000000000,  // 114 r
  123.   0b1011100000000000,  // 115 s
  124.   0b1010000000000000,  // 116 t
  125.   0b1101110000000000,  // 117 u
  126.   0b1111011000000000,  // 118 v
  127.   0b1101011000000000,  // 119 w
  128.   0b1101111100000000,  // 120 x
  129.   0b1011101000000000,  // 121 y
  130.   0b1110101010000000,  // 122 z
  131.   0b1010110111000000,  // 123 {
  132.   0b1101110110000000,  // 124 |
  133.   0b1010110101000000,  // 125 }
  134.   0b1011010111000000,  // 126 ~
  135.   0b1110110101000000   // 127 (del)
  136. };
  137.  
  138. volatile int index = 0;
  139. volatile uint16_t symbol;
  140. volatile int psk_bit = 0;
  141. volatile int zero_count = 0;
  142. volatile int set_vfo = 0;
  143.  
  144.  
  145. uint32_t freq = 14100000UL;
  146. //uint64_t freq = 1410000000ULL;
  147. String mystring = "DE NT7S CN85NM\n";
  148. int psk_bit_prev = 0;
  149. const int baud_rate = 3125;
  150. //const int baud_rate = 6250;
  151. const unsigned long long pll_freq = 87000000000ULL;
  152.  
  153. int led = 13;
  154.  
  155. void setup()
  156. {
  157.   Serial.begin(57600);
  158.  
  159.   // Initialize the Si5351A
  160.   si5351.init(SI5351_CRYSTAL_LOAD_8PF, 0);
  161.  
  162.   delay(10);
  163.  
  164.   uint8_t temp = si5351.si5351_read(16);
  165.   Serial.println(temp, HEX);
  166.   temp = si5351.si5351_read(17);
  167.   Serial.println(temp, HEX);
  168.  
  169.  
  170.   //si5351.set_correction(14);
  171.   si5351.set_correction(-72);
  172.   si5351.si5351_write(187, 0x92);
  173.  
  174.   si5351.set_pll(pll_freq, SI5351_PLLA);
  175.   //si5351.set_pll(pll_freq, SI5351_PLLB);
  176.   si5351.si5351_write(16, 0x80);
  177.   si5351.si5351_write(17, 0x80);
  178.   si5351.si5351_write(18, 0x80);
  179.   si5351.set_ms_source(SI5351_CLK0, SI5351_PLLA);
  180.   si5351.set_ms_source(SI5351_CLK1, SI5351_PLLA);
  181.   si5351.set_ms_source(SI5351_CLK2, SI5351_PLLA);
  182.  
  183.   si5351.set_freq((freq * 100ULL), pll_freq, SI5351_CLK1);
  184.   si5351.set_freq((freq * 100ULL), pll_freq, SI5351_CLK2);
  185.  
  186.   si5351.set_phase(SI5351_CLK0, 0);
  187.   si5351.set_phase(SI5351_CLK1, 0);
  188.   si5351.set_phase(SI5351_CLK2, 0);
  189.  
  190.   //si5351.set_freq((freq * 100ULL), pll_freq, SI5351_CLK0);
  191.   //si5351.set_freq((freq * 100ULL) + (baud_rate / 2), pll_freq, SI5351_CLK1);
  192.   //si5351.set_freq((freq * 100ULL) - (baud_rate / 2), pll_freq, SI5351_CLK2);
  193.  
  194.   si5351.si5351_write(16, 0x0c);
  195.   si5351.si5351_write(17, 0x0c);
  196.   si5351.si5351_write(18, 0x0c);
  197.   si5351.si5351_write(177, 0xAC);
  198.  
  199.   // Load the first varicode symbol from the message
  200.   symbol = varicode[mystring.charAt(index)];
  201.  
  202.   // We'll flash the LED in sync with the PSK modulation
  203.   pinMode(led, OUTPUT);
  204.  
  205.   // Set up Timer1 for interrupts at 31.25 Hz
  206.   cli(); //stop interrupts
  207.   TCCR1A = 0;// set entire TCCR1A register to 0
  208.   TCNT1  = 0;//initialize counter value to 0
  209.   // set compare match register
  210.   if(baud_rate == 3125)
  211.   {
  212.     OCR1A = 7971;// = (16*10^6) / (1*1024) - 1 (must be <65536)
  213.     //OCR1A = 499;// = (16*10^6) / (1*1024) - 1 (must be <65536)
  214.   }
  215.   else if(baud_rate == 6250)
  216.   {
  217.     OCR1A = 250;
  218.   }
  219.   // turn on CTC mode, set CS12 and CS10 bits for 1024 prescaler
  220.   //TCCR1B = (1 << WGM12) | (1 << CS12) | (1 << CS10);
  221.  
  222.   // 64
  223.   TCCR1B = (1 << WGM12) | (1 << CS11) | (1 << CS10);
  224.   // enable timer compare interrupt
  225.   TIMSK1 = (1 << OCIE1A);
  226.   sei(); //allow interrupts
  227. }
  228.  
  229.  
  230. ISR(TIMER1_COMPA_vect)
  231. {
  232.   if(symbol == 0)
  233.   {
  234.     if(zero_count)
  235.     {
  236.       psk_bit = 0;
  237.       zero_count--;
  238.     }
  239.     else
  240.     {;
  241.       index++;
  242.    
  243.       // Reset message pointer to beginning of string if at end
  244.       if(index >= mystring.length())
  245.       {
  246.         index = 0;
  247.       }
  248.      
  249.       symbol = varicode[mystring.charAt(index)];
  250.     }
  251.   }
  252.   else
  253.   {
  254.     if(symbol & 0x8000) // 1 in the MSB position
  255.     {
  256.       psk_bit = 1;
  257.     }
  258.     else // 0 in the MSB position
  259.     {
  260.       psk_bit = 0;
  261.     }
  262.    
  263.     symbol <<= 1;
  264.    
  265.     if(symbol == 0)
  266.     {
  267.       zero_count = 2;
  268.     }
  269.     else
  270.     {
  271.       zero_count = 0;
  272.     }
  273.   }
  274.  
  275.   set_vfo = 1;
  276. }
  277.  
  278. void loop()
  279. {
  280.   if(set_vfo)
  281.   {
  282.     set_vfo = 0;
  283.    
  284.     if(psk_bit)
  285.     {
  286.       if(psk_bit_prev == 0)
  287.       {
  288.         psk_one();
  289.         digitalWrite(led, HIGH);
  290.       }
  291.      
  292.       psk_bit_prev = 1;
  293.     }
  294.     else
  295.     {
  296.       if(psk_bit_prev == 1)
  297.       {
  298.         psk_zero();
  299.         digitalWrite(led, LOW);
  300.       }
  301.      
  302.       psk_bit_prev = 0;
  303.     }
  304.   }
  305. }
  306.  
  307. void psk_zero()
  308. {
  309.   //si5351.si5351_write(165, 0);
  310.   //si5351.si5351_write(166, 0);
  311.   //si5351.pll_reset(SI5351_PLLA);
  312.   //si5351.set_clock_source(SI5351_CLK0, SI5351_CLK_SRC_CLKIN);
  313.   //si5351.set_clock_source(SI5351_CLK1, SI5351_CLK_SRC_MS);
  314.   //si5351.set_clock_source(SI5351_CLK2, SI5351_CLK_SRC_MS);
  315.   si5351.set_freq((freq * 100ULL) + (baud_rate / 2), pll_freq, SI5351_CLK1);
  316.   si5351.set_freq((freq * 100ULL) - (baud_rate / 2), pll_freq, SI5351_CLK2);
  317.   //si5351.set_phase(SI5351_CLK1, 0);
  318.   //si5351.set_phase(SI5351_CLK2, 0);
  319.   //si5351.si5351_write(16, 0x0c);
  320.   //si5351.si5351_write(17, 0x0c);
  321. }
  322.  
  323. void psk_one()
  324. {
  325.   //si5351.set_clock_source(SI5351_CLK0, SI5351_CLK_SRC_CLKIN);
  326.   //si5351.set_clock_source(SI5351_CLK1, SI5351_CLK_SRC_MS0);
  327.   //si5351.set_clock_source(SI5351_CLK2, SI5351_CLK_SRC_MS0);
  328.   //si5351.set_phase(SI5351_CLK1, 0);
  329.   //si5351.set_phase(SI5351_CLK2, 0);
  330.   si5351.set_freq((freq * 100ULL), pll_freq, SI5351_CLK1);
  331.   si5351.set_freq((freq * 100ULL), pll_freq, SI5351_CLK2);
  332.   //si5351.set_phase(SI5351_CLK1, 0);
  333.   //si5351.set_phase(SI5351_CLK2, 0);
  334.   //si5351.si5351_write(16, 0x0c);
  335.   //si5351.si5351_write(17, 0x0c);
  336. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top