Esempio n. 1
0
        public void WritePhase(int channel, double frequency, double phase)
        {
            /*
             * // Address
             * byte mae = (byte)(channel >> 4);
             * byte ato = (byte)((channel - (mae << 4)) << 4);
             * var address = new byte[] {0x40, 0x00, mae, ato};
             * // Phase offset
             * var phase_offset = (long)((phase / 360.0) * width_factor);
             * var poff_bytes = System.BitConverter.GetBytes(phase_offset).Take(4).ToList();
             * // Phase increment
             * var phase_increment = (long)(frequency % Program.ADCSampleRate / Program.ADCSampleRate * width_factor);
             * var pinc_bytes = System.BitConverter.GetBytes(phase_increment).Take(4).ToList();
             */
            short towrite = (short)(4 * (channel) + 1);
            var   address = new List <byte> {
                0x40, 0x00
            };

            address.AddRange(BitConverter.GetBytes(towrite).Reverse());
            // Write
            var target_freq = frequency > 0 ? frequency : (frequency % Program.ADCSampleRate) + Program.ADCSampleRate;

            Console.WriteLine("DEBUG freq: {0} Hz", target_freq);
            var phase_increment = (long)(target_freq / Program.ADCSampleRate * width_factor);

            Console.WriteLine("DEBUG pinc: {0}", phase_increment);
            var pinc_bytes = System.BitConverter.GetBytes(phase_increment).Take(4).ToList();

            pinc_bytes.Reverse();
            Console.WriteLine("DEBUG pinc bytes: {0}", BitConverter.ToString(pinc_bytes.ToArray()));


            var wr_data     = pinc_bytes.ToArray();
            var ret_data    = _rbcp.Write(address.ToArray(), wr_data);
            var intprt_data = RBCP.Interpret(ret_data);

            if (!address.SequenceEqual(intprt_data.Item1) ||
                !wr_data.SequenceEqual(intprt_data.Item2))
            {
                throw new Exception("Wrote <-> Read do not match");
            }
            _rbcp.Write(new byte[] { 0x70, 0, 0, 0 }, new byte[] { 0x01 });
        }
Esempio n. 2
0
 public void DAC_4ena()
 {
     _rbcp.Write(DACAddress(0x17), new byte[] { 0x04 });
 }
Esempio n. 3
0
 public void ToggleSnap(bool on)
 {
     byte[] snap_switch_addr = { 0x30, 0x00, 0x00, 0x00 };
     _rbcp.Write(snap_switch_addr, new byte[] { Convert.ToByte(on) });
 }
Esempio n. 4
0
 public void SetRate(int rate_num)
 {
     byte[] ds_addr = { 0x61, 0x00, 0x00, 0x00 };
     _rbcp.Write(ds_addr, BitConverter.GetBytes(rate_num).Reverse().ToArray());
 }
Esempio n. 5
0
 public void ADCReset()
 {
     _rbcp.Write(ADCAddress(0x00), new byte[] { 0x02 });
     ADCWriteEnabled = true;
     ADCChannelSwap(false);
 }