Show Posts
Pages: [1] 2 3
1  Using Arduino / LEDs and Multiplexing / Re: 8-Digit 7-Segment LED Display Module on: March 11, 2014, 05:22:07 pm
Yeah that is what the code is doing, unfortunately it doesn't work. Each write causes all 8 LEDs to display the exact same value.  It appears it makes no difference if I send in a position value or not.  Unless I try to send the position value after the character value in which case if freaks out. Hmmm....
2  Using Arduino / LEDs and Multiplexing / 8-Digit 7-Segment LED Display Module on: March 10, 2014, 09:29:14 pm
I've been sent this display and I'm having some issues getting it to work.

http://www.icstation.com/product_info.php?products_id=2428#.Ux5gPfmwLYg

With the code below I'm able to write the various digits to the display and control the decimal points.  However it appears that what ever the last digit is that I write to the display fills all of the LEDs.  So if I write 98765432 then 2 is displayed in all of the LEDs.  This thing has no documentation so I'm just trying to figure it out.  It uses two 595 shift registers. Any ideas?

Code:
#define SER 11 //DATA
#define RCL 12 // LATCH
#define CLK 8 // CLOCK
// 7 segment display with segment/bit encoding of .gfedcba
//   AA
// FF  BB
//   GG
// EE  CC
//   DD  .
// Binary mapping for digits 0 to 9 with decimal point turned off.
// a bit value of 0 turns the segment on, a value of 1 turns it off.
byte numbers[10] = {
  B11000000, B11111001, B10100100,
  B10110000, B10011001, B10010010,
  B10000010, B11111000, B10000000,
  B10010000 };
byte space = B11111111;   // space, all segements off
byte decimal = B10000000; // decimal point on bit
// Positions
byte positions[8]={1, 2, 4, 8, 16, 32, 64, 128};

void setup() {
  //set pins to output so you can control the shift register
  pinMode(RCL, OUTPUT);
  pinMode(CLK, OUTPUT);
  pinMode(SER, OUTPUT);
}

void loop() {
  digitWrite(9, 0, true);
  digitWrite(8, 1, true);
  digitWrite(7, 2, true);
  digitWrite(6, 3, true);
  digitWrite(5, 4, false);
  digitWrite(4, 5, true);
  digitWrite(3, 6, true);
  digitWrite(2, 7, true);

}

void digitWrite(int value, int pos, boolean decimalOn) {
  // turn off the output so the pins don't light up
  // while you're shifting bits:
  digitalWrite(RCL, LOW);

  shiftOut(SER, CLK, MSBFIRST, positions[pos]);
  //shiftOut(SER, CLK, MSBFIRST, pos);
  if(decimalOn)
    shiftOut(SER, CLK, MSBFIRST, numbers[value] ^ decimal);
  else
    shiftOut(SER, CLK, MSBFIRST, numbers[value]);

  // turn on the output so the LEDs can light up:
  digitalWrite(RCL, HIGH);
}
3  Using Arduino / Programming Questions / Re: Optimization of code for maximum speed, very specific project. on: April 25, 2013, 08:55:47 am
Ah, okay. Thanks I didn't realize that.  It gives me an idea for how to "fix" it though.
4  Using Arduino / Programming Questions / Re: Optimization of code for maximum speed, very specific project. on: April 24, 2013, 10:29:21 pm
Here is a new video. It may take a little while for youtube to process it and make it live. This shows the project basically completed and running through some effects fed to it by Vixen. Finding some interesting side effects of the relay boards. Most interesting is that they seem to be leaking enough power to dimly light a string of LEDs. It isn't a code problem, there is definitely power leaking through the relays. You don't notice it until you connect a string of LEDs, incandescent lights don't have the issue. I wonder if replacing the relays with random cross relays is showing a flaw in the sainsmart board design.

More likely there are resistors on the boards that aren't large enough to keep the power from leaking or the photo decouplers are getting triggered somehow. I've also found an interesting issue with Vixen that I didn't run into before. If none of the channel values change from one frame to the next frame, no data is sent. So my suggestion is to use one of the channels to make sure something always changes so all of the channel data will get sent every frame.

http://youtu.be/AGeSo57uV1I
5  Using Arduino / Programming Questions / Re: Optimization of code for maximum speed, very specific project. on: April 07, 2013, 07:30:15 pm
Working?!  Already!   Excellent!

