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 / /* Here is the actual Working

/* Here is the actual Working

|

Microcontroller › AVR › Servo Program Using TIMER0 › /* Here is the actual Working

April 2, 2013 at 6:08 pm #9422
BhanuKiran Chaluvadi
Participant

/* Here is the actual Working Progam, Controlling Servo Using TIMER0 . SO that we can  use Timer1 for other Purpose */

 

 

#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
 
volatile uint8_t tot_overflow;
 
void timer0_init()
{
TCCR0  |= (1<<WGM01) | (1<<WGM00) | (1<<CS02) ; // Fast PWM CTC mode, Prescaling of 256
 
TCNT0 = 0 ;
OCR0 = 249;
TIMSK  |= (1<<OCIE0) ;
sei();
}
 
ISR (TIMER0_COMP_vect)
{
tot_overflow++;
if(tot_overflow==5)
{
PORTA |= (1<<PA0) | (1<<PA1) | (1<<PA2) ;
tot_overflow=0;
}
 
}
 
int main (void)
{
DDRA |= (1<<PA0) | (1<<PA1) | (1<<PA2) ;
timer0_init();
  tot_overflow=0;
while(1)
{
if (TCNT0>=15 && TCNT0<=145 && tot_overflow==0)
{
if (TCNT0 >= 23 && bit_is_set(PORTA, PINA0)  ) PORTA &= ~(1<<PINA0);
if (TCNT0 >= 78 && bit_is_set(PORTA, PINA1)  ) PORTA &= ~(1<<PINA1);
if (TCNT0 >= 133 && bit_is_set(PORTA, PINA2) ) PORTA &= ~(1<<PINA2);
 
}
}
 
}

RSS Recent Posts

  • Failure of polypropylene motor-run capacitors June 16, 2025
  • Siemens large industrial PLC parts June 16, 2025
  • Wideband matching an electrically short bowtie antenna; 50 ohm, 434 MHz June 16, 2025
  • Curved lines in PCB design June 16, 2025
  • using a RTC in SF basic June 15, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 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