Society of Robots - Robot Forum
Software => Software => Topic started by: Deruty on July 28, 2009, 02:08:11 PM
-
I'm using the basis of the $50 Robot and revising it to my own project.
Currently I'm trying to build a timer of sorts, but I'm having a heck of time doing it.
I tried using a loop of 30 w/ a delay_cycles(65000) in order to make a 2.5 minute timer, but it doesn't appear to work.
Frankly nothing "delay_cycles()" based seems to be working. I may just simply not understand how it is supposed to operate.
Furthermore I tried an alternative method counting the overflow from timer0 but it doesn't appear to be changing from 0 at all.
/****************INITIALIZATIONS*******************/
//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");
/**************************************************/
/*********ADD YOUR CODE BELOW THIS LINE **********/
LED_on();//turn LED on
Beep_off();
timer0Init();
while(1)
{
timecycles=timer0GetOverflowCount();
if(timecycles>= 1)
{
Beep_on();
}
else
{
delay_cycles(200);
}
}
return 0;
}
I really don't know what I'm doing when it comes to using timer and I swear the delay cycles don't work! I even tried the method demonstrated in the cycles and timing section on the main page (the LED w/ delay cycles between on and off port switching)
So if someone could explain how to do this and clarify how delay_cycles works/what I'm doing wrong w/ it that would be great.
-
try including the delay header file
#include <delay.h>
then you can use the delay_ms() function. it takes input in milliseconds
exampe, if you wanted to delay 10 seconds:
delay_ms(10000);
i found this here: http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=43054
but, i've used delay ms before, you can google for more info about delay_ms and avr
-
Ahh thanks. I didn't know there was a difference. That really helped :)
-
no problem, generally when i can't figure out something programming wise i just type it into google with some keywords
for example, in this case, i would type "avr time delay" or something like that
-
Well I did do that, but I had just assumed delay_ms was synonymous w/ delay_cycles and delay_us. Then I searched more and got stuff w/ Timer0, Timer1, and Timer2 <_< made it all more confusing than it really was.
Anyway thanks again. I'll be sure to check everything more indepth than I did this time.
-
That's fine, you had a legitimate question and you were confused by the answers you had found online. We are here to answer you questions, don't mean to deter them :P
Glad I could help though.
-
Could you help w/ 1 more problem :)?
I want to change PORTC pins from the $50 robot tutorial to digital input versus analog input. I know it has something to do w/ void 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')
}but frankly I can't make heads or tails of how to alter that. I know I need to make sure the pull-up resistors are turned on, but... I don't know how to alter that command. Also I've seen code like this #define F_CPU 8000000UL /* 8MHz crystal oscillator */
#define BUTTON_PORT PORTD /* PORTx - register for button output */
#define BUTTON_PIN PIND /* PINx - register for button input */
#define BUTTON_BIT PD2 /* bit for button input/output */
which I can only deduce is a different method of altering the it. The question of the hour now is, how do I turn on the pull-up resistor, can I just comment out the PORTC=0x00 and put PORTC|=_BV(#of pin), albeit I'll have to do that several times. Another way I see is finding the hex number that would do that, but it seems rather ambiguous and I have no idea what to search for that. Also is there a step I'm missing?
Also a link to a tutorial would also be nice, one that specifically deals w/ this since I've found several but they only mention and show how to do it once, w/o much explanation.
EDIT: NVM I think I figured it out, but a nice link to a tutorial site would be nice. A recommended one, since I can't tell which ones are good atm >_>
-
if you have any tutorials you looked at you could post them and i could tell you which one i thought was better?
-
I've mainly used this guy's tutorial so far. It seems good. http://www.micahcarrick.com/05-15-2006/avr-tutorial-switch-debounce.html
-
a quick browse i'd agree with you, he seems to go into detail and thoroughly explain things (which is good for you)