Author Topic: AXON Questions  (Read 2640 times)

0 Members and 1 Guest are viewing this topic.

Offline MagnusTopic starter

  • Jr. Member
  • **
  • Posts: 30
  • Helpful? 0
AXON Questions
« on: November 08, 2009, 08:25:39 PM »
Hello,

OK....so I have gone through Admin's tutorial on the AXON and have compiled and loaded the code to my AXON. It compiled with no errors and shows that it was successful. Here come the questions:

What is the hardware.c file? What is it used for? What do I do with it?
What is the makefile?What is it used for? What do I do with it?
What am I supposed to do with the "projectname".c file? Do I just leave it alone?
Do I delete what's in the control.c folder and put code that I write there?
Can someone please give me an example code of how to use one of the ports to light an L.E.D. (so I know the Axon is working)?
« Last Edit: November 11, 2009, 11:09:10 AM by Magnus »

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Beginner needs help
« Reply #1 on: November 08, 2009, 10:21:02 PM »
Quote
What is the hardware.c file? What is it used for? What do I do with it?
You define pin locations of your electronics. For example:
http://www.societyofrobots.com/axon/axon_function_list.shtml#hardware_defines

Quote
What is the makefile?What is it used for? What do I do with it?
Yea, just leave it alone. It just tells the compiler how to compile your code.

Quote
What am I supposed to do with the "projectname".c file? Do I just leave it alone?
Yeap, just leave it alone.

Quote
Do I delete what's in the control.c folder and put code that I write there?
Kinda. Its an example to help you figure out how to program the Axon. Try to figure out how it works before writing your own code.

Quote
Can someone please give me an example code of how to use one of the ports to light an L.E.D. (so I know the Axon is working)?
http://www.societyofrobots.com/axon/axon_function_list.shtml#led_button

Offline MagnusTopic starter

  • Jr. Member
  • **
  • Posts: 30
  • Helpful? 0
Re: Beginner needs help
« Reply #2 on: November 09, 2009, 09:03:03 PM »
Yea I know that turns the L.E.D. on but, that is not all the code is it?. I am a complete beginner at this. I am not sure what comes before or after that line. Would it be like this:

main()
{
LED_on();
return 0;
}
I erased everything in the control.c file and typed this in then compiled it.
It does not compile without errors.
When I tried the tutorial example, it says it loaded OK but, I don't have any sensors or servos to plug up just yet.
I do have L.E.D.'s that I can try.
I would just like to see the exact code from start to finish so I can confirm my axon will run a program and see results.
Then I can settle in and start learning to code.

I am trying to locate a good book so I can begin learning to program.

Thanks for your help.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: AXON Questions
« Reply #3 on: November 11, 2009, 03:21:30 PM »
The best way for us to help you with errors is:
1) read all the comments in the code to understand it
2) search the error on google
3) if no luck, post it here, with relevant code


Erasing all of the code in control.c will cause your errors. You can't just delete everything :P

So in control.c, you need at minimum to have:
Code: [Select]
void control(void)
{
}

If you want to blink an LED, do this:
Code: [Select]
void control(void)
{
while(1)
{
LED_on();  //turn green LED on
delay_ms(1000);
LED_off(); //turn green LED off
delay_ms(1000);
}
}

Offline MagnusTopic starter

  • Jr. Member
  • **
  • Posts: 30
  • Helpful? 0
Re: AXON Questions
« Reply #4 on: November 11, 2009, 06:16:42 PM »
First of all the green L.E.D. blinks once every time I try to load the axon with the code from your tutorial and it shows that it was successful. Does the L.E.D. always blink once when you do a load?


OK, I copied your code to blink the L.E.D. and pasted it into control.c
When I compile and do the build this is what it says:

Compiling: control.c
avr-gcc -c -mmcu=atmega640 -I. -gstabs   -O0 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=control.lst  -std=gnu99 -Wp,-M,-MP,-MT,control.o,-MF,.dep/control.o.d control.c -o control.o
control.c:7: warning: implicit declaration of function 'LED_on'
control.c:8: warning: implicit declaration of function 'delay_ms'
control.c:9: warning: implicit declaration of function 'LED_off'
Build succeeded with 3 Warnings...

If I try to compile just the code shown below ......without the LED statements:

void control(void)
   {
   
      
   }

It says build successful.
For grins I even tried loading just this to the axon and the L.E.D. still blinks one time.
So what am I doing wrong? ???

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: AXON Questions
« Reply #5 on: November 11, 2009, 06:40:01 PM »
Again, you can't just delete all the other code.

You are compiling only control.c when you should be compiling Axon.c as your primary file.

Load up the default code, and then try to compile. Then modify ONLY control.c and compile again.

Offline Razor Concepts

  • Supreme Robot
  • *****
  • Posts: 1,856
  • Helpful? 53
    • RazorConcepts
Re: AXON Questions
« Reply #6 on: November 11, 2009, 07:15:28 PM »
The single blink is indicating that the program is starting.

Offline MagnusTopic starter

  • Jr. Member
  • **
  • Posts: 30
  • Helpful? 0
