Before using the Mini Circuits UFC-6000 RF Frequency Counter in FOLL, we must characterize the system and estimate the type of noise we expect to see it introduce into the system, so that it may be accounted for when building the loop.
Interfacing the Frequency Counter with the Raspberry Pi
To interface the Mini Circuits RF Frequency Counter(FC) Model UFC-6000 with Raspberry Pi on Linux platform it must be communicated with USB-HID code byte programming. Also a User friendly interface is made to control the FC with command lines.
Highlights of the Code(script attached):
The code enables the user to communicate and control different parameters of the FC like:
1)Frequency Range Selection( for the device to read different frequencies, AutoRange is set by default). 2)Sampling Time (The time intervals for which the data will be retrieved) 3)Read Device Status(Whether the device is reading data or not).
Description of the Code:
HID USB Interfacing by sending byte Values.
1)Read The Freq or Range
Reading the Freq is done by reading the 1st and 2nd LCD of the Frequency counter. 1st line containing Range information, 2nd line is the Frequency result.the code should be send is 2
1st byte: 2 The returned 64 byte array is as follows: 1st byte: 2 2nd byte to Byte17 the ascii value of 16 characters of the 1st LCD line Byte18 to Byte33 the ascii value of 16 characters of the 2nd LCD line
2) Set the Range
By default Freq Counter is in "AutoRange" mode.To set the range manually send the code 4
1st byte: 4 2nd byte: the range value. can be any legal range value. for auto range need to be 255. the 64 byte array is: 1st byte: 4
3)Set the Sample Time
By default Freq Counter Sample Time is 1 sec. you can set the sample time from 0.1 sec and up in step of 0.1 sec.To set the Sample Time send the code 3
1st byte: 3 2nd byte: the sample value in sec double 10. for example: to set the sample time to 0.4 sec 2nd byte need to be: 4 the 64 byte array is: 1st byte: 3
These bytes can be changed by changing the values of buffer[0] and buffer[1] in function /*Write to the device*/ in the main program.
The data is written into a .txt file(example attached) and the user can control the recording of data. The frequency data is now be made to talk to EPICS through slow channels. The data from the .txt file can be used for error analysis at different sampling periods.
Solving the Timing Issues of the FC and the Raspberry Pi
Main Problem:
The frequency counter (FC) takes in an analog RF input(signal) and outputs the frequency of the signal(Ranging from 1 MHz- 6000 MHz) in the digital domain (into a processor). The FC samples the data with a given sample rate( user defined) which ranges from 0.1 s to 1 s(faced problems in fixing this initially). For data acquisition, we have been using a Raspberry Pi(as a processor) which is connected to the martian network and can communicate with the computers inside the 40m. The ultimate challenge which I faced( and been knocking my head off from past two-three weeks) is the synchronization of clocks between the Raspberry Pi and the FC i.e the clock which the FC uses to sample and dump data( every 'x' s) and the clock inside the raspberry pi( used in the loop to wait for a particular amount of time the frequency counter takes to dump successive data).
Steps Taken:
To address this problem, first I added an external clock circuit which monitors the Raspberry Pi and the FC to dump and read data at a particular rate(which is equal to the sampling rate of the FC).In detail: http://nodus.ligo.caltech.edu:8080/40m/10129. While doing so, at first the level trigger algorithm was used which means that the external clock frequency was half as that of the reciprocal of the sampling rate and a trigger was seen every time the level shifts from +DC to -DC(of the external square wave). But this did not completely mitigate the issues and there were still few issues on how quickly the ADC reads the signal and R Pi processes it. To minimize these issues completely, an edge trigger algorithm which detects a pos edge(rising) of the clock was used. The clock frequency is now equal to the reciprocal of the sampling rate. This algorithm showed better results and greatly minimized the drift of the sampling time. Psuedo Code(code attached):
open device : FC via USB-HID;
open device : ADC via I2C;
always(for t= recording time):
- read data from ADC(external clock); if pos edge detected:
- read data from FC and store it in a register;
- else read data from ADC;
end
write data stored in the register to a file( can be an Epics channel or a text file);