I was fun to help with a well-defined, well-expressed problem with existing well-commented code, and someone who was responsive to the suggestions made.  MUCH better than all the "Is a MEGA too slow to handle 32 channels of dimming?  Do I need a Due?" questions that result in an extended "discussion" of 8 vs 32 bit cpus, during which the original poster disappears...


LOL, yeah that kind of topic can be a bummer.  smiley
6  Using Arduino / Programming Questions / Re: Optimization of code for maximum speed, very specific project. on: April 07, 2013, 03:32:24 pm
Okay the code is now working! Thanks for the help everyone.  Boy was I going about this the wrong way.  Code is attached.
7  Using Arduino / Programming Questions / Re: Optimization of code for maximum speed, very specific project. on: April 05, 2013, 08:35:21 pm
Okay, random mode, reading data from Vixen, zero cross detection and setting the powerDelay values all work as long as I set the prescaler to 8 and TIMER_CYCLE_COUNT to 100. However in Vixen mode the channels don't turn on until the channel values reach about 128 out of the 255 possible.  I had a lot of really stupid bugs in there.  Working on this stuff when I'm very tired has proven to be a bad choice, lol.

Now I just have to figure out why the light don't come on until around 128 and they don't seem to change intensity.  Attached is the latest code.
8  Using Arduino / Programming Questions / Re: Optimization of code for maximum speed, very specific project. on: April 05, 2013, 08:59:56 am
Quote
Similarly, since serial messages are only occasional and not more than every 50ms, while AC cycles happen every 1/120 s (8.3ms),
get rid your calculations of powerDelay[] in ZeroCrossDetected and move them into the serial receive code.

Done. I only update the powerDelay values after I have read in a new set of channel values, see the updatePowerDelayValues() in the code.  I'm turning the interrupts off during this process and I'm not sure if that is a good or bad idea.

I asked this next question earlier and I think I've seen to conflicting "answers" can someone give me the straight poop (I've changed the code this is no longer true but I would like to know)?  "Given that the powerDelay array is only assigned values inside one of the ISRs and only read from the other ISR and the ISRs are not nested:  Can I remove the volatile attribute from the declaration?  That should give me a few extra cycles in speed shouldn't it?"

Quote
You can.  You shouldn't.  It won't make any difference...

In each ISR each element of powerDelay is accessed just once (read in one ISR; written in the other).  Removing volatile only helps when there are multiple accesses.  Removing volatile eliminates redundant loads from memory but there aren't any.

and

Quote
This would get better if powerDelay isn't volatile, and if it's smaller, but it still doesn't need to happen every half-cycle.
Or you could look at making the copy into a memcpy() call, which would "short circuit" the (correct) volatile declarations.

Maybe I'm just reading more into the second one than is really there.

 
9  Using Arduino / Programming Questions / Re: Optimization of code for maximum speed, very specific project. on: April 05, 2013, 08:59:06 am
Quote
 tickCounter += TIMER_CYCLE_COUNT;
You are chasing a wrong direction here, I think.   You should want to redefined a "tick" so that tick = CycleTime/BrightnessLevels (or, for 8.3ms and 256 brightness levels, about 32 us.)  That means that the clock always ticks by 1 in your ISR.   The actual clock or instruction rate of the cpu ought to be irrelevant.  Sure, at some level it's the limiting factor, but you want to have your code running in a way that it's so much faster than the problem, that there's no actual dependency...

Looking at the code generated when tick and powerDelay are both uint8_t, it looks to be about 480 instructions.  32 us is about 512 instructions.  Now, every ISR execution doesn't execute all the instructions, and all the instructions are not one cycle, so it's hard to tell whether this would actually be fast enough.  It does indicate (to me) a couple of things:
1) It would be pretty close; certainly close enough to worry about.
2) wider math (32bit tick and powerDelay) probably isn't going to work at all. (1100 instructions!  (odd that it isn't more.))
3) going to, say, 100 ticks/halfcycle instead of 256 ticks/halfcycle, would probably give you all the breathing room you need.

I see what you are getting at now, thanks.  I didn't understand how you expected me to put values of 256 or more into a byte.  I'll have to see what I can to rearrange this.  The latest code is attached.
10  Using Arduino / Programming Questions / Re: Optimization of code for maximum speed, very specific project. on: April 05, 2013, 08:38:53 am
If your sketch can't keep up,   you could always try moving to a country with 50 Hz electricity.    Like, for example,  New Zealand.    Or one half of Japan ( I forget which half ).

