Forum Index > Projects > Larson Scanner kit and LED Menorah kit support
 Pinball mod with a larson kit, couple of questions
 |  Printable Version
By: brand (offline) on Friday, April 13 2012 @ 05:51 PM PDT  
brand

Quote by: Sonny_Jim

All that I need to do know is modify it so that the lights run are triggered from a reed switch, and only to run for a few seconds before stopping again. Then all that's left is get a 3V regulator and I'll have this fun little project done!

I've just bought a 5M of SMD 5050 LED's along with some MOSFETs and another Larson scanner kit, hopefully going to make some cool lighting effects!



That, my friend, is why the Great Babbage gave us interrupts.

There's a new version of larson.c up on http://www.drbrad.org/larson.c -- have a look. I set up an interrupt based on Timer/Counter0 that ticks about twice a second. There's a variable, waking_time, that you can adjust to the number of ticks you want to run before going to sleep. It's currently set to 13 (I'm a triskaidekaphile), so it runs for about 6 seconds.

Wake up is set to a level change on pin PB6 (that's where you could wire in your reed switch -- any of the PBn pins will work). You can cause that by touching a wire to pins 1 and 2 on the 6-pin programming header (the two pins closest to the MCU), and the thing should kick off again.

Alternately, you can replace 'PCINT6' (Pin Change INTerrupt 6) with PCINT4, and pushing the button will wake it up. However, pushing the button will also change the speed at the same time (well, not actually at the same time, but there's no way you could push the button quickly enough for the code not to catch it). I suppose you could set it to a speed you like and comment out the code that looks for a button press.

Again, the code is over-commented, but feel free to ping me if you have questions.

Oh yeah, post some videos (and pointers) when you get your rig set up. It sounds very cool.

Take care,
brad


Forum Apprentice
Apprentice


Status: offline

Registered: 02/27/12
Posts: 10

Profile Email    
   
By: Anonymous: Sonny_Jim () on Sunday, April 15 2012 @ 07:12 AM PDT  
Anonymous: Sonny_Jim

Hmm, that's odd when I comment out the button reading code ("if ((PINB & 16) == 0)"Wink it runs continuously, which is completely baffling me. Even if I just comment out Updateconfig = 1 and nothing else it runs continuously. Very odd (to me at least)

I don't want to shorten the lifespan of the chip by continually writing to the EEPROM, as the settings will be hardcoded.





       
   
By: brand (offline) on Sunday, April 15 2012 @ 09:32 AM PDT  
brand

I just reproduced the behavior by commenting out

UpdateConfig = 0;

That is a head-scratcher; I'll have a look at it in more detail later.

Meanwhile, I wouldn't worry about the life of the chip for a couple-a-three reasons:

1) For sheer endurance, silicon will beat carbon every time. The IceTube Clock from Adafruit updates the EEPROM with the time and date every hour (in case of power failure), and that's good for about 10 years. You're not going to use up the EEPROM pressing the button yourself. The only way you'd run up against the EEPROM limitation is if you were using it as a sort of black box to keep second-by-second event histories.

2) The code is written to do something sane even if the EEPROM is returning garbage on reads, and if it fails, writes will still "succeed" from a program perspective. As a tape drive engineer said to me in the 1970s, when I was a data center tape ape, "Son, I can get it to write on toilet paper; reading is the hard part."

3) Let's face it, the chips are less than $2 apiece (and you can get the 2313A for less than a buck) on Mouser.

Take care,
brad


Forum Apprentice
Apprentice

Status: offline

Registered: 02/27/12
Posts: 10

Profile Email    
   
By: Anonymous: Sonny_Jim () on Monday, April 16 2012 @ 08:48 AM PDT  
Anonymous: Sonny_Jim

Ok, so I messed up my last post, I really should register with this site rather than posting anon, but anyhoo....

I've got a 5V regulator (LM7805C) which isn't ideal but I had one to hand, looking at the datasheet for the 2313 it should operate on 5V happily. Now going by my shady calculations, I'm thinking that I should bump up the values of the resistors from 16ohms to 47ohms due to the increase in voltage?





       
   
By: brand (offline) on Monday, April 16 2012 @ 10:45 AM PDT  
brand

The 2313 is happy up to 5.5v. As for the LEDs...

Um, depends?

