You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

204 lines
9.3 KiB

4 years ago
  1. \documentclass[11pt]{article}
  2. %Gummi|065|=)
  3. \usepackage{graphicx}
  4. \usepackage{caption}
  5. \usepackage{xcolor}
  6. \usepackage[vcentering,dvips]{geometry}
  7. \geometry{papersize={6in,9in},total={4.5in,6.8in}}
  8. \title{\textbf{}}
  9. \author{Steak Electronics}
  10. \date{}
  11. \begin{document}
  12. %\maketitle
  13. \tableofcontents
  14. \textcolor{green!60!blue!70}{
  15. \section{60Hz Divider}}
  16. \subsection{Overview}
  17. Let's count. There is a schematic in Practical Electronics For Beginners 4th edition. I've built that up, and will add some CPLD counter logic, along with a micro to output the SPI to a 7seg counter module.
  18. The goal is relative accuracy. Not absolute. No GPS here. I'm going from 60 to 6,000 cycles.\footnote{Due to limitations of CPLD} This is just meant to be fun.
  19. \begin{center}
  20. \includegraphics[scale=0.15]{../pics/DSCN2964.JPG}
  21. \captionof{figure}{60 Hz Logic Divider to 1Hz}
  22. \end{center}
  23. \subsection{Initial Notes: Counting the Hz}
  24. pseudo code goal:
  25. \begin{verbatim}
  26. Using 1Hz signal
  27. Start counting 1MHz every 1Hz
  28. when next cycle is received,
  29. display count
  30. start counting again
  31. \end{verbatim}
  32. That's all the objective is here. Easy with a micro, but goal is to complete using cmos or 74 logic.
  33. 4553 x 5
  34. 74hct132
  35. 1MHz clock (or 6MHz clock), or some variation thereof
  36. jk flip flop
  37. 74376 - quad jk flip flop
  38. 7476 - jk flip flop
  39. 1mhz clk will be main counter,
  40. 6 hz or 1 hz will be latch / reset
  41. I ended up skipping the 74 CMOS, in favor of a CPLD. Practical Electronics also mentions this approach as favored. Even a micro alone could be used. Schematic entry in the CPLD could also be used.
  42. \subsection{MAX7219 8 digit 7 LED segment Display Driver}
  43. Basic code tested with this was the LedControl arduino library.
  44. \begin{verbatim}
  45. /*
  46. Now we need a LedControl to work with.
  47. ***** These pin numbers will probably not work with your hardware *****
  48. pin 12 is connected to the DataIn
  49. pin 11 is connected to the CLK
  50. pin 10 is connected to LOAD
  51. We have only a single MAX72XX.
  52. */
  53. \end{verbatim}
  54. Some of the lines have to be edited to allow for all digits to be read, and
  55. also to lower intensity of display. I think also a component package (dark
  56. grey clear plastic bag) in front of the leds with intensity 1 is about right.
  57. \subsection{CPLD Programming}
  58. Using the XC9500XL series. This chip has some limitations - which are good.
  59. As you get faster clocks, you need bigger registers to handle parsing the clocks. Bigger registers, use more power. Maybe this is one reason why high clock speeds mean more power.
  60. \subsubsection{6KHz clock}
  61. Due to limitations on the XC9500XL FPGA logic blocks, I ended up limiting the counter registers to 12+1 bits\footnote{Possibly I could use multiple smaller registers in a type of cascade, but let's not bother with that for now. I had 600KHz resolution, until I added the UART out/}, so I have around 6,000 (assuming 60Hz), resolution. With this, I need a 6KHz clock. I could do this with the uno, but let's throw an attiny in there because it's a good tool for this kind of purpose and resolution. It should be able to function as a rough 6KHz timer, easily.
  62. \subsubsection{UART output}
  63. I set the CPLD to use the rising edge of the 6KHz clock and to shift the counter value out... Unsuprisingly, the baud rate is 6000. I found this by using my Open Bench Logic Sniffer\footnote{Phantom 3 in Repairs 2019}. It's fairly quick to configure and get working. Auto detected the UART speed easy.
  64. However, my uart value is 12 - 14 bits, and with uart being an 8 bit protocol, it makes this unconventional. May need to bit bang something. But before that...
  65. \subsection{Divide by N Counters}
  66. \begin{center}
  67. \includegraphics[scale=0.2]{../pics/DSCN2958.JPG}
  68. \captionof{figure}{This divide by 6 counter, appears to not line up with what the TTL Cookbook has for a similar 7490 one.}
  69. \end{center}
  70. The schematics appear to be incorrect for the divide by 6 counter in the Practical Electronics for Beginners book. Having looked at my built up circuit carefully, I see a 20Hz output from the 60Hz. I managed to get my hands on a copy of the TTL Cookbook by Don Lancaster recently, and that details correct divide by 6 and 10 counters (which are different from what's on my proto board), and while I could fix the divide by 6 counter, instead, I'm going to build another divide by 2 counter, and leave the original incorrect one there as a warning (it's also easier to just build a new one).
  71. As it is, I'm getting 2Hz output on the pulse pin... Oops. Practical Untested Electronics for Beginners. Hax. Everything in life is hax. The earlier you realize that, the better you will feel about your own work.\footnote{It's possible they put the error in on purpose. It's really hard to tell...}
  72. \subsection{Attiny 6KHz Clock}
  73. A small victory here: I setup an Attiny10 with an external oscillator (programmable CMOS, not Quartz) of 1.536MHz. I then set prescaler at 256 to get
  74. 6000. Set micro fuse to enable CKOUT pin, and now I have a 6KHz clock from the 20 cent micro plus. Neat usage of the attiny10 here, thanks
  75. to my other project using it. The CPLD works with it, no problem.
  76. \subsection{Parsing of CPLD UART Stream}
  77. Back to the 14 bit stream...
  78. I have the UART stream feeding into the Atmega328/Uno. For the code, I was unsure how to handle it at first, but then I realized a simple shift in would fit.
  79. \textbf{Situation:} I have a serial UART stream at 6000 baud from the CPLD. However, it's not exactly UART. In fact, it has values of 6000, which are over 8 bit. So I have a 14 bit serial stream. There is no stop bit after the 8 bits, and no two 8 bit bytes. So hardware serial will not work. \footnote{I didn't want to deal with coding the UART into the CPLD. There are also size limitations.}
  80. \textbf{Solution:} I have a serial 14 bit stream at 6000 baud. The answer is to tie the 6000 Hz CLK to a pin on the Uno, and implement a shift in, so that every clock up, the value is read on the Serial / 14 bit pin. I do have a start bit, and I am not outputting all the time, so this will be one 14 bit value every second.
  81. \textbf{Problems:} The Uno's digitalRead timing is not 100\% As a result, some values are being read incorrectly. 5996 shows up as 5048 or similar. I need to go back and access the Input direct via register reads to speed things up. A Pin register access similar to:
  82. \begin{verbatim}
  83. Example Code Snippet
  84. Let's demonstrate the use of the DDRx,
  85. PORTx and PINx registers from the
  86. following code snippet:
  87. DDRC = 0x0F;
  88. PORTC = 0x0C;
  89. // lets assume a 4V supply comes to PORTC.6 and Vcc = 5V
  90. if (PINC == 0b01000000)
  91. PORTC = 0x0B;
  92. else
  93. PORTC = 0x00;
  94. \end{verbatim}
  95. Reference: http://maxembedded.com/2011/06/port-operations-in-avr/
  96. may fix these issues. In the meantime, because the errors are consistent, I setup some LUTs\footnote{Lookup tables, i.e. hard coded fixes. e.g. 5048 now converts to 5996.}.
  97. \subsection{Max7219 8 digit 7-Segment Display via Uno}
  98. I didn't have any trouble getting the 7 segment to display with the Uno and the Max7219. Note that I avoided outputting the values via the CPLD. The Uno is just quicker to code this output. I used the LedControl library. I had to adopt a quick function to break down the values. The Max7219 does not take in variables, so instead, you feed it single digits. Therefore I needed to extract a single digit from the tens, hundreds, and thousands. See below:
  99. \begin{verbatim}
  100. //https://playground.arduino.cc/Main/LedControl/#Seg7Control
  101. void printNumber(int v) {
  102. int ones;
  103. int tens;
  104. int hundreds;
  105. int thousands;
  106. boolean negative;
  107. if(v < -9999 || v > 9999)
  108. return;
  109. if(v<0) {
  110. negative=true;
  111. v=v*-1;
  112. }
  113. ones=v%10;
  114. v=v/10;
  115. tens=v%10;
  116. v=v/10;
  117. hundreds=v%10;
  118. v=v/10;
  119. thousands=v;
  120. /*if(negative) {
  121. //print character '-' in the leftmost column
  122. lc.setChar(0,4,'-',false);
  123. }
  124. else {
  125. //print a blank in the sign column
  126. lc.setChar(0,4,' ',false);
  127. }*/
  128. //Now print the number digit by digit
  129. lc.setDigit(0,3,(byte)thousands,false);
  130. lc.setDigit(0,2,(byte)hundreds,false);
  131. lc.setDigit(0,1,(byte)tens,false);
  132. lc.setDigit(0,0,(byte)ones,false);
  133. }
  134. \end{verbatim}
  135. Note that I commented out the negative sign on this. My values are always positive.
  136. \includegraphics[scale=0.30]{../pics/DSCN0170.JPG}
  137. \captionof{figure}{Rev A. 60Hz to 4 digits, is updated once per second.}
  138. \subsection{Project Rev A Complete}
  139. With the above complete, I have an initial prototype. The issues with this are the following:
  140. \begin{itemize}
  141. \item Uno reads 14 bit serial stream wrong (timing issues)
  142. \item 7 segment display slightly bright
  143. \item Should add readout of 120 Volts (can get from transformer)
  144. \item Plywood should be replaced with fiberglass
  145. \end{itemize}
  146. It turns out that 4 digits on the display is the minimum for a project like this to be viable. 3 digits wouldn't be enough resolution, and 5 digits is not necessary (although nice). The values differ here from about 5996 to 6003 cycles per second.
  147. Other than that, it is working, and will be setup and watched for a bit to enjoy the readout.
  148. \subsection{Related:}
  149. \begin{itemize}
  150. \item https://shepherdingelectrons.blogspot.com/2020/07/uart-transceiver-for-breadboard-computer.html
  151. \end{itemize}
  152. This guide shows a UART created in TTL 74 logic. What's relevant to this project, is how he managed syncing the clocks.
  153. %todo insert picture
  154. \end{document}