# how to generate staircase wave using avr microcontroller

I am trying to build staircase wave using atmega16.i have generated pwm signal that also can be controlled width automatically.i have used low pass filter with oc0 output pin of microcontroller.as a result a change is noticed in the wave form.the code and response curve are below; avr code:

MY code:

volatile uint16_t second=0;

volatile unsigned int minute=0;

volatile unsigned int val=0;

void init_timer1(void);

void init_timer0(void);

int main(void)

{


DDRB=0xFF;

init_timer1();

sei();


init_timer0();

while (1) {

val=minute*36.4;

OCR0=val;

}
}


void init_timer0(void)

{

TCCR0 |=(1<<CS00) | (1<<CS02) | (1<<WGM00) | 1<<WGM01 | 1<<COM01;

TCCR0 &=(~1<<CS01) | (~1<<COM00);

}


void init_timer1(void)

   {  TCCR1B |=(1<<CS12);
TCCR1B |=(1<<WGM12);
TCNT1=0;
OCR1A=430;
TIMSK |=(1<<OCIE1A);


}

ISR(TIMER1_COMPA_vect) {

 second++;

if(second<7)
{ minute=second;
}
else
{ minute--;

}
if(second==12)
{
second=0;}
}


End the code ,

i have tried in different way but i have not gained my desired out put,please help anyone;

circuit diagram:

the output response is being shown in proteus oscilloscope bellow:

but when R=15 ohm C=4.7u then the output bellow; since the OCR0 resister value is set to minute from code " val=minute*36.4; OCR0=val;"

so the width of pwm is being changed but i need staircase wave,

• You might want to clean up your code a little bit. There's no need for you to be sloppy. Also, why is there an image inside the code? – Harry Svensson Nov 23 '17 at 12:58
• A proper staircase function needs to contain many high-frequency harmonics. Which are filtered out by your filter. You need the filter for cleaning up the PWM signal. Since the PWM signal frequency from an ATMega is low frequency the only proper staircase function you can make will be at extremely low frequencies, think a couple of Hz. – Bimpelrekkie Nov 23 '17 at 13:18
• Not only is the code formatted to be difficult to read due to excessive blank lines, but there isn't a single comment in the whole file! It's just plain rude to ask others to look at code this irresponsibly written. – Olin Lathrop Nov 23 '17 at 15:28
• i have edited my code .some problem was occured.when the value of resistance and capacitance of my lowpass is scaled in ohm and micron respectively then that output is shown in proteus oscilloscope.but when those value is increased the output is like pwm wave. – Muzahid Karim Nov 23 '17 at 17:46
• I will repeat myself, there's no need for you to be sloppy. Which you are. This is very similar to this scenario: You want us to taste some pie you've made, normally you cut off a part of a pie with a knife, put it on a plate together with a spoon and say "Hope it tastes good". What you've done is this:"Do you want some pie?", which I answer "Uhm.. sure", to which you throw it in my face. I got pie covering my entire face and get some in my mouth. You cannot grasp the problem, because I am indeed tasting the pie. - Your presentation is off the charts. I hope this analogy will reach you. – Harry Svensson Nov 24 '17 at 17:35