Author Topic: Algorithm shouldn't stop, but he does (poker,sex, drugs, rock'n'roll, guns, fun)  (Read 2476 times)

0 Members and 1 Guest are viewing this topic.

Offline PAT_McUserTopic starter

  • Jr. Member
  • **
  • Posts: 32
  • Helpful? 1
  • I just started with robitic.
hi again.
Dear reader if you are afraid of poker-, sex-, drugs-, rock'n'roll-, guns- and/or fun-stuff you might be in the wrong forum...
...but if there is anyone interested in roboticsstuff this is a interesting problem:
I have a tiny program that reads the Data of a I2C Device (look at my last threat for further information:http://www.societyofrobots.com/robotforum/index.php?topic=11173.0).
Everything is like expected, but the programm stops after the seventh call of the i2c_LF.
Why does the algorithm stop? It should run with infinity method calls.
Maybe you can sea the problem, here my code

my control.c
Code: [Select]
/****************************************************************************
*
*   Copyright (c) 2008 [url=http://www.societyofrobots.com]www.societyofrobots.com[/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.
*
****************************************************************************/

#include "pwm.c"
#include "test.c"
#include "beeper.c"

void control(void)
{
//rprintfInit(uart1SendByte); //sets rprintf to USB (for terminal)
//rprintf("\r\nStartup Aplication\n");
configure_ports();
LED_on();
while(1)
{
//...

//test Line Following
LF_test();

}
}

my addition to sensors.c

Code: [Select]
//...
/***************I2C Devices*******************/

//I2C Line Following Sensor Array
#define ADDR 0x50
#define BUFFSIZE 0x01
int i2c_LF(void)
{
volatile u08 readbuffer=0x00;
volatile u08 databuffer = 0;
i2cMasterSend(ADDR, 0x01, &databuffer);
i2cMasterReceive(ADDR, BUFFSIZE, &readbuffer);
return readbuffer;
}
//...

my test.c

Code: [Select]
//...
void LF_test(void)
{
int a=0;
u08 r=0x00;
for(a=0;a<5;a++)
{
r=i2c_LF();
rprintf("\r\n Line Following: %d",r);
delay_ms(100);
}
}
//...

my Axon.c (the myterious main ;-) )

Code: [Select]
/****************************************************************************
*
*   Copyright (c) 2008 [url=http://www.societyofrobots.com]www.societyofrobots.com[/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 Include
#include "SoR_Utils.h" //includes all the technical stuff
#include "hardware.c" //declare hardware variables and ports
#include "sensors.c" //sensor libraries for sonar, sharp IR, etc.
#include "misc.c" //includes libraries for various hardware and other useful stuff
#include "axon_DAQ.c" //use the Axon like a data acquisition device
#include "control.c" //your code goes in here
#include <string.h>
#include "laser.c"
#include "i2c.h"
#include "i2c.c"



int main(void)
{
//declare variables here
int i=0;//useless variable
int j=0;//useless variable

//add 1.7s delay for potential power issues
delay_cycles(65535);
delay_cycles(65535);
delay_cycles(65535);
delay_cycles(65535);
delay_cycles(65535);
delay_cycles(65535);
delay_cycles(65535);

/****************INITIALIZATIONS*******************/
//other stuff Im experimenting with for SoR
uartInit();  // initialize the UART (serial port)
    uartSetBaudRate(0, 38400); // set UARTE speed, for Bluetooth
uartSetBaudRate(1, 115200); // set UARTD speed, for USB connection, up to 500k, try 115200 if it doesn't work
    //uartSetBaudRate(2, 19200);
uartSetBaudRate(2, 38400);
    uartSetBaudRate(3, 38400); // set UARTJ speed, for Blackfin
//G=Ground, T=Tx (connect to external Rx), R=Rx (connect to external Tx)

rprintfInit(uart1SendByte);// initialize rprintf system and configure uart1 (USB) for rprintf
//rprintfInit(uart2SendByte);//Sets UART2 as chosen in rprintf system

configure_ports(); // configure which ports are analog, digital, etc.

LED_on();

rprintf("\r\nSystem Warmed Up");

// initialize the timer system
  init_timer0(TIMER_CLK_1024);
  init_timer1(TIMER_CLK_64);
  init_timer2(TIMER2_CLK_64);
  init_timer3(TIMER_CLK_64);
  init_timer4(TIMER_CLK_64);
  init_timer5(TIMER_CLK_64);