Re: AXON Questions
« Reply #7 on: November 11, 2009, 09:11:47 PM »
My project file is called Robot.c. The tutorial said I could name it something else as long as I changed the line in the makefile.
I did not change or delete anything else in the hardware.c  or what was placed in the Robot.c file. The only file I changed was the control.c file. Right now this is what is in each file:

Robot.c

/****************************************************************************
*
*   Copyright (c) 2008 www.societyofrobots.com
*   (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 "CMUcam.c" //not yet written
#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 "Blackfin_Axon.c" //files for Blackfin Robot camera
#include "control.c" //your code goes in here
//#include "servo_controller.c" //Axon servo controller
//#include "axon_test.c" //include this is doing a function test for the Axon
//#include "axon_oscope_test.c" //include this is doing a function test for the Axon


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, 38400); // set UARTH speed
    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

   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();

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

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


//test programs
//while(1)
//{
//test_oscope();
//test();
//while(!button_pressed());

//PWM_Init_timer3_E3(8);
//PWM_timer3_On_E3();
//PWM_timer3_Set_E3(30);
//axon_DAQ();//activate the slow DAQ software (data acquisition), all 16 sensors, ~10ms resolution
//axon_DAQ_fast();//activate the super fast DAQ, only ADC pin 9, ~1ms resolution
//}
   
   /*********ADD YOUR CODE BELOW THIS LINE **********/

   //wait until user pushes button
   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)

      //servo_controller();

/*
PWM_Init_timer1_LED(8);
PWM_timer1_On_LED();
while(1)
   {
   for(i=90;i<255;i++)
      {
      PWM_timer1_Set_LED(i);
      delay_ms(10);
      }
   for(i=255;i>90;i--)
      {
      PWM_timer1_Set_LED(i);
      delay_ms(10);
      }
      rprintf("stuff\r\n");
   }

rprintf("Initializing timer2 for PWM\r\n");
PWM_Init_timer1_LED(8);
PWM_Init_timer2_H6(8);//9 doesn't work
PWM_Init_timer3_E3(8);
PWM_Init_timer3_E4(8);
PWM_Init_timer3_E5(8);
delay_ms(100);
rprintf("2");
//PWM_Init_timer4_H3(10);
delay_ms(100);
rprintf("3");
//PWM_Init_timer4_H4(10);
delay_ms(100);
rprintf("4");
//PWM_Init_timer4_H5(10);
delay_ms(100);
rprintf("5");

rprintf("Turning on both PWM channels\r\n");
PWM_timer1_On_LED();
PWM_timer2_On_H6();
PWM_timer3_On_E3();
PWM_timer3_On_E4();
PWM_timer3_On_E5();
PWM_timer4_On_H3();
PWM_timer4_On_H4();
PWM_timer4_On_H5();
delay_ms(1000);

rprintf("Setting PWM to 1%% duty cycle\r\n");
PWM_timer1_Set_LED(1);
PWM_timer2_Set_H6(1);
PWM_timer3_Set_E3(1);
PWM_timer3_Set_E4(1);
PWM_timer3_Set_E5(1);
PWM_timer4_Set_H3(1);
PWM_timer4_Set_H4(1);
PWM_timer4_Set_H5(1);
delay_ms(1000);

rprintf("Setting PWM to 50%% duty cycle\r\n");
PWM_timer1_Set_LED(127);
PWM_timer2_Set_H6(127);
PWM_timer3_Set_E3(127);
PWM_timer3_Set_E4(127);
PWM_timer3_Set_E5(127);
PWM_timer4_Set_H3(127);
PWM_timer4_Set_H4(127);
PWM_timer4_Set_H5(127);
delay_ms(1000);

rprintf("Setting PWM to 99%% duty cycle\r\n");
PWM_timer1_Set_LED(254);
PWM_timer2_Set_H6(254);
PWM_timer3_Set_E3(254);
PWM_timer3_Set_E4(254);
PWM_timer3_Set_E5(254);
PWM_timer4_Set_H3(254);
PWM_timer4_Set_H4(254);
PWM_timer4_Set_H5(254);
delay_ms(1000);

rprintf("Turning off PWM\r\n");
PWM_timer1_Off_LED();
PWM_timer2_Off_H6();
PWM_timer3_Off_E3();
PWM_timer3_Off_E4();
PWM_timer3_Off_E5();
PWM_timer4_Off_H3();
PWM_timer4_Off_H4();
PWM_timer4_Off_H5();
delay_ms(1000);
*/
      delay_cycles(100);//an optional small delay to prevent crazy oscillations
      }
   /*********ADD YOUR CODE ABOVE THIS LINE **********/

   return 0;
   }
----------------------------------------------------------------------------------------------------------------------------------------------------------
hardware.c

