Close

First code

A project log for SHTTTRRR

A small shutter controller for Canon EOS Cameras

glitchmakerGlitchmaker 01/11/2015 at 20:170 Comments

As a first approach i wanted to find out how to count the time between two button presses. Based on this project I would use a one second watchdog timer in interrupt mode to increment a counter:

ISR(WDT_vect)
{
	seconds++;
}

Instead of the buttons being pooled, I also implemented a hardware pin interrupt. When the interrupt occours, the ISR function is called with the PCINT0 vector, as this:

ISR(PCINT0_vect)
{
	unset_interrupt();
	switch(button_press)
	{
		case START_P:
		start_second = get_seconds();
		blink(3);
		break;
		case STOP_P:
		stop_second = get_seconds();
		blink(2);
		break;
		default:
		break;
	}
	button_press++;
	duration = stop_second - start_second;
	if(button_press>=3){
		for (i=0; i <duration; i++)
		{
			blink(1);
		}
		button_press = START_P;
	}
	set_interrupt();
}
The unset_interrupt() function stops the hardware interrupt, eliminating interference, and after running the code, we use set_interrupt() to re-enable the hardware interrupt.

The function get_second() gets the current second, using atomic operation, from the seconds variable.

int get_seconds()
{
	int current_second;
	ATOMIC_BLOCK(ATOMIC_FORCEON){
		current_second = seconds;
	}
	return current_second;
}

The next step I want to take is to eliminate the _delay_ms() functions of my code, do a little clean up and advance with the shutter part.

Discussions