Close

Some programming

A project log for RGB WIFI Dimmer

12V Dimmer with 4-PWM Outputs a 3A and ESP-01 suitable pinheader

ethonEthon 12/10/2015 at 13:150 Comments

Today I wrote some lines codes for the project and checked the results with an oscilloscope. I created 4 PWM signals, three with the Output Compare Registers of the µC and another one with timer0 by using an ISR. The slowest PWM has 600Hz and the other three have about 30kHz frequency which I want to use for the RGB LEDs.

void ATmega8_PWM_8bit_Software_timer0(uint8_t value)
{
	softpwmvalue=value;
}

void ATmega8_PWM_8bit_Software_timer0_setup(void)
{
	DDRD	|=(1<<PORTD5);		//set D5 as output
	TIMSK	|=(1<<TOIE0);		//Counter0 Overflow Interrupt Enable
	TCCR0	|=(1<<CS00);		//set prescaler to 1
}
ISR(TIMER0_OVF_vect)
{
	static uint8_t counter;
	counter=counter+1;
	if (counter>softpwmvalue)
	{
		PORTD &= ~(1<<PORTD5);			//off
	}
	else
	{
		PORTD |= (1<<PORTD5);			//on
	}
	
}

Discussions