Arduino and MAX6921

786 views
Skip to first unread message

Gideon Wackers

unread,
Nov 21, 2013, 3:11:51 PM11/21/13
to neoni...@googlegroups.com
Well after all the great help with the hardware part of the arduino I have been looking at the code for my clock. For clarity I thought it would be better to open a new thread just about the software. 

What I want to make is a four digit clock with IV-11 VFD's that simply starts at 12:00 and starts running, no fancy menus or anything. Time will be set with two buttons; Button A increases the hours by 1, Button B increaes the minutes by 1. Pretty simply one would say but after looking at various other peoples code such as:

https://github.com/8163jb/VFD/blob/master/MAX6921_With_RTC/MAX6921_With_RTC.ino
http://www.vonnieda.org/tc18
http://learn.adafruit.com/ice-tube-clock-kit/

I am completely lost. 
I do understand how to create the digit pattern in an effective way such as shown here:http://www.hacktronics.com/Tutorials/arduino-and-7-segment-led.html But when I see other peoples examples, driving the MAX6921 looks like voodoo to me. Can someone give me a hint/tip/example on how to get going with this project?

Adam Jacobs

unread,
Nov 21, 2013, 3:47:33 PM11/21/13
to neoni...@googlegroups.com, gideon....@student.uhasselt.be
Hi Gideon,
  What are you studying at university? We're starting to get to the point where you should be able to start figuring it out. Definitely shouldn't look like voodoo...

Start with the Datasheet:
http://datasheets.maximintegrated.com/en/ds/MAX6921-MAX6931.pdf

The datasheet tells us that the part is SPI (Serial interface), which means it is much easier to talk to than a I2C part. I'm not going to be able to help you with arduino, I've never used one. I always just program the Atmel microcontroller directly and use the part directly without the arduino bootloader/sketches business. To each their own. One of the huge advantages of the Arduino, though, is supposed to be the availability of community libraries to support these parts. I would maybe look a little harder or consider switching components to something that already has a community library written for it. I linked you the code/schematic to my VFD clock which uses a max6921. It's not arduino sketch, it is atmel microcontroller C code. I think that you should be able to figure it out.
Worst case, the arduino sketches are guaranteed to include support for sending a command via SPI.

http://elbastl.sweb.cz/6-digit-VFD.zip
The part of the code that you should be interested in is the part that I cribbed from Limor's IceClock. Specifically, the spi_xfer(), vfd_send(), setdisplay(). Setdisplay will definitely need to be modified to suit your clock, but spi_xfer and vfd_send are the 'voodoo' that you are trying to understand. Look at the schematic in that file to see how SPI parts are electrically connected to the microcontroller.

-Adam
--
You received this message because you are subscribed to the Google Groups "neonixie-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neonixie-l+...@googlegroups.com.
To post to this group, send an email to neoni...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/neonixie-l/a3465b27-72b0-45b2-b897-e36e474609e1%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Gideon Wackers

unread,
Nov 21, 2013, 4:18:02 PM11/21/13
to neoni...@googlegroups.com, gideon....@student.uhasselt.be
Lets put it like this, the only programming I ever do is a bit of LabVIEW. I'm doing a master in Bioelectronics and Nanotechnology but although it says electronics in the name, there is not too much "classic" electronic stuff. It mainly involves biosensor applications and cell membrane potentials which is a completely different branch of electronics. 

That your code is not in the arduino language but Atmel already explains a bit of my confusion. I'm going to take another look at it and maybe a friend of mine who is a lot better at written programming languages can help me a bit. 

Op donderdag 21 november 2013 21:47:33 UTC+1 schreef Adam Jacobs:

Gideon Wackers

unread,
Nov 21, 2013, 5:03:28 PM11/21/13
to neoni...@googlegroups.com
Maybe I should not be doing this kind of thing late in the evening I just noticed the attachment in this thread http://forum.arduino.cc/index.php?topic=159775.0 which gave me a complete piece of code. This made things a lot clearer and I have started "stripping" the code of things I do not need to make things easier. I will also add a RTC because for what they cost it seems like they make things a lot easier. There are still some tiny errors in this piece of code that need fixing but I think that the raw basis is there. 
arduino_6921.ino

David Forbes

unread,
Nov 21, 2013, 5:09:49 PM11/21/13
to neoni...@googlegroups.com
On 11/21/2013 3:03 PM, Gideon Wackers wrote:
> I will
> also add a RTC because for what they cost it seems like they make things a
> lot easier.
>

I have always thought it strange when people do that. After all, the job of a
microcontroller that runs a clock is to keep track of the time and make it show
up on the display. Why add a second chip to keep track of the time when the
micro is perfectly capable of doing that job?

Especially if someone has already written the code for you, unless they did a
bad job of it.
--
David Forbes, Tucson, AZ

Gideon Wackers

unread,
Nov 21, 2013, 5:29:59 PM11/21/13
to neoni...@googlegroups.com, dfo...@dakotacom.net
You mean using the milis function instead of a RTC?

Anyway, this looks like a good basis to me, I'm only missing the part that actually sets the time (I believe). 

Op donderdag 21 november 2013 23:09:49 UTC+1 schreef nixiebunny:

Adam Jacobs

unread,
Nov 21, 2013, 5:34:24 PM11/21/13
to neoni...@googlegroups.com
Ah-ha! Good deal. I was assuming that your were in school studying electronics or microcontrollers, since you were posting to the group from a university address. :)

