• API
• FAQ
• Tools
• Archive
SHARE
TWEET

a guest May 1st, 2019 112 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #InnovateFPGA 2019
2. #Team Number: EM002
3. #Project Name: Successive-approximation-memory (SAM) analog-to-digital converter (ADC)
4. # http://www.innovatefpga.com/cgi-bin/innovate/teams.pl?Id=EM002
5.
6. clear all;
7.
8. F_SAMPLES = 0.6250 # 625 MHz
9. F_SAMPLES_DAC = F_SAMPLES/4 # 156.25 MHz
10. F_SQUAREWAVE_INPUT = 0.1485 # 148.5 MHz
11.
12. function y = SquareWave(F,x)
13.   #y = 1.5 + (sin(2 * pi * F * x) > 0) * 2 - 1.0;
14.   y = 1.5 + sin(2 * pi * F * x);
15. endfunction
16.
17. function y = Samples(F,x)
18.   y = (abs(x/(1/F) - round(x/(1/F))) < 0.1) * 0.6 - 0.2;
19. endfunction
20.
21. f_width = 700;
22. f_height = 150;
23.
24. h = figure('position',[100,100,f_width,f_height]);
26.
27. xSTEP = 1/F_SAMPLES/20;
28. xNUM = 4000;
29. xMAX = xSTEP * xNUM;
30.
31. x2STEP = 1/F_SAMPLES_DAC;
32. x2NUM = xMAX / x2STEP;
33.
34. iterNUM = 7;
35.
36. x = 0:xSTEP:xMAX;
37. SignalIN = SquareWave(F_SQUAREWAVE_INPUT,x); #only for plot
38. SamplesIN = Samples(F_SAMPLES_DAC,x); #only for plot
39.
40. x2 = 0:x2STEP:xMAX;
41. Signal2IN = SquareWave(F_SQUAREWAVE_INPUT,x2);
42. ComparatorOUT = ones(1, x2NUM + 1);
43. ApproximationLogicOUT = zeros(1, x2NUM + 1);
44. DACOUT = zeros(1, x2NUM + 1);
45.
46. for n = 1:1:iterNUM
47.   DACOUT = ApproximationLogicOUT;
48.   ComparatorOUT = (Signal2IN - DACOUT > 0.0) * 2 - 1;
49.   ApproximationLogicOUT = ApproximationLogicOUT + (ComparatorOUT * 3 / (2^n));
50.   plot(x,SignalIN,";Signal input 148.5MHz;",...
51.        x,SamplesIN,":;Samples 156.25MHz;",...
52.        x2,DACOUT,";DAC output;");
53.        #x,ComparatorOUT * 0.3,";Comparator result;");
54.   axis([0, xMAX, -0.4, 3]);
55.   drawnow;
56.   # Capture the plot as an image
57.   frame = getframe(h,[1,1,f_width-1,f_height-3]);
58.   im = frame2im(frame);
59.   [imind,cm] = rgb2ind(im);
60.   # Write to the GIF File
61.   if n == 1
62.     imwrite(imind,cm,filename,'gif','WriteMode','overwrite','Loopcount',inf,'DelayTime',1.5);
63.   elseif n == iterNUM
64.     imwrite(imind,cm,filename,'gif','WriteMode','append','DelayTime',6.5);
65.   else
66.     imwrite(imind,cm,filename,'gif','WriteMode','append','DelayTime',1.5);
67.   endif
68. end
69. delete(h);
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.

Top