That is thinking outside the box. smiley
11  Using Arduino / Programming Questions / Re: Optimization of code for maximum speed, very specific project. on: April 04, 2013, 07:26:07 pm
Man I'm waaay to beat and brain fried, I need to step away, I can't even read your post, lol.

I have determined that the numbers simply look erratic, by adding a counter for the ZC ISR and using it to add the overhead in cycles for the ZC ISR and massively increasing the timer interrupt interval the numbers even out a lot.  Basically it is all happening so fast there is just no way to use serial output to measure it.  I wish I a scope and a logic analyzer.

Oh well.  Thanks again, I'll take a look at your post again after I get some sleep.
12  Using Arduino / Programming Questions / Re: Optimization of code for maximum speed, very specific project. on: April 04, 2013, 06:56:44 pm
Okay sorry to keep pestering everyone but this has me baffled.  Attached is the version of the code that generated the following output.  As you will see I have set the timer/counter 1 TOP value to 100 so I should get the interrupt every 100 cycles.  I've commented out everything in both ISRs except:

1> the reset of tickCounter=0 on the detection of AC zero cross
2> the addition of 100 to tickCounter every time the timer/coutner interrupt is triggered

I'm not reading anything from Vixen in this test.  This is just to see if I get a stable zero cross detection and a stable tick count.

What I am seeing is:

Code:
Power on self test running.
Channel: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
POST Done.
Setting up Vixen mode.
millis=8256 tickCounter=13200
millis=8257 tickCounter=35600
millis=8258 tickCounter=6364
millis=8261 tickCounter=33000
millis=8263 tickCounter=9164
millis=8266 tickCounter=49564
millis=8269 tickCounter=25000
millis=8271 tickCounter=1264
millis=8274 tickCounter=41664
millis=8276 tickCounter=16700
millis=8280 tickCounter=58500
millis=8282 tickCounter=34664
millis=8285 tickCounter=10300
millis=8287 tickCounter=52000
millis=8290 tickCounter=28064
millis=8293 tickCounter=3300
millis=8295 tickCounter=43700
millis=8298 tickCounter=19864
millis=8300 tickCounter=500
millis=8303 tickCounter=34500
millis=8305 tickCounter=10764
millis=8308 tickCounter=52464
millis=8310 tickCounter=27500
millis=8313 tickCounter=3664
millis=8315 tickCounter=44064
millis=8318 tickCounter=19600
millis=8322 tickCounter=61400
millis=8324 tickCounter=37564

Are these number more stable than they look and it is just because the serial printing is so slow compared to the interrupts?
13  Using Arduino / Programming Questions / Re: Optimization of code for maximum speed, very specific project. on: April 04, 2013, 04:31:00 pm
Quote
I'm trying to get 256 levels of brightness, but frankly I'm not sure that level is needed.

Very unlikely.  In my opinion, what works best are fewer levels with levels that reflect how a human perceives brightness.  I typically use 100 levels with each level such that a person would say there is about a 1% difference in brightness between each level.


That makes a lot of sense.  I guess I'll see how the 256 works out and then maybe back off and give 100 a try.  I'm betting you are right.
14  Using Arduino / Programming Questions / Re: Optimization of code for maximum speed, very specific project. on: April 04, 2013, 11:58:02 am
Given that the powerDelay array is only assigned values inside one of the ISRs and only read from the other ISR and the ISRs are not nested:  Can I remove the volatile attribute from the declaration?  That should give me a few extra cycles in speed shouldn't it?
15  Using Arduino / Programming Questions / Re: Optimization of code for maximum speed, very specific project. on: April 04, 2013, 11:48:01 am
If speed is very critical, I imagine moving the part that does the interrupt handling and turning on specific lights at specific times off to an outboard processor that does not do interrupts, instead it is dedicated, and just reads the status constantly in the loop.  It should do nothing but just a busy poll, and turn on/off lights.  It would need some way of getting control updates from the brain processor (another pin perhaps).  Otherwise you are going to be spending a lot of time having the interrupt set up the call stack and then undo it.  And if that is not fast enough, consider getting a faster processor like an ARM embedded board.

Perhaps you could use a standard 555 type circuit to do the timing, perhaps not.

I guessing that is beyond my current skill level, lol.  Maybe that will be Version 3 of the controller.
Pages: [1] 2 3