Author Topic: VR line detector, Debugging and MOSFET questions.  (Read 1561 times)

0 Members and 1 Guest are viewing this topic.

Offline jessman275Topic starter

  • Jr. Member
  • **
  • Posts: 8
  • Helpful? 0
VR line detector, Debugging and MOSFET questions.
« on: February 03, 2010, 01:31:49 AM »
So i used axon_test.c to test my ports and see if i hooked up a MOSFET correctly. It was switching a relay just fine , but was drawing alot of power ( enough to kill a 9 V within 20 min ) .

The flowchart attached is what i have. I have since loaded up a program that would pull from a IR sensor and activate PORTE, 6 which of course doesn't seem to be working.  But i seem to be getting some feedback of some sort. For instance, when i disconnect the drain wire (from the MOSFET)  my servo moves a bit( which is not even close to PORTE,6) . Then reconnect it and it moves again. I had a random servo on a port for no reason.I just noticed this and then checked it on all the other ports ( E's - H's. )

So i would like some clarification on some things.

First a when hooking up a mosfet the signal ( inner most pin ) goes to the gate side of the MOSFET? 

Second Where is the ground supposed to go? I currently have it attached to the neg side of the power supply for the AXON. But that may be causing my fast drain problem...?

Third , I keep getting a "warning : implicit declaration of function "a2dConvert8bit"  . what is that all about. I have #include a2d.c  in my file.

Fourth , Is compiling supposed to replace the old file? for instance i am using control.c . So all my code is in control.c. I save it, run and build it, then compile it. But when i open up the file where control.c is the time it was created doesn't change. Am i doing something wrong?

Here is the Axon.c code

Code: [Select]

#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
#include "a2d.h" // analog to digital

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

//below is various test code for Admin
/*
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;
}



Here is the control.c code
Code: [Select]
//define port functions; example: PORT_ON( PORTD, 6);
#define PORT_ON( port_letter, number )
#define PORT_OFF( port_letter, number )

int se5=0;

int control(void)
{
while(1)
{
se5=(a2dConvert8bit(5));
if(se5>128)//depends on values you expect
    PORT_ON(PORTE,6);
else
    PORT_OFF(PORTE,6);

}
}



Thanks a bunch in advance , I am just learning robots in my spare time while i go to school and so far its keeping me busy.

Jesse

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: VR line detector, Debugging and MOSFET questions.
« Reply #1 on: February 08, 2010, 04:50:36 AM »
Quote
First a when hooking up a mosfet the signal ( inner most pin ) goes to the gate side of the MOSFET?
yeap . . .

Quote
Second Where is the ground supposed to go? I currently have it attached to the neg side of the power supply for the AXON. But that may be causing my fast drain problem...?
Ground for the MOSFET or? PNP or NPN type?

Quote
Third , I keep getting a "warning : implicit declaration of function "a2dConvert8bit"  . what is that all about. I have #include a2d.c  in my file
Which code line is causing that warning?

Quote
Fourth , Is compiling supposed to replace the old file? for instance i am using control.c . So all my code is in control.c. I save it, run and build it, then compile it. But when i open up the file where control.c is the time it was created doesn't change. Am i doing something wrong?
The .hex should be overwritten. Sure you are checking the correct folder location?

Offline jessman275Topic starter

  • Jr. Member
  • **
  • Posts: 8
  • Helpful? 0
Re: VR line detector, Debugging and MOSFET questions.
« Reply #2 on: February 11, 2010, 01:47:23 AM »
Well its a N type mosfet. I fixed the warning by adding the a2d.c in the code, But now that there are no errors and everything is compiling the program doesnt work. I am double checking the file that i am putting on the controller. Evertime i update it the date and time change. So i know im good there. Could someone possibly take a look at the code and see what may be missing.

Thanks

Code: [Select]
#define PORT_ON( port_letter, number )
#define PORT_OFF( port_letter, number )

int se5=0;

int control(void)
{
while(1)
{
LED_on();
if (button_pressed())
LED_off();

DDRE = 0b11111111;  //configure all E ports for output
DDRK = 0b11111111;  //configure all K ports for output

se5=a2dConvert8bit(5);
if(se5>128)//depends on values you expect
    PORT_ON(PORTE,5);
else
    PORT_OFF(PORTE,5);

}
}

and

Code: [Select]
//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 "_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();

//below is various test code for Admin
/*
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;
}


Thanks a Bunch !

Jesse

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: VR line detector, Debugging and MOSFET questions.
« Reply #3 on: February 11, 2010, 02:45:15 AM »
For an NPN MOSFET, ground connects directly to the source, and drain connects to your motor or whatever.

As for your code, you need to better specify 'the program doesnt work' :P

I mean, what debugging steps have you taken? You should use rprintfs to locate the error.

Also, change this:
int se5=0;

to
uint8_t se5=0;

You forgot that int is by default signed, which doesn't go higher than 128 :P

 


Get Your Ad Here