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.
sei(); // Enable interruptsdelay_cycles(20);cli(); // Disable interruptsservo_do_something();
sei(); // Enable interruptsrprintf("Hello, World! Read My Analog: %u\r\n", rangefinder);//output message to serial (use hyperterminal)delay_cycles(20);cli(); // Disable interruptsservo_do_something();
sei(); // Enable interruptsrprintf("Hello, World! Read My Analog: %u\r\n", rangefinder);//output message to serial (use hyperterminal)cli(); // Disable interruptsdelay_cycles(20);servo_do_something();
void delay_cycles(unsigned long int cycles) { while(cycles > 0) cycles--; }void servo_left(signed long int speed) { PORT_ON(PORTD, 7); delay_cycles(speed); PORT_OFF(PORTD, 0);//keep off }
Code: [Select]sei(); // Enable interruptsdelay_cycles(20);cli(); // Disable interruptsservo_do_something();Code: [Select]sei(); // Enable interruptsrprintf("Hello, World! Read My Analog: %u\r\n", rangefinder);//output message to serial (use hyperterminal)delay_cycles(20);cli(); // Disable interruptsservo_do_something();Code: [Select]sei(); // Enable interruptsrprintf("Hello, World! Read My Analog: %u\r\n", rangefinder);//output message to serial (use hyperterminal)cli(); // Disable interruptsdelay_cycles(20);servo_do_something();Code: [Select]void delay_cycles(unsigned long int cycles) { while(cycles > 0) cycles--; }void servo_left(signed long int speed) { PORT_ON(PORTD, 7); delay_cycles(speed); PORT_OFF(PORTD, 0);//keep off }
You might be using the same timer/counter for the UART and your servo control. You might want to use one for UART and one for the servo controls.
void servo_left(signed long int speed) { PORT_ON(PORTD, 7); delay_cycles(speed); PORT_OFF(PORTD, 0);//keep off change to PORT_OFF(PORTD, 7) ???? }
2nd guess. Now I am looking at the Photovore code. I am assuming this is the base of most of your code.In your code you are using PD0 and PD1 as the servo port BUT for an ATmega8 (and ATmega16) those ports are also the ones for RXD and TXD respectively. That is bad!
//************CONFIGURE PORTS************//configure ports for input or output - specific to ATmega8void configure_ports(void) { DDRC = 0x00; //configure all C ports for input PORTC = 0x00; //make sure pull-up resistors are turned off DDRD = 0xFF; //configure all D ports for output DDRB = 0xC7; //configure B ports 0, 1, 2, 6, 7 for output (google search '0b11000111 to hex') }//***************************************
3rd guess. If you caught #2 above then you have a bug. Look at "PORT_OFF(PORTD, 0)" should it be "PORT_OFF(PORTD, 7)" instead???
Im not that dumb! Nothing is connected to the TX/RX pins and Im not telling the pins to do anything in software.
This is the only code that touches those pins:Code: [Select]//************CONFIGURE PORTS************//configure ports for input or output - specific to ATmega8void configure_ports(void) { DDRC = 0x00; //configure all C ports for input PORTC = 0x00; //make sure pull-up resistors are turned off DDRD = 0xFF; //configure all D ports for output DDRB = 0xC7; //configure B ports 0, 1, 2, 6, 7 for output (google search '0b11000111 to hex') }//***************************************
Which servos are behaving erratically? To which specific ports are they connected?
I didnt try all ports, but I am current using D4, B6, and B7. Each have the same problem.
XCK, USART external clock.T0, Timer/Counter0 counter source.PCINT20: Pin Change Interrupt source 20. The PD4 pin can serve as an external interrupt source.
XTAL1: Chip clock Oscillator pin 1. Used for all chip clock sources except internal calibrated RC Oscillator. When used as a clock pin, the pin can not be used as an I/O pin.TOSC1: Timer Oscillator pin 1. Used only if internal calibrated RC Oscillator is selected as chip clock source, and the asynchronous timer is enabled by the correct setting in ASSR. When the AS2 bit in ASSR is set (one) to enable asynchronous clocking of Timer/Counter2, pin PB6 is disconnected from the port, and becomes the input of the inverting Oscillator amplifier. In this mode, a crystal Oscillator is connected to this pin, and the pin can not be used as an I/O pin.PCINT6: Pin Change Interrupt source 6. The PB6 pin can serve as an external interrupt source. If PB6 is used as a clock pin, DDB6, PORTB6 and PINB6 will all read 0.
XTAL2: Chip clock Oscillator pin 2. Used as clock pin for crystal Oscillator or Low-frequency crystal Oscillator. When used as a clock pin, the pin can not be used as an I/O pin.TOSC2: Timer Oscillator pin 2. Used only if internal calibrated RC Oscillator is selected as chip clock source, and the asynchronous timer is enabled by the correct setting in ASSR. When the AS2 bit in ASSR is set (one) and the EXCLK bit is cleared (zero) to enable asynchronous clocking of Timer/Counter2 using the Crystal Oscillator, pin PB7 is disconnected from the port, and becomes the inverting output of the Oscillator amplifier. In this mode, a crystal Oscillator is con nected to this pin, and the pin cannot be used as an I/O pin.PCINT7: Pin Change Interrupt source 7. The PB7 pin can serve as an external interrupt source. If PB7 is used as a clock pin, DDB7, PORTB7 and PINB7 will all read 0.