{"id":1409,"date":"2015-08-30T21:13:57","date_gmt":"2015-08-31T07:13:57","guid":{"rendered":"http:\/\/blog.familjenjonsson.org\/blog\/?p=1409"},"modified":"2017-02-25T18:34:41","modified_gmt":"2017-02-26T04:34:41","slug":"microsquirting-the-nc30-part-8-the-tachometer","status":"publish","type":"post","link":"https:\/\/blog.familjenjonsson.org\/blog\/2015\/08\/30\/microsquirting-the-nc30-part-8-the-tachometer\/","title":{"rendered":"Microsquirting the NC30, part #8: The tachometer"},"content":{"rendered":"<p>I was feeling pretty good about how things were going when I <a href=\"http:\/\/blog.familjenjonsson.org\/blog\/2015\/08\/30\/microsquirting-the-nc30-part-7-reading-lambda\/\">&#8220;just&#8221; had hooking up the tachometer left<\/a>. That&#8217;s when I ran into an unsolved problem. From looking at the tachometer signal with the oscilloscope, I had determined that it consisted of short, square pulses, 4 per engine revolution. The Microsquirt outputs a tachometer signal, but it outputs one pulse per cylinder per engine <em>cycle<\/em>, i.e. per 2 revolutions. There is no way to configure it to output a higher frequency.<\/p>\n<p>Another problem was that the signal to the tach was 7V, not 12V. And more strangely, if I unplugged the tach itself, the signal stopped even though the engine was still running. I realized this meant the stock ignition box must <em>sink<\/em> an output from the tach. Sure enough, the tach input showed 7V when unplugged.<\/p>\n<p>This meant I could at least test it. While the &#8220;normal&#8221; Microsquirt tach output is a +12V pulsed signal, you can reroute the signal to one of the open-drain outputs. After doing this, the tach did indeed respond but, as suspected, it showed only half the RPM. Luckily the fact that the Microsquirt tach output is a 50\/50 high\/low square wave did not seem to affect how the tach responded to it.<\/p>\n<p>I toyed with the option of building a pulse-doubling circuit, but realized that I have an unused pin in the connector to the wideband controller\/comm box. The Atmega microcontroller that sends the oxygen sensor data to the CAN-bus can easily generate a pulse train with arbitrary frequency using the built-in timers. And it is also possible to request the RPM (or any other piece of data, in fact) over the CAN-bus. This sounds like a perfect solution.<\/p>\n<p>There&#8217;s one small problem, though. The Arduino pins can&#8217;t handle 7V, and they can&#8217;t be switched between low and high-impedance using the timer, so an external MOSFET would be necessary. This was a bit annoying, since it meant the circuit board had to come out of the box&#8230;<\/p>\n<div id=\"attachment_1404\" style=\"width: 610px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/blog.familjenjonsson.org\/blog\/wp-content\/uploads\/2015\/08\/IMG_20150830_194108.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1404\" class=\"size-medium-size wp-image-1404\" src=\"http:\/\/blog.familjenjonsson.org\/blog\/wp-content\/uploads\/2015\/08\/IMG_20150830_194108-600x450.jpg\" alt=\"The formerly professionally-looking circuit board is starting to slum it. I soldered a small MOSFET I had in on hand to ground and the timer output pin, and added a short lead to the drain pin.\" width=\"600\" height=\"450\" srcset=\"https:\/\/blog.familjenjonsson.org\/blog\/wp-content\/uploads\/2015\/08\/IMG_20150830_194108-600x450.jpg 600w, https:\/\/blog.familjenjonsson.org\/blog\/wp-content\/uploads\/2015\/08\/IMG_20150830_194108-150x113.jpg 150w, https:\/\/blog.familjenjonsson.org\/blog\/wp-content\/uploads\/2015\/08\/IMG_20150830_194108-300x225.jpg 300w, https:\/\/blog.familjenjonsson.org\/blog\/wp-content\/uploads\/2015\/08\/IMG_20150830_194108.jpg 1000w, https:\/\/blog.familjenjonsson.org\/blog\/wp-content\/uploads\/2015\/08\/IMG_20150830_194108-730x548.jpg 730w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><p id=\"caption-attachment-1404\" class=\"wp-caption-text\">The formerly professionally-looking circuit board is starting to slum it. I soldered a small MOSFET I had in on hand to ground and the timer output pin, and added a short lead to the drain pin.<\/p><\/div>\n<p>The packaging will have to be done again, but it wasn&#8217;t that big of a deal. I connected a MOSFET to the timer output pin and ground on the circuit board with the Atmega and brought the drain pin out to a lead. When the Arduino pin is high, it&#8217;ll sink the tach voltage, when the pin is low, it&#8217;ll be disconnected. Piece of cake.<\/p>\n<div id=\"attachment_1405\" style=\"width: 610px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/blog.familjenjonsson.org\/blog\/wp-content\/uploads\/2015\/08\/IMG_20150830_194207.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1405\" class=\"size-medium-size wp-image-1405\" src=\"http:\/\/blog.familjenjonsson.org\/blog\/wp-content\/uploads\/2015\/08\/IMG_20150830_194207-600x450.jpg\" alt=\"The other end of the lead connects to the unused pin on the Ampseal connector. Not too bad, this is what happens when you work with prototypes...\" width=\"600\" height=\"450\" srcset=\"https:\/\/blog.familjenjonsson.org\/blog\/wp-content\/uploads\/2015\/08\/IMG_20150830_194207-600x450.jpg 600w, https:\/\/blog.familjenjonsson.org\/blog\/wp-content\/uploads\/2015\/08\/IMG_20150830_194207-150x113.jpg 150w, https:\/\/blog.familjenjonsson.org\/blog\/wp-content\/uploads\/2015\/08\/IMG_20150830_194207-300x225.jpg 300w, https:\/\/blog.familjenjonsson.org\/blog\/wp-content\/uploads\/2015\/08\/IMG_20150830_194207.jpg 1000w, https:\/\/blog.familjenjonsson.org\/blog\/wp-content\/uploads\/2015\/08\/IMG_20150830_194207-730x548.jpg 730w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><p id=\"caption-attachment-1405\" class=\"wp-caption-text\">The other end of the lead connects to the unused pin on the Ampseal connector. Not too bad, this is what happens when you work with prototypes&#8230;<\/p><\/div>\n<p>With the hardware worked out, I had to improve the software on the Atmega a bit. The Megasquirt CAN-bus protocol description at\u00a0<a href=\"http:\/\/www.msextra.com\/manuals\/\">http:\/\/www.msextra.com\/manuals\/<\/a>\u00a0details the different messages and how to send a request to the Microsquirt to respond with the RPM. Amazingly, it worked (almost) right away!<\/p>\n<p>With the RPM in hand, it was not a big deal to set up Timer1 on the Atmega such that it toggles the output pin every time it reaches the set limit, and calculate what that limit should be for a given RPM. I had some glitches in the tach response until I realized that I should only change the timer limit from the interrupt that fires when the timer hits the limit. This prevents a scenario where, if you are setting a lower timer limit, the timer may already have ticked past the new limit and must then overflow the 16-bit register and wrap around before it hits the limit again.<\/p>\n<p>I also noticed that the tach is noticeably nonlinear. It starts out showing about 500RPM less than the input frequency just above idle but by the time you get to 10,000RPM, it&#8217;s showing almost 1000RPM too much. That&#8217;s not a big deal, I fit a second order polynomial correction to &#8220;correct&#8221; the output frequency. I also discovered that the tach has noticeable hysteresis; the displayed RPM for, say, 7000RPM is quite different depending on whether you approach it from below or above. I guess this means that there&#8217;s some friction in the mechanism. It&#8217;s only maybe 400RPM, though. Not a huge deal.<\/p>\n<p>So that&#8217;s where we&#8217;re at now. I&#8217;m pretty happy with the progress over the weekend. I still have to package the circuit board and the wideband controllers back into the enclosure and run the tach wire, but then I think it might finally be time to put\u00a0it back together (at least the important parts like the gas tank) and go for a ride to see what happens with the engine under load.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was feeling pretty good about how things were going when I &#8220;just&#8221; had hooking up the tachometer left. That&#8217;s when I ran into an unsolved problem. From looking at the tachometer signal with the oscilloscope, I had determined that it consisted of short, square pulses, 4 per engine revolution. The Microsquirt outputs a tachometer &#8230;<\/p>\n<p><a href=\"https:\/\/blog.familjenjonsson.org\/blog\/2015\/08\/30\/microsquirting-the-nc30-part-8-the-tachometer\/\" class=\"more-link\">Continue reading &lsquo;Microsquirting the NC30, part #8: The tachometer&rsquo; &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[4,29],"tags":[11,13,15],"class_list":["post-1409","post","type-post","status-publish","format-standard","hentry","category-motorcycle","category-nc30","tag-electronics","tag-motorcycles","tag-nc30"],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/blog.familjenjonsson.org\/blog\/wp-json\/wp\/v2\/posts\/1409","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.familjenjonsson.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.familjenjonsson.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.familjenjonsson.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.familjenjonsson.org\/blog\/wp-json\/wp\/v2\/comments?post=1409"}],"version-history":[{"count":7,"href":"https:\/\/blog.familjenjonsson.org\/blog\/wp-json\/wp\/v2\/posts\/1409\/revisions"}],"predecessor-version":[{"id":1416,"href":"https:\/\/blog.familjenjonsson.org\/blog\/wp-json\/wp\/v2\/posts\/1409\/revisions\/1416"}],"wp:attachment":[{"href":"https:\/\/blog.familjenjonsson.org\/blog\/wp-json\/wp\/v2\/media?parent=1409"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.familjenjonsson.org\/blog\/wp-json\/wp\/v2\/categories?post=1409"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.familjenjonsson.org\/blog\/wp-json\/wp\/v2\/tags?post=1409"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}