Well, more and more, I think that electronics & software are extremely useful skill sets for anyone. Well, Electronics, Software & Law. But Law is outside the scope of discussion. :)
We have an employee here at work that joined as an intern (on a lark) during a break from her doctoral studies in biochemistry. She liked it so much that she stayed, changed her pending doctorate into an existing masters and joined the company full-time as a software engineer.

-Adam

Gideon Wackers

unread,
Nov 21, 2013, 5:44:27 PM11/21/13
to neoni...@googlegroups.com
The law starts to apply when someone dies by your electronic contraption ;)

Op donderdag 21 november 2013 23:34:24 UTC+1 schreef Adam Jacobs:

Adam Jacobs

unread,
Nov 21, 2013, 5:47:07 PM11/21/13
to neoni...@googlegroups.com, David Forbes, gideon....@student.uhasselt.be
Hi David,

I used to think it was strange too and always included the clock
functionality in the microcontroller. However, I was always fine-tuning
the accuracy. I believe that someone was posting to this list a little
while back about his own Atmel microcontroller clock-code accuracy issues.

Later, I needed to build a clock that knew what day it was. I started
putting thought into adding that to the microcontroller, how to account
for leap-years, which months have how many days, etc. It was all more
than doable, but I decided to use the opportunity to try using an RTC.
Another driving factor was battery-backup. The RTC I was using (another
from Maxim, can't remember the name but it is a 8-pin DIP) made battery
backup a complete breeze. Real battery backup, a CR2032 or similar, with
a total of months/years of battery life driving the RTC & TCXO.

The RTC I used was I2C and it also provided an opportunity to learn how
to interface with I2C parts. :)
In the future, I'll probably use an RTC when I feel like it, on more
complex clocks that have a smidge of extra space on the board and maybe
could also use some reduction in microcontroller software size.

It is important to note that these builds are strictly for a hobby and
not sale, so 'price is no object' provided that I can sample the parts
for free. An RTC, TCXO and max6921 might total $25-$30 if I was doing
this for sale, so that would be a non-starter. Of course, I've used
those above parts as well as tons of other Maxim IC parts at work on
larger projects. Maxim IC gets their money's worth out of me, I think. :)

-Adam

Gideon Wackers

unread,
Nov 21, 2013, 5:59:25 PM11/21/13
to neoni...@googlegroups.com, David Forbes, gideon....@student.uhasselt.be
Yeah this project is also a bit of a learning project, but time is starting to become scarce so I'll have to have some results (plus code is not exactly my strong point) and really learn later on. 

Anyway, my to do list:

-Find out where time setting is done, and/or add it to my code
-fix the small bugs
-find out whether this is going to work

Adam Jacobs

unread,
Nov 21, 2013, 6:02:34 PM11/21/13
to neoni...@googlegroups.com, gideon....@student.uhasselt.be
Time-setting as well as time-getting and displaying will need to be done
on the Microcontroller.
The RTC relies on receiving an I2C message with the time to set; it
doesn't have any mechanism for connecting buttons or such directly.
'find out whether this is going to work' is probably something that
depends entirely on the amount of interest & time you have. :)
> --
> You received this message because you are subscribed to the Google
> Groups "neonixie-l" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to neonixie-l+...@googlegroups.com.
> To post to this group, send an email to neoni...@googlegroups.com.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/neonixie-l/04711d2c-068d-4535-be09-36e9e60778fe%40googlegroups.com.

Gideon Wackers

unread,
Nov 21, 2013, 6:28:00 PM11/21/13
to neoni...@googlegroups.com, gideon....@student.uhasselt.be
Yeah as I thought, I'll have to add something to the code for setting the time.

And well... Time is short (Christmas), interest is surely present. 

Two worst case scenarios: it is not ready and they receive a IOU a clock coupon instead of a clock or it never gets finished because my programming skills kinda suck. 

doom scenario: things catch fire :P


Op vrijdag 22 november 2013 00:02:34 UTC+1 schreef Adam Jacobs:

Jan Rychter

unread,
Nov 22, 2013, 3:18:57 PM11/22/13
to neoni...@googlegroups.com

On 21 lis 2013, at 23:47, Adam Jacobs <jacob...@gmail.com> wrote:

> I used to think it was strange too and always included the clock functionality in the microcontroller. However, I was always fine-tuning the accuracy. I believe that someone was posting to this list a little while back about his own Atmel microcontroller clock-code accuracy issues.

I had clock accuracy issues with my MSP430-based clock until I remembered to properly set the load capacitance for the 32.768kHz crystal. After changing it to 12pF the clock runs incredibly well.

As for battery backup, the chip detects external power failing and quickly switches into a power-saving mode, where it does pretty much nothing except wake up every second to increase the counter (I use the watchdog timer for that). It also checks the voltage. In this mode, the power consumption is down to single microamps, so a single CR2032 can last for years. It worked better than I expected it to.

I was never fond of external RTC chips because of their prices. I try to design cheaply, I think this approach forces you to design better. And I try to never design in a part that is not available (samples don't cut it). I'll use it only if Farnell or RS stock it. This rules out most Maxim parts, unfortunately, because while often the best fit, they are usually unobtainium.

Exceptions can be made for chips like 74141 or the MAX6921, which can be gotten from eBay.

Going back to the RTC, I think implementing the loops that count seconds, minutes and hours is a really fun experience, the "going to the basics" kind you very rarely get.

--J.

Reply all
Reply to author
Forward
0 new messages