Author Topic: Is it possible and worthwhile to try to speed up Sor Scope?  (Read 1655 times)

0 Members and 1 Guest are viewing this topic.

Offline KurtEckTopic starter

  • Robot Overlord
  • ****
  • Posts: 217
  • Helpful? 12
I was going to add this to the Sor Scope revival thread, but...

The concept of using your own Microcontrollers to help debug stuff is a great idea.  There are times when you need to test out sensors and the like and you can not justify purchasing test equipment.  For me I am doing this for the fun of it as I have a Salaea logic analyzer (I highly recommend) and use use a lot.  Likewise I have an old parallax USB Oscilloscope, which I now only use on rare occasions, like this Sunday to verify that the quadrature encoders on some motors were generating proper digital signals.  They are...   

I thought about trying out the SOR scope for this, but quickly decided it would not be fast enough: Motor spinning at 3/4 speed (150rpm)  * 30 (motor geared 30 to 1) 100CPR for encoder, which implies that I have about 450,000 cycles per second. would want at least 10 samples per cycle so 5M per minute or 75000 per second.   So I quickly dismissed this approach. 

But it still made me think, could we speed it up enough to maybe do something like this, after all for this I could run the motor at a slower speed.

So first look at Atmega640 spec to see how fast we can do AtoD conversions.  It appears like the processor may be able to do up to 76.9KSPS, so it looks like it could be doable for 1 channel.  Now assuming we can switch channels and still get near that speed, we could probably do 2 or 4 channels and see the encoder... 

But now how to get the information back to the PC.  So I then started looking at the webbotlib example code and first discovered I think it may be busted...
Code: [Select]
// This routine is called repeatedly - its your main loop
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart){

while(1);

//select number of ports to output
//ADC_1();
ADC_3();
//ADC_8();
//ADC_16();

#ifdef USE_TIMER
//add time stamp at end of data:
rprintf(" %d",clockGetus()-time_start);
//reset start time
time_start = clockGetus();
#endif

rprintf("\r\n");

return 0;
}
i.e. what is that while 1 at the beginning... 
Then I looked at how the signals were sampled and sent back to the PC.  Start simple with 1 channel:
Code: [Select]
void ADC_1(void)
{
//gather data
a0=a2dConvert8bit(ADC0);

//report data
rprintf("%d",a0);
}
A couple of things I noticed.  Each time through, the code sets up the AtoD conversion, selects channel, starts it up and waits for it to complete.  Second each of the samples is converted to ASCII text and sent along with a CR/LF, so assuming all values are equally likely that comes out to maybe on average: 4.6 characters per sample.  At the baud rate of 115200 that would imply a top end maximum of about 2.5k samples per second.  So for sure here is obviously place to start looking at.

Looking at the the Sor Scope program, it has buttons for Text input, Binary input, Binary 4 bit and Binary 2 bit.  Going binary would for sure help!  If we simply output 1 byte instead of the 4.6 we can get this up to over 10K per second.  Is there any more information on this?  Assuming this can be done the next major improvement would be for the conversions and IO to happen at the same time.  Then maybe some form of data compression.  But this would require changes on both ends.

Is this worthwhile? 

Kurt

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Is it possible and worthwhile to try to speed up Sor Scope?
« Reply #1 on: May 05, 2010, 02:56:04 PM »
Hi Kurt

First let me say this is not an official  'WebbotLib Example' - but may be an example based on WebbotLib. So I can't comment directly on the coding style you have mentioned.

I had also thought about a more optimised example for pure digital I/O pins - eg including PWM. This would result in far more compact transmission ie 1 bit per signal as opposed to 8.

WebbotLib also allows you to set a UART speed in excess of 1M/bit per second .
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Is it possible and worthwhile to try to speed up Sor Scope?
« Reply #2 on: May 05, 2010, 11:06:07 PM »
The SoR Scope is more meant for slow stuff (signals under 1KHz) and analog voltage measurement . . .

If you want *really* fast, the best way is not to use SoR Scope at all, as any use of the UART by default slows things down.

Set up an interrupt that detects for pulses and use a timer to measure it.

Then just output the frequency by UART once a second or so.

Offline KurtEckTopic starter

  • Robot Overlord
  • ****
  • Posts: 217
  • Helpful? 12
Re: Is it possible and worthwhile to try to speed up Sor Scope?
« Reply #3 on: May 06, 2010, 08:46:15 AM »
Thanks guys, I many not spend much time on it.  As I said I have other equipment to use. 

