-1

i'm working on a school project "automatic railway system" my project suppose to close the gate when the train coming to the station with a buzzer on with 90 sec count down display on 7-seg. and a led flashing. after the train leaving the station, the gate opens and the buzzer off and the led off . i tried to use a dc motor to open and close the gate but it didn't give me the accurate angle that i need to i try to use a servo motor . so i need it to open the gate at position zero and close it at position 90 . all the code i found on the internet they using PWM and timers which i didn't take it in my course , so can anyone help me to do this with simple code ,please ?

i'm using Atmega32 running at 16000000 HZ

Sara Gero
  • 1
  • 2
  • 1
    Servo motors require PWM to operate. You can use the built-in PWM, or you can use interrupts to turn the pin on and off at the correct rate yourself. Search the web or Stack Overflow for example code and tutorials. Don't ask such a broad question here. – UncleO Sep 29 '16 at 20:39
  • Thanks ,, I will try to understand pwm and using it in my project – Sara Gero Sep 30 '16 at 06:38

1 Answers1

1

Its depend on your analog servo (which is controlled by PWM) frequency specification. After you learn about the servo specification, you can set your PWM using build-in features on cvavr compiler, or you can do some research about PWM registers.
Here is some example of PWM setup

//using OC0 (B.3)
DDRB.3 = 1; //set B.3 as output
TCCR0=0b0111 0001;
TCNT0=0; //set to Phase Correct PWM mode, no prescaler, and inverted output

//to assign a value to your PWM
OCR0 = 127 //50% duty cycle since it was 8 bit
duck
  • 369
  • 3
  • 17