EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Replies / Hi Lokesh, Try these

Hi Lokesh, Try these

|

Microcontroller › AVR › Issue regarding waveform generation › Hi Lokesh, Try these

March 5, 2013 at 4:19 pm #9249
AJISH ALFRED
Participant

Hi Lokesh,

 

Try these modifications.

 

#include <avr/io.h>
#define F_CPU 1000000UL
#include <util/delay.h>
#include <avr/interrupt.h>
//int counter,flag;
int counter = 0, flag = 0;                               //modification
void timer_init()
{
TCCR1B |= (1 << WGM12)|(1 << CS10)|(1 << CS11);
TIMSK |= (1 << OCIE1A);
TCNT1 = 0;
}
void timer_set()
{
OCR1A = 15624;
sei();
}
 
ISR(TIMER1_COMPA_vect)
{
//counter++;                                                //modification
if(counter == 60)
{
counter=0;
flag=1;
}
else
counter++;
}
 
int main()
{
DDRC = 0xFF; 
DDRD = 0xFF; 
timer_init(); 
timer_set();
while(1)
{
if(flag)                            //modification
{
PORTD = 0x80; 
_delay_ms(125); 
PORTD = 0x00; 
_delay_ms(125); 
PORTC=0x01; 
_delay_ms(125); 
PORTC = 0x00; 
_delay_ms(125); 
PORTC=0x02; 
_delay_ms(125); 
PORTC = 0x00; 
_delay_ms(125); 
PORTC=0x80; 
_delay_ms(125); 
PORTC = 0x00;
_delay_ms(125);             //modification
flag = 0;                          //modification
}
}
}

RSS Recent Posts

  • reviving old swordfish program but? May 18, 2026
  • Assistance locating a 'trail' camera gadget, please ? May 18, 2026
  • Projector focus circuit May 18, 2026
  • Relay question May 18, 2026
  • Phone Charger 5v to 12v May 17, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise