Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Help with line of code (var rowNumber)


  • Please log in to reply
6 replies to this topic

#1 vader7071

vader7071

    Advanced Member

  • Members
  • PipPipPip
  • 132 posts
  • LocationDothan, AL

Posted 03 March 2014 - 08:46 PM

I am still working on my max7219 code. In trying to tweak a existing program, I came across a line that I think is my hang up.

Here is what I want to do. I have the line
byte[] r2 = new byte[8];
I want to be able to change the 8 to either 16, 24, 32, 40, etc, depending on how many chips I have. I have done this in other applications.

But here is what I am having an issue with. In the old code there is a line:
var rowNumber = (byte)RegisterAddressMap.Digit0;
If read this right, rowNumber = the number of bytes in digit0 inside RegisterAddressMap. In this case, that would be 8.

If I want to do, say 16, I would need to hard code rowNumber to 16, correct?

I can post more parts of the code if need be.

Thank you for your help.

#2 vader7071

vader7071

    Advanced Member

  • Members
  • PipPipPip
  • 132 posts
  • LocationDothan, AL

Posted 03 March 2014 - 09:44 PM

Ok tried coding for 16, and it just got worse. Here are the code snippets of what I am doing. Maybe this will help.
 
{from program.cs}
(...)

_max = new Max72197221(chipSelect: Pins.GPIO_PIN_D8);

(...)

while (true)
{
     Random rndGen0 = new Random();
     _max.SetIntensity(15);
     byte[] r2 = new byte[8];      //for speed, an 8 byte setup
     byte[] r3 = new byte[16];     //for speed, a 16 byte setup
     rndGen0.NextBytes(r2);        //random generator for 8
     rndGen0.NextBytes(r3);        //random generator for 16
     _max.Display(r3);             //display either the 8 or 16 byte depending on what I put in
     Thread.Sleep(120);
}

(...)
{from max72197221.cs}
(...)

public class Max72197221 : IDisposable 
{
     public enum RegisterAddressMap 
     {
          NoOp,
          Digit0,
          Digit1,
          Digit2,
          Digit3,
          Digit4,
          Digit5,
          Digit6,
          Digit7,
          DecodeMode,
          Intensity,
          ScanLimit,
          Shutdown,
          DisplayTest = 0x0F
     }

(...)

public void Display(byte[] matrix) 
{
     //if (matrix.Length != 8)
     //{
     //    throw new ArgumentOutOfRangeException("matrix");
     //}
     // the above code set an error if the byte was more than 8, so I just shut it down
     
     var rowNumber = (byte)RegisterAddressMap.Digit0;
     foreach (var rowData in matrix) 
     {
          Write(rowNumber, rowData);
          rowNumber++;
     }
}

(...)
When I lock it down to 8, it works perfect (well if you consider all displays showing the exact same thing perfect). When I take it outside of 8, it goes haywire.

#3 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 04 March 2014 - 12:35 AM

Judging from the RegisterAddressMap enum, there seem to be an 8 digit limit to the driver.

The enum is conceptionally mistreated. They way they are defined, they are not meant for you to apply arithmetics operations onto them.

Surely, as the corresponding enum values just so happens to be 0,1,2,3...etc because of the order in which they appear, you consecuently happen to get "digit1" by adding a one to "digit0". However, when adding a one to "digit7" you suddenly get "DecodeMode" instead of "digit8" which is not defined.

See what I mean?

#4 sfugarino

sfugarino

    Member

  • Members
  • PipPip
  • 29 posts
  • LocationSuwanee, GA

Posted 08 March 2014 - 06:37 PM

Don't know if this will work, but derive your enum from byte.

public enum RegisterAddressMap : byte


Then assign values to each element in the enum.

NoOp = 0x00,
Digit1 = 0x01...

#5 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 09 March 2014 - 08:23 PM

Those are the values assigned by default so it won't change anything.

Actually, the MAX 7219 and 7221 are 8 digit driver chips but they support daisy-chaining while the driver class apparently does not.

https://www.sparkfun...219-MAX7221.pdf

The solution is to modify the driver so that it supports cascading.

#6 vader7071

vader7071

    Advanced Member

  • Members
  • PipPipPip
  • 132 posts
  • LocationDothan, AL

Posted 09 March 2014 - 09:30 PM

Ok, did a little more reading from an old program I used. The old program works on 2+ chips. I just have to tell it how many chips, but here is the problem, get past 2 chips, and it get SLOOOOOOOOOOW. Seriously slow. Like no "thread.sleep" command at all and still operates just about the right speed for a scroller slow, and you can still see the updating on the display.

So in that reading, I caught an interesting line. There is a line that says (basically):

create byte1[8] random
create byte2[8] random
create byte3[8] random

write location 1 from byte 1 to col 1 chip 1
write location 1 from byte 2 to col 1 chip 2
write location 1 from byte 3 to col 1 chip 3
write location 2 from byte 1 to col 2 chip 1
and so on.

I am trying to be able to use the SPI mode to control the chips because according to the code, this seems to be more of a "bitbang" method. I am trying to speed up the transfer to make the data on the grid smoother.

Where I am going awry in the faster code is that I still get in my head that I create "byte[16]" and transmit that, but that is not the case, I will have to create (2) "byte[8]" and transmit one to one chip and one to the other.

#7 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 15 March 2014 - 03:43 PM

When cascading as depicted on page 13 of the d/s, you don't send data to a certain chip, instead you just clock out the data bits in a series out the MOSI line and into the shift register of each chip. When all bits are in place, you assert the load pin for all chips at once and each chip will load whatever command there is sitting in its shift register at that point.

Of curiosity, how come you need more than 16 digits?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.