a2dInit(); // initialize analog to digital converter (ADC)
a2dSetPrescaler(ADC_PRESCALE_DIV32); // configure ADC scaling
a2dSetReference(ADC_REFERENCE_AVCC); // configure ADC reference voltage

//let system stabelize for X time
for(i=0;i<16;i++)
{
j=a2dConvert8bit(i);//read each ADC once to get it working accurately
delay_cycles(5000); //keep LED on long enough to see Axon reseting
rprintf(".");
}

LED_off();
LASER_off();
i2cInit();
//i2cSetBitrate(100);
//i2cSetLocalDeviceAddr(0x42,TRUE);

rprintf("Initialization Complete \r\n");

/**************************************************/

//wait until user pushes button
rprintf("Waiting for Input \r\n");
while(!button_pressed());

//reset all timers to zero
reset_timer0();
reset_timer1();
reset_timer2();
reset_timer3();
reset_timer4();
reset_timer5();

while(1)
{
control();//uncomment this for your code (and use control.c only to program)
delay_cycles(100);//an optional small delay to prevent crazy oscillations
}
return 0;
}
« Last Edit: May 18, 2010, 06:16:32 AM by PAT_McUser »
I just started with robitic.

PS.: you have to sorry my bad english.

Offline little-c

  • Robot Overlord
  • ****
  • Posts: 186
  • Helpful? 1
so this is

 making the first 5 calls to i2c_LF on the first call to control function
 finishes the control function
 delays
 loops,
 enters the control function
 then makes two calls to i2c
 crashes.


correct?

the only things I can possibly come up with are

 dud conections on the PCB
 issues with the other i2c device not working
 source files having bugs or been acidently modified.

my best advice is check the wires, and rewrite the code with a fresh copy of the source files. if that fails, I can't see the problem.

Offline PAT_McUserTopic starter

  • Jr. Member
  • **
  • Posts: 32
  • Helpful? 1
  • I just started with robitic.
so this is

 making the first 5 calls to i2c_LF on the first call to control function
 finishes the control function
 delays
 loops,
 enters the control function
 then makes two calls to i2c
 crashes.


correct?
yes...
the only things I can possibly come up with are

 dud connections on the PCB
If there's something wrong with the connections, it wouldn't work exact seven times (at each start of the robot).
issues with the other i2c device not working
I don't think so, because it works seven times before it fails, if there is a HW problem with the foreign device it would manifest at its first call.
(It's cheaper to print a chip which has one hardware function than to produce a chip that has the same HW-funktion seven a times (think to a Moore-/Mealy-Machine; you wouldn't put 7 in a row, you would turn the end- to a start-state))
source files having bugs or been acidently modified.
I exchanged the source files , same problem (with the I2C code I have still some issues, for example: Why I have to add the i2c.c into the AXON.c when I want to get ride of these "undefined reference to ..." errors.)
my best advice is check the wires, and rewrite the code with a fresh copy of the source files.
Wires are connected and not broken (nothing moves at the wires and the same behavior comes even the wires wouldn't touched), code is OK (I used eclipse and AVR Studio 4 to verify and several people read it and couldn't find some mistakes).
if that fails, I can't see the problem.
I know this is a strange problem.
Okay thanks for your help, but it's not the final solution of my problem.
« Last Edit: May 17, 2010, 04:45:33 AM by PAT_McUser »
I just started with robitic.

PS.: you have to sorry my bad english.

Offline PAT_McUserTopic starter

  • Jr. Member
  • **
  • Posts: 32
  • Helpful? 1
  • I just started with robitic.
Okay I solved this problem. I had to do strange things with the code and I don't understand what I've done but by changing the method

Code: [Select]
i2cMasterReceive(ADDR, BUFFSIZE, &readbuffer);
to

Code: [Select]
i2cMasterReceiveNI(ADDR, BUFFSIZE, &readbuffer);
I'm able to call the data as much as I want. (i2c.c and i2c.h are the standart of the AVR Source.)
If someone can explain that is going on, please do that.

Here the code which I have added to the sensors.c for supporting the "RoboticConnections.com i2c line following sensor":

Code: [Select]
#define ADDR 0x50
#define BUFFSIZE 0x01
u08 i2c_LF(void)
{
i2cInit();
volatile u08 readbuffer=0x00;
volatile u08 databuffer = 0;
i2cMasterSend(ADDR, 0x01, databuffer);
i2cMasterReceiveNI(ADDR, BUFFSIZE, &readbuffer);
return readbuffer;

}
I just started with robitic.

PS.: you have to sorry my bad english.

 


Get Your Ad Here