R = (Vpowersupply - LEDforwardvoltage) / LEDcurrent

For a typical red LED, that might be something like 2.5v forward and 50mA current, so

2.5 / .05 = 50 ohms, so, yeah 47 ohms would probably take care of you.

I haven't had a chance to muck with the code yet, but I want to check the watchdog timer settings first. Then I'll have a look through the rest of it.

Take care,
brad


Forum Apprentice
Apprentice

Status: offline

Registered: 02/27/12
Posts: 10

Profile Email    
   
By: Windell (offline) on Monday, April 16 2012 @ 04:07 PM PDT  
Windell

That's higher than *necessary* for the red LEDs, and they'll be crazy bright, but they'll probably survive it. If you want them to run that bright, go for it.


Windell H. Oskay
drwho(at)evilmadscientist.com
http://www.evilmadscientist.com/

Forum Evil Scientist
Evil Scientist

Status: offline

Registered: 06/15/06
Posts: 1932
Sunnyvale, CA

Profile Email Website  
   
By: brand (offline) on Monday, April 16 2012 @ 06:10 PM PDT  
brand

Quote by: brand


I haven't had a chance to muck with the code yet, but I want to check the watchdog timer settings first. Then I'll have a look through the rest of it.



Yeah, that was a pretty stupid idea. The watchdog is disabled by default, and near as I can tell, this code:

PHP Formatted Code
  MCUSR &= 0xF7;                //Clear WDRF Flag                              
  WDTCSR        = 0x18;         //Set stupid bits so we can clear timer...      
  WDTCSR        = 0x00;                                                        
 



explicitly disables the watchdog timer if it had been enabled before (for some reason) and caused a reset. I guess if someone had mucked around with their chip, enabled the watchdog, and let it cause a reset, this would clean up the mess.

I'm going to go back to checking my interrupt handler and friends. My next guess is that this is some sort of race condition I've introduced with bad semaphore handling.

Take care,
brad


Forum Apprentice
Apprentice

Status: offline

Registered: 02/27/12
Posts: 10

Profile Email    
   
By: Anonymous: Sonny_Jim () on Tuesday, April 17 2012 @ 12:02 AM PDT  
Anonymous: Sonny_Jim

Quote by: Windell

That's higher than *necessary* for the red LEDs, and they'll be crazy bright, but they'll probably survive it. If you want them to run that bright, go for it.


Well the LED's are going to be mounted underneath the piece of plastic that says 'LOCK' in the following picture:


Considering the amount of other lighting in the pinball table, I'd like to get them as bright as possible, without melting the plastic. I'm thinking that it'll be pretty much impossible for the LED to melt the plastic, but I'll mount it and see how it looks with the 16ohm and modify to suit.





       
   
By: brand (offline) on Thursday, April 26 2012 @ 12:32 AM PDT  
brand

OK, I'd love to say I cracked it, but I had to go onto AVR-freaks to have someone point me to the very first item in the bloody AVR Libc FAQ that was under my nose the whole time.

Sigh.

Replace the line:

PHP Formatted Code
uint8_t tick_flag;



with

PHP Formatted Code
volatile uint8_t tick_flag;



and you can dike out the whole block of code that tests for UpdateConfig and friends.

Do I look as dumb as I feel?

To be fair, I've had a couple of hours of amusement playing with avr-gcc and seeing what it does in turning C into assembler....

Take care,
brad


Forum Apprentice
Apprentice


Status: offline

Registered: 02/27/12
Posts: 10

Profile Email    
   



 All times are PDT. The time is now 11:37 AM.
Normal Topic Normal Topic
Locked Topic Locked Topic
Sticky Topic Sticky Topic
New Post New Post
Sticky Topic W/ New Post Sticky Topic W/ New Post
Locked Topic W/ New Post Locked Topic W/ New Post
View Anonymous Posts 
Able to Post 
Filtered HTML Allowed 
Censored Content 

Evil Mad Scientist Forum Archives — Read only!

Please visit our new forums for new discussions.


DIY Hardware for Electronic Art


The Original Egg-Bot Kit


Octolively
Interactive LED kits


Meggy Jr RGB
LED matrix game
development kit.


Business-card sized
AVR target boards


Peggy 2
LED Pegboard kits

My Account






Lost your password?