Society of Robots - Robot Forum
Software => Software => Topic started by: Speed on October 25, 2011, 09:59:52 AM
-
Hey guys, i'm starting a little project involving an atmega8 uC .. I'm bogged down by a problem, the uC either jammes while executing the code, or starting the code over( just like when it's powered up ).
I've ran out of idears, and i'm hoping a little common brain storming might lead to a fix
Technical deteails:
-ATMega8 using internal oscillator at 1 MHz
-C and ASM code debugs ok in AVR Studio 4 simulator
-I'm using avrdude to load the .hex file through parallel port
-winavr libs and defs (io.h , interrupt.h ) and a few nice headers from the $50 buks robot sorce code (uart.h, rprintf.h, buffer.h and global.h)
-attatched C code
Any help would be much apreciated !
PS: the wiii() function only has a no operation instruction (nop)
-
Edit, sorry I was looking at the wrong thing when I responded.
Just a couple things
I'm not sure why you're declaring things volatile the way you are. The volatile keyword is used to tell the compiler not to pull any optimizing tricks with the variable being declared. It's used when a variable is shared between the main loop and interrupt service routines. In particular, main() shouldn't be declared volatile, it's not a variable.
What do you mean by "jammes" (jams I guess). What do you see on the display?
What do you expect to happen that isn't?
Joe
-
I know that, ignore the volatile keyword ... I put them there form lack of inspiration(thought something might be going wrong when optimizing the code). Anyway, it doesen't matter if i declare stuff volatile or not, the problem is just the same.
The uC either starts over form the 1st instructin or it gets stuck (just after turning on PORTC 4)
I'm not sure waht display you're talking about. The only debug i can do on the uC is with a voltmeter, checking actual pin states in report to what the should be after a given commend.
I have a test board with the uC, parallel programmer, a L297 chip mounted and 2 test LEDs.
I want/expect the uC to turn on/off PC4 to generate a clock signal that feeds into the L297 chip, activate 2 ports(PC5 and PC0) giving me 5V, and upon reciving the 'a' character from my laptop, i want a port to switch from on to off, and vice versa.
So far, it executes what i programmed it to do. It runs through the 2nd infinite loop for only 0.5 seconds or 10 second max, the infinite loop deosen't execut forever as it shoul, after x ammount of time it starts over or gets stuck.
I've attached the cleaned up version of the code... And pardon my english, it might not be as shapr as it used to....
-
I'm not sure waht display you're talking about. The only debug i can do on the uC is with a voltmeter, checking actual pin states in report to what the should be after a given commend.
I have a test board with the uC, parallel programmer, a L297 chip mounted and 2 test LEDs.
It looks like you're printing the word "GO" at one point, so I assumed that was going to some display that you could read. If so, does that stop showing up?
I want/expect the uC to turn on/off PC4 to generate a clock signal that feeds into the L297 chip, activate 2 ports(PC5 and PC0) giving me 5V, and upon reciving the 'a' character from my laptop, i want a port to switch from on to off, and vice versa.
When you say "port" I take it you mean "pin", since you're only manipulating one bit?
So far, it executes what i programmed it to do. It runs through the 2nd infinite loop for only 0.5 seconds or 10 second max, the infinite loop deosen't execut forever as it shoul, after x ammount of time it starts over or gets stuck.
How do you know it starts over? I'm not trying to be a pain about this, but I'm trying to imagine what you're seeing, and it would be easier if you could describe it exactly.
If you can print to a display, you might try adding some debug output to show where the program is getting stuck.
Joe
-
It's a little console application i wrote, press a button on the keyboard to get the uC started( and by started i mean go in the 2nd loop where i flip PIN C4 ,as you call it, on and off).
int main(void){
configure_ports();
uartInit();
uartSetBaudRate(4800);
rprintfInit(uartSendByte);
PORT_ON(PORTC,5);
PORT_ON(PORTC,0);
char f=0;
unsigned long int d=35;
rprintf("Device READY!\n");
while(1){
f=uartGetByte();
if(f==103){
rprintf("GO!\n");
while(1){
PORT_ON(PORTC,4);
rprintf("a\n");
f=uartGetByte();
rprintf("b\n");
delay(d);
PORT_OFF(PORTC,4);
if(f==97)
sens();
}
}
}
return 0;
}The uC will start executing the program, print out "Device READY!" on my consone, wait for me to press the 'g' key,print "GO!", prints the 'a' and 'b' test charactersand and after running for let's say 1 second, it will:
-print some random characters and them reprint "Device READY!"
or
-print some random character and PC4 will be ON
Because of the random characters, i can't see any pattern so i can't pin point the instruction that is causing the problem
-
Can you show us the code for the console app?
-
FINALLY FIXED ! After a bot of brain storming with someone, we concluded the the problem came from a power spike!
An aditional capacitor fixed the problem !
I had to use a PC power source that needed an aditional filter, if i'd used a laboratorty power source i wouldn't have had this problem for almost 2 months...
If you waht the source code for the console api i'll uploadit it
Thanks everyone for the support !