MAX696x Library

For a while now I have also been playing around with the Maxim Semiconductor MAX6960 LED matrix controller IC. This is a device capable of driving 2 mono 88 LED matrices or 1x RGY LED matrix and can be cascaded up to 256 devices in a row. This gives a relatively simple method for developing large LED matrix displays which can be controlled by a simple microcontroller over a SPI serial interface.

The result of this experimentation is a library for interfacing to the MAX696x family of devices using Arduino. The MAX6960 family also includes the MAX6961, MAX6962 and MAX6963 which have small differences in capability and should be compatible with this driver.

It should be noted before going much further that embedded software design is highly dependent on the requirements of the final hardware and is often tightly coupled to the hardware, meaning the software sometimes can’t be easily ported from one application to another. That said, the Arduino Library I have written should be fairly portable to other LED matrix display designs using an Arduino as a controller.

If you use this library I cannot stress highly enough that you must read the data sheet for the MAX696x family to fully understand the implications of your hardware design, the way the devices are being configured and the limitations these may place on the display in terms of display frame rate, update speed, Arduino memory utilisation.

Features

The MAX696x library for Arduino has the following features:

  • Configurable to use the ATmega168 hardware SPI bus (default) or any other Digital I/O pins on the Arduino board.
  • Configurable for using any MAX696x clock from 1.0Mhz to 8.5Mhz.
  • Configurable frame rate, dependent on MAX696x clock speed, from 1/63 fps to 63 fps for nominal clock of 4.194303MHz.
  • Supports up to 256 cascaded MAX696x devices any matrix orientation to make the display
  • Supports all the commands and all 8-bit, 16-bit and 24-bit addressing methods of the MAX696x family.
  • Supports automatic or manual control of frame switching and multiple display memory planes.
  • Supports 2-bit per pixel modes in MAX696x devices that offer it.
  • Supports direct discrete read/write access to display memory data (slow) as well as using ATmega168 memory to build an image of the next frame of display data which is then dumped into the display memory (fast).
  • Includes a simple, optional character set.
  • Configurable to output debug information from the library to the Arduino IDE serial terminal. This requires a recompile to turn on and off.

Limitiations

The limitations of the library are mainly those imposed by the MAX696x and ATmega168 devices themselves:

  • At this stage the library only supports one instance of the driver, that is, there can only be one chain of MAX696x devices connected to the Arduino and it hasn’t been tested with other devices on the same SPI bus, but using a different SS pin.
  • Up to 256 MAX696x devices can be daisy chained to make a display however the 1k memory limitation of the ATmega168 restricts this in practice to using direct discrete read/write access to display memory data which is slower and can effect the maximum achievable frame rate.
  • The maximum frame rate of the display is also dependent on the clock source used in the display but the useful maximum frame rate is ultimately limited by the time it takes for the ATmega168 can update the total number of MAX696x devices in the display with new data in.
  • The mapping of the display memory addresses to actual pixel positions is dependent on the user application, the type of LED matrix being used (ie, mono, RGY etc) and the arrangement of the LED matrices to make the display.
  • Does not directly support RGB display applications but they could be seen as an extension to 3 instances of the MAX696x driver – but this isn’t supported by the library right now.
  • Not yet interrupt driven. The plan is to make the library interrupt driven so the main loop won’t have to wait on detecting the IRQ pin going low.

Download the Library
The library can be downloaded here : MAX696X Library for Arduino

Installation Instructions
Exit the Arduino program, unzip the library and copy the max696x folder to the libraries folder under your Arduino install directory, eg for OS X: /Applications/arduino/hardware/libraries, then restart Arduino.

Usage Instructions
The max696x library needs to be configured to match your display hardware before you can use it. Many of the variables it uses are compiled into the code rather than configured at run time to conserve RAM.