/****************************************************************************
*
*   Copyright (c) 2008 www.societyofrobots.com
*   (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 "CMUcam.c" //not yet written
#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 "Blackfin_Axon.c" //files for Blackfin Robot camera
#include "control.c" //your code goes in here
//#include "servo_controller.c" //Axon servo controller
//#include "axon_test.c" //include this is doing a function test for the Axon
//#include "axon_oscope_test.c" //include this is doing a function test for the Axon


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, 38400); // set UARTH speed
    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

   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();

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

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


//test programs
//while(1)
//{
//test_oscope();
//test();
//while(!button_pressed());

//PWM_Init_timer3_E3(8);
//PWM_timer3_On_E3();
//PWM_timer3_Set_E3(30);
//axon_DAQ();//activate the slow DAQ software (data acquisition), all 16 sensors, ~10ms resolution
//axon_DAQ_fast();//activate the super fast DAQ, only ADC pin 9, ~1ms resolution
//}
   
   /*********ADD YOUR CODE BELOW THIS LINE **********/

   //wait until user pushes button
   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)

      //servo_controller();

/*
PWM_Init_timer1_LED(8);
PWM_timer1_On_LED();
while(1)
   {
   for(i=90;i<255;i++)
      {
      PWM_timer1_Set_LED(i);
      delay_ms(10);
      }
   for(i=255;i>90;i--)
      {
      PWM_timer1_Set_LED(i);
      delay_ms(10);
      }
      rprintf("stuff\r\n");
   }

rprintf("Initializing timer2 for PWM\r\n");
PWM_Init_timer1_LED(8);
PWM_Init_timer2_H6(8);//9 doesn't work
PWM_Init_timer3_E3(8);
PWM_Init_timer3_E4(8);
PWM_Init_timer3_E5(8);
delay_ms(100);
rprintf("2");
//PWM_Init_timer4_H3(10);
delay_ms(100);
rprintf("3");
//PWM_Init_timer4_H4(10);
delay_ms(100);
rprintf("4");
//PWM_Init_timer4_H5(10);
delay_ms(100);
rprintf("5");

rprintf("Turning on both PWM channels\r\n");
PWM_timer1_On_LED();
PWM_timer2_On_H6();
PWM_timer3_On_E3();
PWM_timer3_On_E4();
PWM_timer3_On_E5();
PWM_timer4_On_H3();
PWM_timer4_On_H4();
PWM_timer4_On_H5();
delay_ms(1000);

rprintf("Setting PWM to 1%% duty cycle\r\n");
PWM_timer1_Set_LED(1);
PWM_timer2_Set_H6(1);
PWM_timer3_Set_E3(1);
PWM_timer3_Set_E4(1);
PWM_timer3_Set_E5(1);
PWM_timer4_Set_H3(1);
PWM_timer4_Set_H4(1);
PWM_timer4_Set_H5(1);
delay_ms(1000);

rprintf("Setting PWM to 50%% duty cycle\r\n");
PWM_timer1_Set_LED(127);
PWM_timer2_Set_H6(127);
PWM_timer3_Set_E3(127);
PWM_timer3_Set_E4(127);
PWM_timer3_Set_E5(127);
PWM_timer4_Set_H3(127);
PWM_timer4_Set_H4(127);
PWM_timer4_Set_H5(127);
delay_ms(1000);

rprintf("Setting PWM to 99%% duty cycle\r\n");
PWM_timer1_Set_LED(254);
PWM_timer2_Set_H6(254);
PWM_timer3_Set_E3(254);
PWM_timer3_Set_E4(254);
PWM_timer3_Set_E5(254);
PWM_timer4_Set_H3(254);
PWM_timer4_Set_H4(254);
PWM_timer4_Set_H5(254);
delay_ms(1000);

rprintf("Turning off PWM\r\n");
PWM_timer1_Off_LED();
PWM_timer2_Off_H6();
PWM_timer3_Off_E3();
PWM_timer3_Off_E4();
PWM_timer3_Off_E5();
PWM_timer4_Off_H3();
PWM_timer4_Off_H4();
PWM_timer4_Off_H5();
delay_ms(1000);
*/
      delay_cycles(100);//an optional small delay to prevent crazy oscillations
      }
   /*********ADD YOUR CODE ABOVE THIS LINE **********/

   return 0;
   }
----------------------------------------------------------------------------------------------------------------------------------------------------------------

control.c


void control(void)
   {
   while(1)
      {
      LED_on();  //turn green LED on
      delay_ms(1000);
      LED_off(); //turn green LED off
      delay_ms(1000);
      }
   }

--------------------------------------------------------------------------------------------------------------------------------------------------------
Am I supposed to highlight the Robot.c file and do the compile or highlight control.c or what??????
No matter what I try (I tried both methods) it still gives me the same warnings as I noted in the post above and it still does not blink the L.E.D.


Also, if I'm not supposed to mess with the hardware.c file, why does it have a comment in it that says "Add your code below this line"?

I have 25 years of electronics / electrical experience why does programming have to be so confusing? :(

Sorry for the long post.
Thanks for your help.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: AXON Questions
« Reply #8 on: November 11, 2009, 09:27:08 PM »
Try and do it as per the tutorial, calling your main file Axon.c.

It compiles perfectly fine on my end, meaning you did the setup/config improperly somewhere.

Did you modify the makefile?

 


Get Your Ad Here

data_list