Don't ad-block us - support your favorite websites. We have safe, unobstrusive, robotics related ads that you actually want to see - see here for more.
0 Members and 1 Guest are viewing this topic.
#include <avr/io.h>#include <util/delay.h>void main(void){ DDRB = 0xFF; while (1) { PORTB = 0xFF; _delay_us(1500); //Also tried _delay_ms(1.5); PORTB = 0x00; _delay_ms(20); // Tried from 10 ms to 20 ms, but still results are the same }}
Anybody help...I have also tried the code below. After uploading the hex file, it slows down at a particular position, but just keeps vibrating.
Admin's .hex file stops exactly without any movement and the very reason I need to use that code. I need to do this for a college project and hence need to document the code I use and so cannot just use the .hex file from admin.
You might have to adjust the potentiometer. There should be a little screw showing somewhere on the servo. Adjust that until it stops.
I suspect he's using a timer to produce the correct pulses. That's a better way to do it than a manual timing loop. Take a look at http://www.societyofrobots.com/member_tutorials/node/228 for how to do this kind of thing. I think it will have the answers you're looking for. It has an example of driving a servo.
I am not sure if he uses timer. Admin has used PD0 and PD1 whereas the timer pins are PB0 and PB1. Not sure if we can use timer for other pins.
Take a look at the tutorial I mentioned last time
QuoteTake a look at the tutorial I mentioned last timeI did go through that tutorial. It uses timer and the pins used are PB1 and PB2 pins. That is the reason I do not want it
Maybe if you could explain more fully what you actually want to do it would be easier to help.
Thanks for your patience. Also, to make it clear, I am not looking for other options as I am aware of other options. I just need to use the same specific or equivalent code which admin has used, and understand how it works. I may be stubborn, but I love learning like this.
//AVR includes#include <avr/io.h> // include I/O definitions (port names, pin names, etc)#include <avr/interrupt.h> // include interrupt support//AVRlib includes#include "global.h" // include global settings//define port functions; example: PORT_ON( PORTD, 6 );#define PORT_ON( port_letter, number ) port_letter |= (1<<number)#define PORT_OFF( port_letter, number ) port_letter &= ~(1<<number)//************DELAY FUNCTIONS************//wait for X amount of cycles (23 cycles is about .992 milliseconds)//to calculate: 23/.992*(time in milliseconds) = number of cyclesvoid delay_cycles(unsigned long int cycles) { while(cycles > 0) cycles--; }//***************************************//*********hold servo********************void hold_servo(signed long int speed) { PORT_ON(PORTD, 0); delay_cycles(speed); PORT_OFF(PORTD, 0); delay_cycles(200); }//***************************************int main(void) { DDRD = 0xFF; //configure all D ports for output while(1) { //hold servo hold_servo(34.7782); } return 0; }
hold_servo(34.7782);