Squirrels have fuzzy tails.
0 Members and 1 Guest are viewing this topic.
while(1) { wheel_left(30); delay_ms(20); }
#include "SoR_Utils.h"int main(void){initialize();//printf("TEST!\n");//cbi(PORTD,PD4);//LED_on();//delay_cycles(500); while(1) { LED_on(); //PORTD = 0xFF; //servo_left(35); //delay_cycles(20); // robot_turn_left();// delay_cycles(500);// robot_turn_right();// delay_cycles(500);// robot_go_straight();// delay_cycles(500);// servo_right(32);// delay_cycles(500);// servo_scan(33); }return 0;}
/****************************************************************************** Copyright (c) 2007 www.societyofrobots.com[url=http://][/url]* (please link back if you use this code!)** This program is free software; you can redistribute it and/or modify* it under the terms of the GNU General Public License version 2 as* published by the Free Software Foundation.** Alternatively, this software may be distributed under the terms of BSD* license.** SoR Utilities v1, March 10th, 2007*****************************************************************************///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#include "buffer.h" // include buffer function library#include "uart.h" // include uart function library#include "rprintf.h" // include printf function library#include "timerx8.h" // include timer function library (timing, PWM, etc)#include "a2d.h" // include A/D converter function library//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)#define PORT_ALL_ON( port_letter, number ) port_letter |= (number)#define PORT_ALL_OFF( port_letter, number ) port_letter &= ~(number)#define FLIP_PORT( port_letter, number ) port_letter ^= (1<<number)#define PORT_IS_ON( port_letter, number ) ( port_letter & (1<<number) )#define PORT_IS_OFF( port_letter, number ) !( port_letter & (1<<number) )//************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 }//***************************************//************DELAY FUNCTIONS************//wait for X amount of cycles (23 cycles is about .992 milliseconds)//to calculate: 23/.992*(time in milliseconds) = number of cycles//or (number of cycles)*.992/23 = time in millisecondsvoid delay_cycles(unsigned long int cycles) { while(cycles > 0) cycles--; }//***************************************//*********SIMPLIFIED FUNCTIONS**********//functions to make coding easier for a beginner//but could cause port mixup confusion for intermediate usersvoid LED_on(void) { PORT_OFF(PORTD, 4);//turn LED on }void LED_off(void) { PORT_ON(PORTD, 4);//turn LED off }void servo_left(signed long int speed) { PORT_ON(PORTD, 0); delay_cycles(speed); PORT_OFF(PORTD, 0);//keep off delay_cycles(200); }void servo_right(signed long int speed) { PORT_ON(PORTD, 1); delay_cycles(speed); PORT_OFF(PORTD, 1);//keep off delay_cycles(200); }void servo_scan(signed long int speed) { PORT_ON(PORTD, 2); delay_cycles(speed); PORT_OFF(PORTD, 2);//keep off delay_cycles(200); }void robot_turn_left(void) { servo_left(25); servo_right(25); }void robot_turn_right(void) { servo_left(44); servo_right(44); }void robot_go_straight(void) { servo_left(25); servo_right(44); }void hold_position(void)//37 { servo_left(39);//39 servo_right(35);//35 }//***************************************//*************INITIALIZATIONS***********void initialize(void) { //other stuff Im experimenting with for SoR //uartInit(); // initialize the UART (serial port) //uartSetBaudRate(9600);// set the baud rate of the UART for our debug/reporting output //rprintfInit(uartSendByte);// initialize rprintf system //timerInit(); // initialize the timer system configure_ports(); // configure which ports are analog, digital, etc. a2dInit(); // initialize analog to digital converter (ADC) a2dSetPrescaler(ADC_PRESCALE_DIV32); // configure ADC scaling a2dSetReference(ADC_REFERENCE_AVCC); // configure ADC reference voltage //rprintf("Initialization Complete\r\n"); }//****************************************
void LED_on(void) { PORT_ON(PORTD, 4);//turn LED on }
void LED_off(void) { PORT_OFF(PORTD, 4);//turn LED off }
/****************************************************************************** Copyright (c) 2007 www.societyofrobots.com[url=http://][/url][url=http://][/url]* (please link back if you use this code!)** This program is free software; you can redistribute it and/or modify* it under the terms of the GNU General Public License version 2 as* published by the Free Software Foundation.** Alternatively, this software may be distributed under the terms of BSD* license.** SoR Utilities v1, March 10th, 2007*****************************************************************************///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#include "buffer.h" // include buffer function library//#include "uart.h" // include uart function library//#include "rprintf.h" // include printf function library//#include "timerx8.h" // include timer function library (timing, PWM, etc)#include "a2d.h" // include A/D converter function library//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)#define PORT_ALL_ON( port_letter, number ) port_letter |= (number)#define PORT_ALL_OFF( port_letter, number ) port_letter &= ~(number)#define FLIP_PORT( port_letter, number ) port_letter ^= (1<<number)#define PORT_IS_ON( port_letter, number ) ( port_letter & (1<<number) )#define PORT_IS_OFF( port_letter, number ) !( port_letter & (1<<number) )//************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 }//***************************************//************DELAY FUNCTIONS************//wait for X amount of cycles (23 cycles is about .992 milliseconds)//to calculate: 23/.992*(time in milliseconds) = number of cycles//or (number of cycles)*.992/23 = time in millisecondsvoid delay_cycles(unsigned long int cycles) { while(cycles > 0) cycles--; }//***************************************//*********SIMPLIFIED FUNCTIONS**********//functions to make coding easier for a beginner//but could cause port mixup confusion for intermediate usersvoid LED_on(void) { PORT_ON(PORTD, 4);//turn LED on }void LED_off(void) { PORT_OFF(PORTD, 4);//turn LED off }void servo_left(signed long int speed) { PORT_ON(PORTD, 0); delay_cycles(speed); PORT_OFF(PORTD, 0);//keep off delay_cycles(200); }void servo_right(signed long int speed) { PORT_ON(PORTD, 1); delay_cycles(speed); PORT_OFF(PORTD, 1);//keep off delay_cycles(200); }void servo_scan(signed long int speed) { PORT_ON(PORTD, 2); delay_cycles(speed); PORT_OFF(PORTD, 2);//keep off delay_cycles(200); }void robot_turn_left(void) { servo_left(25); servo_right(25); }void robot_turn_right(void) { servo_left(44); servo_right(44); }void robot_go_straight(void) { servo_left(25); servo_right(44); }void hold_position(void)//37 { servo_left(39);//39 servo_right(35);//35 }//***************************************//*************INITIALIZATIONS***********void initialize(void) { //other stuff Im experimenting with for SoR //uartInit(); // initialize the UART (serial port) //uartSetBaudRate(9600);// set the baud rate of the UART for our debug/reporting output //rprintfInit(uartSendByte);// initialize rprintf system //timerInit(); // initialize the timer system configure_ports(); // configure which ports are analog, digital, etc. a2dInit(); // initialize analog to digital converter (ADC) a2dSetPrescaler(ADC_PRESCALE_DIV32); // configure ADC scaling a2dSetReference(ADC_REFERENCE_AVCC); // configure ADC reference voltage //rprintf("Initialization Complete\r\n"); }//****************************************
#include "SoR_Utils.h"int main(void) { initialize(); while(1) { LED_on(); robot_go_straight(); } // end whilereturn 0;} // end main
I know what you're saying, but if you look at the schematic for the robot http://www.societyofrobots.com/images/sbs_avr_schematic.pngor my attachment, you see that the LED is connected directly to the supply voltage, and the other end is connected to a resistor which then connects to PD4
I apologize I see what your saying. That is an odd way to do it. OK well, the VCC is your 5v going directly to the LED, but the current is being limited by the resistor, and the PD4 needs to be 0vdc to act as a ground for it to light. If it were me I would wire the resistor to PD4, then the anode (long leg) of the LED to the resistor, and the cathode (short leg) to ground. That way all you need to do to turn on the LED is bring the pin high with PORT_ON
You should be able to recognize either way as valid, and the current sinking (low = on) as more common.
Can you reference this? I'd like to read more about it.
Quote from: GearMotion on April 04, 2009, 09:52:14 AMYou should be able to recognize either way as valid, and the current sinking (low = on) as more common.Can you reference this? I'd like to read more about it.
Also don't forget that the IO pin which the LED is connected to can also be used to drive other output devices so it may be required to source current for the LED plus the output device if it was cinfigured as 'pin high = on'. So Admins design appears the preferred route.
Quote from: Webbot on April 04, 2009, 12:33:22 PMAlso don't forget that the IO pin which the LED is connected to can also be used to drive other output devices so it may be required to source current for the LED plus the output device if it was cinfigured as 'pin high = on'. So Admins design appears the preferred route.I kinda lost you here....you're saying that if you use the pin to connect a servo, then everytime the pin gets pulsed, the LED will flash?btw...I was never able to get my LED workin on my $50 robot board.
Quote from: Webbot on April 04, 2009, 12:33:22 PMAlso don't forget that the IO pin which the LED is connected to can also be used to drive other output devices so it may be required to source current for the LED plus the output device if it was cinfigured as 'pin high = on'. So Admins design appears the preferred route.I kinda lost you here....you're saying that if you use the pin to connect a servo, then everytime the pin gets pulsed, the LED will flash?
i guess it would? and if you got your led from the place that admin said it may be connected backwards as there was a polarity problem with them. there is a recent thread on this if you want to look it up.
Quotei guess it would? and if you got your led from the place that admin said it may be connected backwards as there was a polarity problem with them. there is a recent thread on this if you want to look it up.That's this thread!