What got me thinking about this, is I am trying out a new Motor Controller (Basic Micro robo-claw) that also takes inputs from encoders and you can ask it information like how many quadrature tics have happened, what is the current speed.  Likewise you can tell it I want to go at this speed and the controller is supposed to take care of it for you...  Well the speed numbers were not making any sense to me, so I hooked up my logic analyzer and watched the input from the encoders and found the speed was half what was reported.  So at that point I knew that either there was a problem with the motor controller or maybe the encoders were not producing a clean signal and maybe it dipped down some which was detected by the controller, but was still high enough that the logic analyzer did not see it.  So that is when I wanted the scope.  I used the old Parallax USB scope that I purchased several years ago as part of their understanding signals product.  It showed nice clean signals, so then I knew that there was an issue with a controller.  If you wish to see more about this, it is up on the thread: http://www.lynxmotion.net/viewtopic.php?f=20&t=6205&start=15

But that made me start thinking what if I did not have this stuff?  That is what me started thinking about using the SOR Scope.  I do think without much work it can maybe be sped up by a factor of 10 or more which would be nice.  My thoughts are:

a) Up the baud rate to maybe 500000 or 1000000 which are both listed in the comm port options and should work out well on a 16mhz processor

b) See about buffering the IO.  That is define buffers for the USB UART.  Something like:
        #define UART1_TX_BUFFER_SIZE 80
        #define UART1_RX_BUFFER_SIZE 20
That way the AtoD conversions can happen while it is outputting data...
b1) Alternatively if I am doing this on without the buffering, look into reworking the functions like:
Code: [Select]
void ADC_4(void)
{
//gather data
a0=a2dConvert8bit(ADC0);
a1=a2dConvert8bit(ADC1);
a2=a2dConvert8bit(ADC2);
a3=a2dConvert8bit(ADC3);

//report data
rprintf("%d %d %d %d ",a0,a1,a2,a3);
}
To maybe something like:
Code: [Select]
void ADC_4(void)
{
a=a2dCompleteConvert8bit(ADC0);
a2dStartConvert8bit(ADC1);
rprintf("%d ",a);

a=a2dCompleteConvert8bit(ADC1);
a2dStartConvert8bit(ADC2);
rprintf("%d ",a);

a=a2dCompleteConvert8bit(ADC2);
a2dStartConvert8bit(ADC3);
rprintf("%d ",a);

a=a2dCompleteConvert8bit(ADC3);
a2dStartConvert8bit(ADC0);
rprintf("%d ",a);
}

To make use of the time waiting for an AtoD to complete. That is you start up an AtoD conversion and then output the previous value to make use of the time while the AtoD completes.   But this would require new AtoD functions to do this...

c) Experiment with binary data instead of ASCII.  The question is this implemented in the PC program and if so what format is it expecting for the binary data?

That is all for now.

Kurt

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Is it possible and worthwhile to try to speed up Sor Scope?
« Reply #4 on: May 06, 2010, 10:54:42 AM »
Well, the code to interface with the SoR Scope is open source, so you're welcome to experiment. Personally, I think the code I wrote doesn't do a great job measuring servo pulses, so I'd definitely like it to work faster . . .

Feel free to post .hex files if you get it going really fast. :P

Offline KurtEckTopic starter

  • Robot Overlord
  • ****
  • Posts: 217
  • Helpful? 12
Re: Is it possible and worthwhile to try to speed up Sor Scope?
« Reply #5 on: May 06, 2010, 11:10:06 AM »
Well, the code to interface with the SoR Scope is open source, so you're welcome to experiment. Personally, I think the code I wrote doesn't do a great job measuring servo pulses, so I'd definitely like it to work faster . . .

Feel free to post .hex files if you get it going really fast. :P
Well, I have it running at about 1.86k per second for 16 channels text input, by buffering the text, going at baud rate of 500000. Would like to try binary mode (assuming it is implemented on the PC side.  As I see 3 buttons for this (binary, binary 4 bit and binary 2 bit), I will first assume binary is 8 bit. But don't know if there is any handshaking for binary mode. Likewise if there is clock... So right now it would be a shot in the dark.

It would be nice if clicking on the buttons on the PC side sent some request over to the Axon2 and let it optimize for what is being displayed. For example maybe able to config for how many channels you wish data on...
« Last Edit: May 06, 2010, 11:11:30 AM by KurtEck »

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Is it possible and worthwhile to try to speed up Sor Scope?
« Reply #6 on: May 06, 2010, 11:41:34 AM »
Quote
It would be nice if clicking on the buttons on the PC side sent some request over to the Axon2 and let it optimize for what is being displayed. For example maybe able to config for how many channels you wish data on...
Yea, there was talk about implementing this feature. But the author went AWOL (he had more important priorities), and it just never happened.

 


data_list