Using USB port - page 2 - Hello, I'm a NEWBIE - HELP!! (Newbies assistance, User Guides and thank you notes) - CHDK Forum

Using USB port

  • 14 Replies
  • 3572 Views
Re: Using USB port
« Reply #10 on: 25 / January / 2012, 13:34:30 »
Advertisements
I think I see the problem.  Look at this part of the code :

Code: [Select]
for b = 1 to 100
  a = get_usb_power()
  m = m + a
  c = c + a*a
next b

You need to recognize that if there is no new pulse width to report,  then get_usb_power() returns zero.  Your average reading is then a pseudo-random value that's a more a function of how fast uBasic can iterate through the loop that how well  the USB remote can distinguish USB pulse widths.

This might give you a more precise answer about the statistical variation in the measured USB pulse witdth  :

Code: [Select]
for b = 1 to 100
  do a = get_usb_power 0 until a>0
  m = m + a
  c = c + a*a
next b
Ported :   A1200    SD940   G10    Powershot N    G16

Re: Using USB port
« Reply #11 on: 26 / January / 2012, 17:42:23 »
Thanks for that suggestion.  It obviously could be the problem, but I thought that the command get_usb_power only returned a result on the transition mark to space.  Have I misunderstood this command?  Whoops, I see a fault in my logic there, if it only returns a result on the transition I don't know how long the loop is anyway (that is also true for your code segment).  The question is still valid though, what exactly does the command return and when?  Is it the case that zero is returned unless there has been a transition and if so surely that means that the result will always be zero unless the command is activated at the exact moment of the transition.  Sorry to be a pain,  I am probably showing my ignorance of the basic coding.

Re: Using USB port
« Reply #12 on: 26 / January / 2012, 20:44:57 »
Thanks for that suggestion.  It obviously could be the problem, but I thought that the command get_usb_power only returned a result on the transition mark to space.  Have I misunderstood this command? 
Yes.

Quote
Whoops, I see a fault in my logic there, if it only returns a result on the transition I don't know how long the loop is anyway (that is also true for your code segment).  The question is still valid though, what exactly does the command return and when?
The command returns zero if there has been no pulses since the last time it was called (or no pulses since startup).  Otherwise,  it returns a count proportional to the width of  the most recent pulse ( roughly one count for every 10mSec of pulse width).

Quote
Is it the case that zero is returned unless there has been a transition and if so surely that means that the result will always be zero unless the command is activated at the exact moment of the transition. 
I think what you are missing is that there is a piece of code keeping track of the width of USB pulses independent of your uBasic program.  So when you call get_usb_power(),  you are actually asking that other code what the most recent pulse width is.  If there has been a pulse,  you get the width as a return value.  If there has not been a pulse, it returns zero. The get_usb_power function never looks at the state of the USB power itself.

« Last Edit: 26 / January / 2012, 23:36:19 by waterwingz »
Ported :   A1200    SD940   G10    Powershot N    G16

Re: Using USB port
« Reply #13 on: 27 / January / 2012, 06:50:55 »
Thanks for your patience and reply.
 
But, sorry always a but from some people!, if  "The command returns zero if there has been no pulses since the last time it was called " it can only do this if the calling loop is shorter than the space between pulses which in this case is 23 ms which is shorter than the calling loop.

I understand what you say about independent (from the uBasic) code keeping track of the pulses but this should always have a value from a previous pulse even if the call to get_usb_power comes halfway through a new pulse.

So do you mean " The command returns zero if there has been no pulse since the last time it was called or there is a pulse in progress.  Otherwise,  it returns a count proportional to the width of  the most recent complete pulse".

I imagine this topic has gone on to the boring stage so please feel free to tell me to shut up.


Re: Using USB port
« Reply #14 on: 27 / January / 2012, 09:48:37 »
Quote
The command returns zero if there has been no complete pulse since the last time it was called. Otherwise,  it returns a count proportional to the width of  the most recent complete pulse".
Did you enjoy your time in law school ?
 8)
« Last Edit: 27 / January / 2012, 10:32:11 by waterwingz »
Ported :   A1200    SD940   G10    Powershot N    G16

 

Related Topics