From: Justin R. <ju...@ra...> - 2008-02-10 03:02:21
|
I am using I2C to talk with the robostix heavily. The program runs too slow. How can I speed up the I2C? I am using it to control PWM for a servo and two motors, and ADC for a sensor. Any way to speed things up? What speed does is run at by default with the i2c-io program? Thanks, Justin -- View this message in context: http://www.nabble.com/I2C-speed-up.-tp15392828p15392828.html Sent from the Gumstix mailing list archive at Nabble.com. |
From: DJ D. <dj...@de...> - 2008-02-10 03:51:13
|
For a quick test, run "pxaregs ICR_FM 1". If that makes a difference, you've increased the I2C speed from 100KHz to 400KHz. Otherwise, another option is to write your own C program to do all the I2C communications. It's a lot faster than running a separate i2c-io program for each I2C request. |
From: Dave H. <dhy...@gm...> - 2008-02-10 06:36:47
|
Hi Justin, > I am using my own C program on the gumstix to do all of the I2C, I wanted to > know what the robostix could take. How do I set the I2C speed in C? Can I > set it faster then 400KHz? Essentlly the same way that pxaregs does. You mmap in the register space and set the appropriate bit in the register. No - you can't go faster than 400 kHz. Even going to 400 kHz requires that all of the devices on the i2c bus support 400 kHz. -- Dave Hylands Vancouver, BC, Canada http://www.DaveHylands.com/ |
From: Justin R. <ju...@ra...> - 2008-02-10 20:49:34
|
I was looking at the i2c-io for the robostix and it does not take that much space on the Atmega128. I was looking at it trying to understand where I can edit it to write my code. From what I can see (correct me if I am wrong) When an I2C command is recived it triggers an interrupt and then does a switch command to see what it should do for that command. I added typedef struct { uint8_t deg; ///< How far the servo should scan (180=2,90=1,45=0). } I2C_IR_Scan_t; #define I2C_IR_SCAN 0x0B in i2c-io.h and in i2c-io.c I added case I2C_IR_SCAN: { I2C_IR_Scan_t *req = (I2C_IR_Scan_t *)&packet->m_data[ 2 ]; volatile uint8_t *dgr = (volatile uint8_t *)(int)(req->deg); //code goes here return 0; } The variable dgr will now point to the value received for deg over I2C, correct? Also I was thinking since the main loop just flashes the LED would it be possible to have my scanning code run there and where the I2C_IR_SCAN command came just send the most recent scan data? That way since I am using a thread on the Gumstix to scan and another do change the motor speed the I2C will be open more. What do you think? It seems to me that packet->m_data[ 0 ] = 2; packet->m_data[ 1 ] = ADCL; packet->m_data[ 2 ] = ADCH; return 3; tells the program to send three bytes back and m_data is where it is stored. Is this true? I need to send 20 bytes back. Could I use case I2C_IR_SCAN: { I2C_IR_Scan_t *req = (I2C_IR_Scan_t *)&packet->m_data[ 20 ]; volatile uint8_t *dgr = (volatile uint8_t *)(int)(req->deg); packet->m_data[0-19]=data_to_send; return 20; } Thanks, Justin -- View this message in context: http://www.nabble.com/I2C-speed-up.-tp15392828p15401232.html Sent from the Gumstix mailing list archive at Nabble.com. |
From: Justin R. <ju...@ra...> - 2008-02-10 21:48:46
|
Ok. I now have the robostix scanning in its free time(replaced the flashing LED with my routine). I saved the data I need in the variable ir[25]. All I can say is wow. I actually had to slow down the program quite a bit. I also was able to add servo ramping so it is smoother. The only problem now is I need to send ir[25] to the Gumstix. How do I do this? Thanks, Justin -- View this message in context: http://www.nabble.com/I2C-speed-up.-tp15392828p15401938.html Sent from the Gumstix mailing list archive at Nabble.com. |
From: Justin R. <ju...@ra...> - 2008-02-10 22:26:22
|
Here is what I got so far. On the robostix (in i2c-io.c) case I2C_IR_SCAN: { uint8_t ct=0; for (ct=0;ct<25;++ct){ packet->m_data[ ct ] = ir[ ct ]; } return 25; } and on the gumstix (in i2c-io-api.c) int I2C_IR_Scan(int i2cDev, uint16_t *irdata ){ uint8_t bytesRead; if ( I2cReadBlock( i2cDev, I2C_IR_SCAN, irdata, 25, &bytesRead ) != 0 ) { LogError( "I2C_IR_Scan: I2cProcessBlock failed: %s (%d)\n", strerror( errno ), errno ); return FALSE; } return TRUE; } // I2C_IR_Scan The problem is when I try to use I2C_IR_Scan () I get ERROR: I2cTransfer: ioctl failed: Remote I/O error (121) ERROR: I2C_IR_Scan: I2cProcessBlock failed: Remote I/O error (121) is this an error on the robostix side? Thanks for any help, Justin -- View this message in context: http://www.nabble.com/I2C-speed-up.-tp15392828p15402383.html Sent from the Gumstix mailing list archive at Nabble.com. |
From: Thierry G. <thi...@re...> - 2008-02-10 23:33:53
|
Hi Justin, I don't know about the error you are getting, but, if I were you, I would take a look at the GetInfo command. See how it is done: the Robostix returns a struct to the Gumstix. It might help you. Personnaly, I used it as a template to get the values of two signed 32- bits integers counters for my quadrature encoders. Hope that helps. Thierry Genovese |
From: Justin R. <ju...@ra...> - 2008-02-11 02:00:56
|
I took a look at it. I under stand it a little more but I need to send all of uint16_t ir[25], how do I send an array? I tried (in i2c-io.h) typedef struct { uint16_t irdata[25]; } I2C_IR_Scan_t; (in i2c-io.c) case I2C_IR_SCAN: { uint8_t ct; I2C_IR_Scan_t *irdat = (I2C_IR_Scan_t *)&packet->m_data[ 1 ]; IO_LOG0( "Get IR Data\n" ); for (ct=0;ct<25;++ct){ irdat->irdata[ct] = ir[ct]; } packet->m_data[ 0 ] = sizeof( *irdat ); return sizeof( *irdat ) + 1; } It compiled fine but when when I tried to read it with the gumstix it froze after giving me the error. Any suggestions? Justin Thierry Genovese wrote: > > Hi Justin, > > I don't know about the error you are getting, but, if I were you, I > would take a look at the GetInfo command. See how it is done: the > Robostix returns a struct to the Gumstix. It might help you. > Personnaly, I used it as a template to get the values of two signed 32- > bits integers counters for my quadrature encoders. > > Hope that helps. > > Thierry Genovese > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > gumstix-users mailing list > gum...@li... > https://lists.sourceforge.net/lists/listinfo/gumstix-users > > -- View this message in context: http://www.nabble.com/I2C-speed-up.-tp15392828p15404333.html Sent from the Gumstix mailing list archive at Nabble.com. |
From: Dave H. <dhy...@gm...> - 2008-02-11 02:26:54
|
Hi Justin, > I2C_IR_Scan_t *req = (I2C_IR_Scan_t *)&packet->m_data[ 2 ]; This looks right. > I2C_IR_Scan_t *req = (I2C_IR_Scan_t *)&packet->m_data[ 20 ]; This is definitely wrong. It should still be using [ 2 ]; This email has an overview of adding commands <http://article.gmane.org/gmane.linux.distributions.gumstix.general/25095> Generally speaking, I use Block Read/Write commands. In this case, the request comes in at &packet->m_data[ 2 ]. [0] contains the command and [1] contains the length of the request. For the reply, [0] contains the length of the response, and [1] through the [len] contain the response data. -- Dave Hylands Vancouver, BC, Canada http://www.DaveHylands.com/ |
From: Dave H. <dhy...@gm...> - 2008-02-11 02:28:43
|
Hi Justin, > I now have (in i2c-io-api.c) > int I2C_IR_Scan(int i2cDev, I2C_IR_Scan_t *irdata ){ > if ( I2cReadBlock( i2cDev, I2C_IR_SCAN, irdata, sizeof(*irdata), NULL ) != > 0 ) > { > LogError( "I2cReadBlock failed\n" ); > return 0; > } > return 1; > > } // I2C_IR_Scan > Now I get > ERROR: I2cTransfer: rdLen too big: 50, max is 32 > ERROR: I2cReadBlock failed Yep - exactly what the error says. The max total response is 32 bytes, so you'd need to have the gumstix retrieve the response using two separate commands. -- Dave Hylands Vancouver, BC, Canada http://www.DaveHylands.com/ |
From: Justin R. <ju...@ra...> - 2008-02-11 03:09:59
|
I changed it to send it in two separate commands but now I get: ERROR: I2cTransfer: ioctl failed: Remote I/O error (121) ERROR: I2cReadBlock failed Any suggestions? Justin Dave Hylands wrote: > > Hi Justin, > >> I now have (in i2c-io-api.c) >> int I2C_IR_Scan(int i2cDev, I2C_IR_Scan_t *irdata ){ >> if ( I2cReadBlock( i2cDev, I2C_IR_SCAN, irdata, sizeof(*irdata), >> NULL ) != >> 0 ) >> { >> LogError( "I2cReadBlock failed\n" ); >> return 0; >> } >> return 1; >> >> } // I2C_IR_Scan >> Now I get >> ERROR: I2cTransfer: rdLen too big: 50, max is 32 >> ERROR: I2cReadBlock failed > > Yep - exactly what the error says. The max total response is 32 bytes, > so you'd need to have the gumstix retrieve the response using two > separate commands. > > -- > Dave Hylands > Vancouver, BC, Canada > http://www.DaveHylands.com/ > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > gumstix-users mailing list > gum...@li... > https://lists.sourceforge.net/lists/listinfo/gumstix-users > > -- View this message in context: http://www.nabble.com/I2C-speed-up.-tp15392828p15404866.html Sent from the Gumstix mailing list archive at Nabble.com. |
From: Justin R. <ju...@ra...> - 2008-02-11 04:25:56
|
Ok, I just read the e-mail. This is what is in ProcessCommand() case I2C_IR_SCAN: { uint8_t ct; I2C_IR_Scan_t *irdat = (I2C_IR_Scan_t *)&packet->m_data[ 1 ]; IO_LOG0( "Get IR Data\n" ); for (ct=0;ct<10;++ct){//send ir[0-9] irdat->irdata[ct] = ir[ct]; } packet->m_data[ 0 ] = sizeof( *irdat ); return sizeof( *irdat ) + 1; } case I2C_IR_SCAN2: //split into two functions to stay under 32 byte limit { uint8_t ct; I2C_IR_Scan2_t *irdat = (I2C_IR_Scan2_t *)&packet->m_data[ 1 ]; IO_LOG0( "Get IR Data\n" ); for (ct=10;ct<25;++ct){ //send ir[10-25] irdat->irdata[ct-10] = ir[ct]; } packet->m_data[ 0 ] = sizeof( *irdat ); return sizeof( *irdat ) + 1; } Look ok? In i2c-io.h I have typedef struct { uint16_t irdata[10]; } I2C_IR_Scan_t; #define I2C_IR_SCAN 0x0B typedef struct { uint16_t irdata[15]; } I2C_IR_Scan2_t; #define I2C_IR_SCAN2 0x0C and finally in i2c-io-api.c I have int I2C_IR_Scan(int i2cDev, uint16_t *ir[25] ){ I2C_IR_Scan_t irdata; I2C_IR_Scan2_t irdata2; uint8_t ct; if ( I2cReadBlock( i2cDev, I2C_IR_SCAN, &irdata, sizeof(irdata), NULL ) != 0 ) { LogError( "I2cReadBlock failed\n" ); return 0; } if ( I2cReadBlock( i2cDev, I2C_IR_SCAN2, &irdata2, sizeof(irdata2), NULL ) != 0 ) { LogError( "I2cReadBlock failed\n" ); return 0; } for (ct=0;ct<10;++ct){ ir[ct]=irdata.irdata[ct]; } for (ct=10;ct<25;++ct){ ir[ct]=irdata2.irdata[ct-10]; } return 1; } // I2C_IR_Scan What is wrong? I still get error, but the Gumstix does not freeze now. Thanks, Justin Dave Hylands wrote: > > Hi Justin, > >> I2C_IR_Scan_t *req = (I2C_IR_Scan_t >> *)&packet->m_data[ 2 ]; > > This looks right. > >> I2C_IR_Scan_t *req = (I2C_IR_Scan_t >> *)&packet->m_data[ 20 ]; > > This is definitely wrong. It should still be using [ 2 ]; > > This email has an overview of adding commands > <http://article.gmane.org/gmane.linux.distributions.gumstix.general/25095> > > > Generally speaking, I use Block Read/Write commands. > > In this case, the request comes in at &packet->m_data[ 2 ]. [0] > contains the command and [1] contains the length of the request. > > For the reply, [0] contains the length of the response, and [1] > through the [len] contain the response data. > > -- > Dave Hylands > Vancouver, BC, Canada > http://www.DaveHylands.com/ > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > gumstix-users mailing list > gum...@li... > https://lists.sourceforge.net/lists/listinfo/gumstix-users > > -- View this message in context: http://www.nabble.com/I2C-speed-up.-tp15392828p15405403.html Sent from the Gumstix mailing list archive at Nabble.com. |
From: Dave H. <dhy...@gm...> - 2008-02-11 05:45:11
|
Hi Justin, I only see one thing wrong: > and finally in i2c-io-api.c I have > int I2C_IR_Scan(int i2cDev, uint16_t *ir[25] ){ This is declaring an array of 25 pointers to uint16_t's. Did you really want this? I think you either wanted: int I2C_IR_Scan(int i2cDev, uint16_t ir[25] ){ or int I2C_IR_Scan(int i2cDev, uint16_t *ir ){ I added your code to my copy of i2c-io and it seems to be running fine on my connex/robostix combo. I just had it return an array of 25 increasing numbers. Did you reprogram i2c-io.hex? -- Dave Hylands Vancouver, BC, Canada http://www.DaveHylands.com/ |
From: Justin R. <ju...@ra...> - 2008-02-12 00:22:19
|
... I changed it to *ir but the gumstix freezes halfway displaying the output with all 0s. ERROR: I2cTransfer: ioctl failed: Remote I/O error (121) ERROR: I2cReadBlock failed 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Does nothing, I can't even connect to it to kill the process. (it is a working, no CRC errors, XL6P Verdex board) Is there anything else to check? Dave Hylands wrote: > > Hi Justin, > > I only see one thing wrong: > >> and finally in i2c-io-api.c I have >> int I2C_IR_Scan(int i2cDev, uint16_t *ir[25] ){ > > This is declaring an array of 25 pointers to uint16_t's. Did you > really want this? > > I think you either wanted: > > int I2C_IR_Scan(int i2cDev, uint16_t ir[25] ){ > > or > > int I2C_IR_Scan(int i2cDev, uint16_t *ir ){ > > I added your code to my copy of i2c-io and it seems to be running fine > on my connex/robostix combo. > > I just had it return an array of 25 increasing numbers. > > Did you reprogram i2c-io.hex? > > -- > Dave Hylands > Vancouver, BC, Canada > http://www.DaveHylands.com/ > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > gumstix-users mailing list > gum...@li... > https://lists.sourceforge.net/lists/listinfo/gumstix-users > > -- View this message in context: http://www.nabble.com/I2C-speed-up.-tp15392828p15423952.html Sent from the Gumstix mailing list archive at Nabble.com. |
From: Dave H. <dhy...@gm...> - 2008-02-12 01:06:44
|
Hi Justin, On Feb 11, 2008 4:22 PM, Justin Rajewski <ju...@ra...> wrote: > > ... I changed it to *ir but the gumstix freezes halfway displaying the output > with all 0s. > ERROR: I2cTransfer: ioctl failed: Remote I/O error (121) > ERROR: I2cReadBlock failed You'd have to send me your code for both the gumstix and robostix, since my test code seems to be working. -- Dave Hylands Vancouver, BC, Canada http://www.DaveHylands.com/ |
From: Dave H. <dhy...@gm...> - 2008-02-13 07:50:59
|
Hi Justin, > > You can download my whole robostix directory at > > http://coilgunpower.com/robostix.zip > > The program on the gumstix is in /gumstix/tank > > Thanks for the help, > > I've just started to look at your code. > > One thing I've noticed is that ir is declared to have 25 elements, > with indicies of 0 thru 24. Your code references indicies 0 thru 25 > which means it's trampling one word beyond the end of the array. > > Also, unrelated to the problem, but I noticed you're updating OCR1x > once every 100 msec. > > Since the servos only receive one pulse every 1/50 of a second second, > updating the OCR register more frequently than once every 20 > milliseconds is not going to actually achieve anything. Some other things I discovered: 1 - In your Makefile you do: CC = $(CROSS_COMPILE)gcc -lm -lpthread which causes lots of compile warnings. I changed it to be: CC = $(CROSS_COMPILE)gcc LDFLAGS = -lm -lpthread which eliminated those warnings. 2 - In tank.c, you do: I2C_IR_Scan(i2cDev,&ir); This should be one of: I2C_IR_Scan(i2cDev,&ir[0]); I2C_IR_Scan(i2cDev,ir); 3 - Finally, the thing that's causing all of the problems is in tankcont.c You need to uncomment this line: I2cSetSlaveAddress( i2cDev, 0x0b, I2C_USE_CRC ); The fact that its not getting called is the primary cause of your errors. The one word overwrite on the robostix side may or may not be causing problems, but it should also be corrected. -- Dave Hylands Vancouver, BC, Canada http://www.DaveHylands.com/ |
From: Justin R. <ju...@ra...> - 2008-02-14 01:23:29
|
Great! no errors. Only problem now is I get all 10... I can't believe I commented out I2cSetSlaveAddress( i2cDev, 0x0b, I2C_USE_CRC ); I commented the rest as it is now done when the robostix turns on but I accidentally got that too. -- View this message in context: http://www.nabble.com/I2C-speed-up.-tp15392828p15471903.html Sent from the Gumstix mailing list archive at Nabble.com. |
From: Dave H. <dhy...@gm...> - 2008-02-14 07:47:44
|
Hi Justin, > Seems to be a ADC code problem as I set ir[0-24] to 125 and received 125. I got all 10's on my robostix with your code as well. I had nothing connected to ADC0. I don't see ADMUX being set anywhere? -- Dave Hylands Vancouver, BC, Canada http://www.DaveHylands.com/ |
From: Justin R. <ju...@ra...> - 2008-02-14 23:30:53
|
I am not familiar with the Atmega128 so I will have to look into the data sheet for how to set it up. (I only used PIC and dsPIC before I got the gumstix) Justin Dave Hylands wrote: > > Hi Justin, > >> Seems to be a ADC code problem as I set ir[0-24] to 125 and received 125. > > I got all 10's on my robostix with your code as well. I had nothing > connected to ADC0. > > I don't see ADMUX being set anywhere? > > -- > Dave Hylands > Vancouver, BC, Canada > http://www.DaveHylands.com/ > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > gumstix-users mailing list > gum...@li... > https://lists.sourceforge.net/lists/listinfo/gumstix-users > > -- View this message in context: http://www.nabble.com/I2C-speed-up.-tp15392828p15491923.html Sent from the Gumstix mailing list archive at Nabble.com. |
From: Justin R. <ju...@ra...> - 2008-02-15 00:08:04
|
Ok, I now have // Set ADMUX but don't mess with REFS0 & REFS1 ADMUX = ( ADMUX & (( 1 << REFS1 ) | ( 1 << REFS0 ))) | 0; //read ADC0 // Start the conversion ADCSR = ADCSR | ( 1 << ADSC ); // Wait for it to complete while ( ADCSR & ( 1 << ADSC )); val[x]=((ADCH<<8)&ADCL); but I still am getting 10 Do you see anything wrong? Justin Justin Rajewski wrote: > > I am not familiar with the Atmega128 so I will have to look into the data > sheet for how to set it up. (I only used PIC and dsPIC before I got the > gumstix) > Justin > > Dave Hylands wrote: >> >> Hi Justin, >> >>> Seems to be a ADC code problem as I set ir[0-24] to 125 and received >>> 125. >> >> I got all 10's on my robostix with your code as well. I had nothing >> connected to ADC0. >> >> I don't see ADMUX being set anywhere? >> >> -- >> Dave Hylands >> Vancouver, BC, Canada >> http://www.DaveHylands.com/ >> >> ------------------------------------------------------------------------- >> This SF.net email is sponsored by: Microsoft >> Defy all challenges. Microsoft(R) Visual Studio 2008. >> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ >> _______________________________________________ >> gumstix-users mailing list >> gum...@li... >> https://lists.sourceforge.net/lists/listinfo/gumstix-users >> >> > > -- View this message in context: http://www.nabble.com/I2C-speed-up.-tp15392828p15492407.html Sent from the Gumstix mailing list archive at Nabble.com. |
From: Justin R. <ju...@ra...> - 2008-02-15 00:12:42
|
Never mind. I found the error. It was in my code when I moved it from the Gumstix to the robostix. I used x as a counter but in the robostix code it was used to store the ADC value so it would loop up to 10 then return 10. It works now. Thanks a lot for all of the help I really appreciate it. Justin Justin Rajewski wrote: > > Ok, I now have > // Set ADMUX but don't mess with REFS0 & REFS1 > > ADMUX = ( ADMUX & (( 1 << REFS1 ) | ( 1 << REFS0 ))) | 0; //read ADC0 > > // Start the conversion > > ADCSR = ADCSR | ( 1 << ADSC ); > > // Wait for it to complete > > while ( ADCSR & ( 1 << ADSC )); > > val[x]=((ADCH<<8)&ADCL); > but I still am getting 10 > Do you see anything wrong? > Justin > > > Justin Rajewski wrote: >> >> I am not familiar with the Atmega128 so I will have to look into the data >> sheet for how to set it up. (I only used PIC and dsPIC before I got the >> gumstix) >> Justin >> >> Dave Hylands wrote: >>> >>> Hi Justin, >>> >>>> Seems to be a ADC code problem as I set ir[0-24] to 125 and received >>>> 125. >>> >>> I got all 10's on my robostix with your code as well. I had nothing >>> connected to ADC0. >>> >>> I don't see ADMUX being set anywhere? >>> >>> -- >>> Dave Hylands >>> Vancouver, BC, Canada >>> http://www.DaveHylands.com/ >>> >>> ------------------------------------------------------------------------- >>> This SF.net email is sponsored by: Microsoft >>> Defy all challenges. Microsoft(R) Visual Studio 2008. >>> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ >>> _______________________________________________ >>> gumstix-users mailing list >>> gum...@li... >>> https://lists.sourceforge.net/lists/listinfo/gumstix-users >>> >>> >> >> > > -- View this message in context: http://www.nabble.com/I2C-speed-up.-tp15392828p15492409.html Sent from the Gumstix mailing list archive at Nabble.com. |
From: Justin R. <ju...@ra...> - 2008-02-15 00:28:28
|
I lied. It still does not work. I now get 0 and not 10 though. What do you see in my code that I don't? uint16_t readir (void){ uint16_t x=0,a[2]={0,0},val[15],avg=0,flag[2]={0,0}; a[0]=0; a[1]=0; for (x=0;x<10;++x){ // Set ADMUX but don't mess with REFS0 & REFS1 ADMUX = ( ADMUX & (( 1 << REFS1 ) | ( 1 << REFS0 ))) | 0; // Start the conversion ADCSR = ADCSR | ( 1 << ADSC ); // Wait for it to complete while ( ADCSR & ( 1 << ADSC )); val[x]=((ADCH<<8)&ADCL); // The Sharp IR sensors have a noise problem where they emit large pulses // that cause the readings to be off. There for we take 10 readings and // remove the highest two to create a more stable result if ((val[x]>a[0])||(val[x]>a[1])){ // The two highest numbers are stored in a[0] and a[1] // The location of thoes numbers are stored in flag[0] and flag[1] if (a[0]<a[1]){ flag[0]=x; a[0]=val[x]; }else{ flag[1]=x; a[1]=val[x]; } } } avg=0; for (x=0;x<10;++x){ //average the 8 numbers if ((x!=flag[0])&&(x!=flag[1])){ //if the numbers are one of the top two then don't average them avg+=val[x]; } } avg/=8; //x=exp(-1.3879*log(avg)+10.4518); //Done on Gumstix to save time return avg; } Justin -- View this message in context: http://www.nabble.com/I2C-speed-up.-tp15392828p15492610.html Sent from the Gumstix mailing list archive at Nabble.com. |
From: Justin R. <ju...@ra...> - 2008-02-15 00:42:07
|
I got it working! I changed val[x]=((ADCL) | ((ADCH)<<8)); and added DDRF = 0x00; // configure a2d port (PORTF) as input so we can receive analog signals PORTF = 0x00; // make sure pull-up resistors are turned off (else we’ll just read 0xCFF) Thanks, Justin -- View this message in context: http://www.nabble.com/I2C-speed-up.-tp15392828p15492799.html Sent from the Gumstix mailing list archive at Nabble.com. |
From: Dave H. <dhy...@gm...> - 2008-02-10 06:01:41
|
Hi Justin, > I am using I2C to talk with the robostix heavily. The program runs too slow. > How can I speed up the I2C? I am using it to control PWM for a servo and two > motors, and ADC for a sensor. Any way to speed things up? What speed does is > run at by default with the i2c-io program? The i2c-io program doesn't set or care about the speed of the i2c bus. DJ posted how to change the speed from 100 kHz to 400 kHz. If you're actually using the i2c-io program to do your servo stuff, then this is where most of the slowdown is coming from. You really want to be talking to the i2c-dev interface directly from your own C program. I did some performance tests with ADC on the i2c bus running at 100 kHz and was able to read about 540 samples/sec. Since R/C servos can only update about 50 times/sec, this should be fast enough. You can run the i2c-adc test yourself to see what kind of rate you're getting. I just tried on my 400 MHz verdex and over the serial port I got 8847 samples in 10 seconds. I think that this due to the improvements in the newer gcc toolchain. -- Dave Hylands Vancouver, BC, Canada http://www.DaveHylands.com/ |
From: Justin R. <ju...@ra...> - 2008-02-10 06:24:27
|
I am using my own C program on the gumstix to do all of the I2C, I wanted to know what the robostix could take. How do I set the I2C speed in C? Can I set it faster then 400KHz? Thanks, Justin DJ Delorie wrote: > > > For a quick test, run "pxaregs ICR_FM 1". If that makes a difference, > you've increased the I2C speed from 100KHz to 400KHz. > > Otherwise, another option is to write your own C program to do all the > I2C communications. It's a lot faster than running a separate i2c-io > program for each I2C request. > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > gumstix-users mailing list > gum...@li... > https://lists.sourceforge.net/lists/listinfo/gumstix-users > > -- View this message in context: http://www.nabble.com/I2C-speed-up.-tp15392828p15393631.html Sent from the Gumstix mailing list archive at Nabble.com. |