Setup
The max696x_conf.h file is where all the settings need to be made to suit your display. This file needs to be edited before the library is compiled, the file itself contains instructions on how to change the settings for your display. Here’s a general run down of the process.

  1. Open the max696x_conf.h file
  2. Set MAX696x_DEBUG to (1) to enable debugging information from the library or to (0) to disable debug information. Including debugging output increases the code size and RAM usage.
  3. Set MAX696x_USE_HW_SPI to (1) use the hardware SPI and associated pins (10 through 13) or to (0) to define your own pins and emulate the SPI in software. Hardware SPI is faster.
  4. Set DATAOUT, DATAIN, SPICLOCK and SLAVESELECT pins if you’ve set MAX696x_USE_HW_SPI to (0)
  5. Set RESET and INTERRUPT pins to suit your design
  6. Also set the associated PORT and BIT assignments to match those pin allocations
  7. Set NUMBER_OF_DRIVER_DEVICES to match the number of MAX696x devices daisy chained in your display.
  8. Set NUMBER_OF_DRIVERS_PER_ROW to the number of drivers that drive LEDs each row of your display, eg four 88 LED modules arranged in a 22 grid driven by 2x MAX6960s will have a NUMBER_OF_DRIVERS_PER_ROW set to 1
  9. Set MAX696x_OSC_FREQ to the frequency of the clock driving the MAX696x ICs. This number is in hertz, eg 4MHz -> 4000000.
  10. Set FRAME_AUTO to (1) to enable automatic display memory frame switching or to (0) enable manual switching.
  11. Set FRAME_SPEED to (1) if you’ve set FRAME_AUTO to (1) and you want to use a frame rate of greater than 1 Hz, or to (0) if you want to use a frame rate of less than 1Hz.
  12. Set FRAME_RATE_FPS to the frame rate you want. The way the library interprets this value depends on how FRAME_SPEED is set. If FRAME_SPEED is (1) then the number set here corresponds directly to the frame rate. If FRAME_SPEED is set to () then the number sets here corresponds to 1 divided by the number set here.
  13. Set MAX_696x_MODE to match the mode of the display, either MODE_MONO, MODE_RYG, MODE_RGB

When you compile the library (after linking it to your sketch) the compiler will perform some basic checking of these settings and will exit with an error message if the settings don’t add up, eg if you specify an invalid MAX696x_OSC_FREQ or a frame rate that isn’t possible.

The actual frame rate you get with FRAME_AUTO (1) is probably not going to be exactly what you specify because of the way the MAX696x divides the oscillator down, but it will be fairly close.

Recompiling
If you need to change the settings in the library, you need to go into the Library installation directory and delete the max696x.o file. If you don’t do this then Arduino IDE will not recompile the library and your changes will not be included. This is a “feature” of the Arduino environment.

Example of Usage
Here’s some example code showing how to instantiate the library, initiate the driver and use most of the library functions to manipulate the display. Also included is a custom 57 ASCII font suitable for use with an 88 LED module : MAX6960 Example

6 Responses to MAX696x Library

  1. ISP says:

    Hi! Can I use this MAX6960 library with the ATMega2560?

  2. tom says:

    There’s no reason why the library won’t work with the ATMega2560, but it probabl won’t work without some work. The only real differences may be in the pins you use and maybe the register names for the SPI interface. I’m not familiar with the ATMega2560 (never used one myself) but the differences between it and the ATMega168 or ATMeg328 won’t be that large.

    A bigger issue is that I haven’t used the library since beta version 0.17 or so of the IDE so I am not even sure it will compile properly but again the differences should be minor and if you start with the data sheet you should be able to fix any compile errors yourself.

  3. ISP says:

    Have you the C-code that you have wrote with the AtMega168/AtMega328 for use the MAX6960?

  4. tom says:

    On this page you can find links to download the Arduino library for the MAX6960 and some example code. Since Arduino is based on C/C++, and the differences are minor you should be able to use those two sets of code with any other C compiler without much problem.

  5. ISP says:

    hi tom, i have set the registers of the MAX6960 but the display continues to flashing with a frequency of 20 Hz. You know the register that i must set for have the display forever on, without flashing?

    thx

  6. tom says:

    Without seeing your circuit or knowing what you’re trying to do, it’s hard to say.

    That said, I wrote the library back in 2009 and not used it since so I’ve pretty much forgotten how it works.

    I suggest you read the comments in the code, in particular the max696x_conf.h file. I remember spending a lot of time making the code calculate all the parameters it needs from key parameters that you set in that file, eg the frame rate, clock speed.

    You probably want to start by looking in the code and read the data sheet for the MAX6960.

    From memory what you can achieve in terms of frame rate is dependent on how large your display is, how many MAX6960 devices you have, the clock rate of the MAX6960 and the speed of the data interface from your micro.

Leave a Reply

Your email address will not be published.