You might have noticed the Slaveflash I built with an Attiny 24, the instructable can be found here: Slaveflash-trigger-for-digital-with-Attiny24


After building the first prototype I collected all my old flashes I got over the years and had four more slaveflash-triggers to built. 
I already figured out an PCB-Layout for the SOIC-version of the attiny 24. But the biggest parts in the design are actually the hex-switch and the optocoupler, so it would make no sense to substitute only the microcontroller by a smaller one. Instead I replaced the hex-switch by a learning mode in software and also replaced the power source.

By replacing the 7805 voltage controller by a button cell with 3V, the power consumption was reduced from 2mA to below 0.5mA without the LED on. 

So here it is: Let's got started!

Step 1: Changes in the schematics

In comparison to the former model a lot of things are deleted and the schematics is much easier.
  • The complete voltage controller section is deleted.
  • The hex-switch is replaced by nothing.
And this is what is left:
  • The reset-button
  • the flash-detector
  • the status-Led
  • and the optocoupler. 

<p>Hello and thank you for this instructible. :)</p><p>I will try to make one but i need to use attiny85. Code would not compile in WinAVR so i started poking and prodding. Since I am total beginner it must contain mistakes but it compiles without any warnings.</p><p>I can't be sure when i will have time to test this but when i do i will confirm or edit or more likely ask for help :)</p><p>Comments and corrections are more then welcome ;)</p><p>Mladen </p><br><br><p>main.c code:</p><p>/***********************************************************************<br>*<br>* Slave-Flash with Attiny85<br>* Original code by: andyk75 - http://www.instructables.com</p><p>* <a href="http://www.instructables.com/id/Slaveflash-with-Attiny24-ver-20/?ALLSTEPS" rel="nofollow"> http://www.instructables.com/id/Slaveflash-with-A...</a><br>*<br>* Description:<br>* A photo-diode registers a flash and counts an internal counter<br>* if the counter reaches the limit an second flash is triggered.<br>*<br>* Ports:<br>* PB4 statusled<br>* PB3 Reset, active low, 10k to VCC, pushbutton to GND<br>* PB2 Interrupt int0, active high, 1k to Pushbutton, 10k to GND Pulldown<br>* PB1 Clock (Xtal2), UNUSED <br>* PB0 fire<br>*<br>***********************************************************************/<br><br>#ifndef F_CPU<br>// #warning &quot;F_CPU not defined, is set to 1MHz&quot;<br>#define F_CPU 1000000UL <br>#endif<br><br>#include &lt;inttypes.h&gt;<br>#include &lt;avr/io.h&gt;<br>#include &lt;util/delay.h&gt;<br>#include &lt;avr/sleep.h&gt;<br>#include &lt;avr/interrupt.h&gt; <br>#include &quot;slaveflash.h&quot;<br><br><br>void init(void)<br>{<br> statusledport &amp;= ~(1&lt;&lt;statusled); <br> statusledDDR |= (1&lt;&lt;statusled); <br><br> fireledport &amp;= ~(1&lt;&lt;fireled); <br> fireledDDR |= (1&lt;&lt;fireled); <br> <br> // Flashdetect-Interrupt <br> MCUCR = (1&lt;&lt;ISC01); // A rising Edge at Int0 generates Interrupt<br> GIMSK |= (1&lt;&lt;INT0); // aktivate interupt for int0<br><br> // reduce power consumption by switching off unneeded options<br> ACSR |= (1&lt;&lt;ACD); // Analog comparator disable<br> ADCSRA = 0; // ADC disable<br> PRR = (1&lt;&lt;PRTIM0) | (1&lt;&lt;PRUSI) | (1&lt;&lt;PRADC); // shut down timer1, USI, ADC for power reduce<br><br> // Timer to reset the flashcounter<br> TCCR1 |= (1 &lt;&lt; CS10) | (1 &lt;&lt; CS11) | (0 &lt;&lt; CS12) | (1 &lt;&lt; CS13); // timer 1 prescaler to 4096<br> TIMSK |= (1&lt;&lt;TOIE1); // Overflow interrupt enable<br><br><br> flashcount = 0; // clear all counted flashes<br> flashesneeded = 0; // initialise flashesneeded to zero<br>}<br><br>ISR(TIM1_OVF_vect) // Timer 1 Overflow<br>{<br> cli();<br> TCNT1 = 255; // preload the timer counter for about 1s.<br> if(flashesneeded == 0) // if still learning <br> {<br> flashesneeded = flashcount; // timer kicking in after learning flashes<br> }<br> flashcount = 0; // Reset the counted flashes<br> statusledport &amp;= ~(1&lt;&lt;statusled); // clear the statusled<br> sei();<br>}<br><br>ISR(INT0_vect) // Interrupt Service routine for the int0-Pin (PB2 = interrpt)<br>{<br> cli();<br> TCNT1 = 255; // preload the timer counter for about 1s. <br> statusledport ^= (1&lt;&lt;statusled); <br> flashcount++;<br> if (flashesneeded &gt; 0) if (flashcount == flashesneeded) fire();<br> sei();<br>}<br><br><br><br>int main(void)<br>{<br> init(); // Set all Registers and initialise<br> <br> _delay_ms(100); // Wait a 'bit'<br><br> signal(2); // signal correct startup<br> sei(); // enable interrupts<br> for(;;); // do nothing, everything important is done in the interrupt routines<br><br>return 0;<br>}<br><br><br>void signal(uint8_t counter)<br>{<br>uint8_t i;<br>for(i = 0; i&lt;counter; i++)<br> {<br> statusledport |= (1&lt;&lt;statusled);<br> _delay_ms(50);<br> statusledport &amp;= ~(1&lt;&lt;statusled);<br> _delay_ms(150);<br> } <br>}<br><br><br>void fire(void) <br>{<br> // Release the slave-flash<br> fireledport |= (1&lt;&lt;fireled);<br> _delay_ms(250); // enough to release the flash<br> fireledport &amp;= ~(1&lt;&lt;fireled);<br> _delay_ms(100); // wait a bit before going back and reactivating the interrupt<br> flashcount = 0;<br>}</p><p>**************************************************</p><p>slaveflash.h is also modified for new pins</p><p>**************************************************</p><p>#define true 1<br>#define false 0<br><br>#define flashdetect PB2 // IN<br><br>#define statusled PB4 // OUT<br>#define fireled PB0 // OUT<br><br>#define flashdetectDDR DDRB<br>#define flashdetectport PORTB<br><br>#define statusledDDR DDRB<br>#define statusledport PORTB<br>#define fireledDDR DDRB<br>#define fireledport PORTB<br><br><br>// Function prototypes<br>/*------------------------------------------------------------------*/<br>void init(void);<br>int main(void);<br>void signal(uint8_t counter);<br>void fire(void);<br>/*------------------------------------------------------------------*/<br><br>// Variables<br><br>uint8_t flashcount, flashesneeded;</p><p>***************************************************</p>
<p>Sorry, but I can not debug your code. Since I don't have the time and the Attiny85. </p><p>But here are some hints: </p><p>Use a LED to see where the code is going to. Does the Interrupt really occur? Did you configure the interrupt correctly? Does the photodiode work correctly? Is the timing right? Do you wait to long for the second flash? Or reset the counter too fast? </p><p>Good luck! </p>
Adler44 say: <br />Thanks Andy, you are absolutely right. My mind was playing tricks on me; I was reading slaveflash.h file as an hex file. Sorry for your time and thanks again.
andyk75, <br />thanks for your circuit. I hope it works with my sony dsc w300 PS camera. One question though, in the list of include files is the slaveflash.h. It is not listed in my avrstudio4 or winavr installations. How do I get this for compiling and programming? <br />thanks a lot.
You have to download the file slaveflash.h from step 2! <br />Just where you got the c-code! <br />Have fun and enjoy the slaveflash!
sir i copied ur c file and pasted it on avr studio and buil but its showing many error around 24 error <br>
You also need to include the header file (*.h)! <br>And make the correct settings in the avr-studio f&uuml;r the attiny 24. Unfortunately I'm not using avr-studio any more, so I can't help you with that. You could try a avr-forum for specific questions.<br>
Could be just me, but yr code generates many many errors in compiling. I am no expert on libraries, but is just a header file (slaveflash.h) enough for compiling?<br><br>What compiler have you used?
Hi,<br><br>this code works well with the AVR-Studio 4.something and the winAVR-gcc compiler. I had no error and not even a warning left when compiling. <br>I set up the workflow long ago. <br>AVR-studio is the editing-environment that takes care of the makefile and the includes and everything. While the winAVR provides the compiler, the libraries and the rest of what is needed. winAVR works completely in the background, I don't know if there is even a gui for it. <br><br>Hope that helped! <br>
Thanks Andy, I already presumed it was depending on the compiler. Guess I will get AVR
Great design. The 'learning' mode is a great addition. There is another design of a 'learning' slave unit in the public domain (from Pavel Janko), based on a PIC, but this one might be easier coz the Attiny24 is probably somewhat easier to program.<br>No let me correct that, it is easier in my experience to build an attiny programmer than it is to build a PIC programmer.<br><br>I may build this one. I think though that the optocoupler is not really necessary as the unit is self contained. A Thyristor or even a transistor (if the sync voltage is not to0 high) will suffice.

About This Instructable


12 favorites


Bio: I like to explore new things and try out stuff. At the moment I'm in to electronics and LEDs (mainly).
More by andyk75: BLE-Controlled WS2801 LEDs Make a secret IR-camera security raspberry pi unit Write a new service for linux (opensuse)
Add instructable to: