Wiring Forum
http://wiring.org.co/cgi-bin/yabb/YaBB.pl
Programming Questions & Help >> Programs >> Nixie integer overflow problem
http://wiring.org.co/cgi-bin/yabb/YaBB.pl?num=1266522992

Message started by jj on 02/18/10 at 19:56:32

Title: Nixie integer overflow problem
Post by jj on 02/18/10 at 19:56:32


Hello World,

I need some advice on how to modify some arduino code which controls
a six digit 'nixie' tube counter. This code appears simple, but will
not allow a high enough number (999,999) before overflowing because
the value is 'int' and I am told it should be 'long'...
The count breaks down at 32768 which appears to confirm this advice as
that equals 0.5 * 65536 = 2^16

I have tried just changing 'int' to 'long' in the code (two instances,
'loop' lines 2 and 3) but this does not seem to solve my problem. 

There is a special library (see below) to go with the code. Should I need
to change any part of the library? Are there other, hidden bits of the library
which the code may be using?

Any help would be very welcome. Thanks.

(The original code is to be found at http://www.ogilumen.com)

Here's the code:

/*
  nixie_write_zero - sample code using the Nixie library
                      for controlling the Ogi Lumen nixie tube driver.
  Created by Lionel Haims, July 25, 2008.
  Released into the public domain.
*/

// include the library
#include <Nixie.h>

// note the digital pins of the arduino that are connected to the nixie driver
#define dataPin 2  // data line or SER
#define clockPin 3 // clock pin or SCK
#define latchPin 4 // latch pin or RCK

// note the number of digits (nixie tubes) you have (buy more, you need more)
#define numDigits 6

// just some defines to simplify the examples
#define shortDelay 10
#define longDelay 5000
#define maxCount 999999

// Create the Nixie object
// pass in the pin numbers in the correct order
Nixie nixie(dataPin, clockPin, latchPin);

void setup()
{
  // Clear the display if you wish
  nixie.clear(numDigits);
}

void loop()
{
  // just some local variables to help the example
  int i = 0;
  int highestNum = pow(10,numDigits)-1;
 
  // limit the counter just to make sure we don't have to sit and watch it all day
  if(highestNum > maxCount)
  {
    highestNum = maxCount;
  }

  // --- Example 2 ---
  // Write out the number using a zero padding.
  // The number will be right justified with "0"s on the left
  // if the number doesn't use all tubes.
  for(i=0; i <= highestNum; i++)
  {
    // Write the number
    nixie.writeNumZero( i, numDigits);
    delay(shortDelay);
  }
 
  // wait for the next example
  delay(longDelay);
}

.....................................................................................................


and here's the library...


/*
  Nixie.h - Library for controlling the Ogi Lumen nixie tube driver.
  Created by Lionel Haims, July 25, 2008.
  Released into the public domain.
 
  Rev 2: July 27, 2008
  Rev 3: March 1, 2009:
         Added include of WProgram.h to fix compile error in arduino IDE 12/13
*/

#ifndef Nixie_h
#define Nixie_h

// Include the standard types
#include <WProgram.h>
#include <WConstants.h>

// Define the Nixie class
class Nixie
{
  public:
    // Constructor
    // dataPin  -> nixie driver pin 1 (SER)
    // clockPin -> nixie driver pin 3 (SCK)
    // latchPin -> nixie driver pin 4 (RCK)
    Nixie(int dataPin, int clockPin, int latchPin);
   
    // Write a full number, left justified, pushing digits to the right
    //   number = the number to write out
    void writeNumLeft(int number);
 
    // Write a full number, right justified, padded with zeros
    //   number = the number to write out
    //   digits = the number of digits (nixie tubes)
    void writeNumZero(int number, int digits);

    // Write a full number, right justified, padded with blanks
    //   number = the number to write out
    //   digits = the number of digits (nixie tubes)
    void writeNumTrim(int number, int digits);
   
    // Write the digits of an array of specified size
    //   arrayNums = the array of digits
    //   size      = the number to digits
    // note: a digit with a value of 10 will display a blank
    void writeArray(int* arrayNums, int size);

    // Clear the display
    //   digits = the number of digits (nixie tubes)
    void clear(int digits);


  private:
    int _dataPin;
    int _clockPin;
    int _latchPin;
    void _serializeDigit(byte writeDigit);

};

#endif //Nixie_h

.......................................................................................

Title: Re: Nixie integer overflow problem
Post by barragan on 02/19/10 at 20:23:47
seems if you are writing you have to use void writeNumLeft(int number);
which receives an integer, I guess you need to change it  to long to enable nixie to accept higher numbers.

Wiring Forum » Powered by YaBB 2.5 AE!
YaBB Forum Software © 2000-2010. All Rights Reserved.