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

Using USB port

  • 14 Replies
  • 4965 Views
Using USB port
« on: 16 / January / 2012, 07:27:31 »
Advertisements
Hi,

I am just starting out with CHDK and looking for some help setting up remote control via the USB port.

I need to operate the zoom control and shutter release.  My idea was to use a 555 timer to generate different pulse widths (as seen on a number of topics) but I wanted to keep zooming as long as I kept a button pressed by generating an astable signal with different mark space ratios for zoom in/zoom out.  I find that the command get_usb_power gives the pulse length (approximately) for a monostable signal (so I can zoom one step per button press) but gives seemingly random pulse lengths when in astable mode even if I make the space quite large.  I was using various mark lengths of 30 to 130 ms on an IXUS 860.  Ultimately want to use system on SX40HS.

Has anyone done this or know why it doesn't seem to work?  Thanks

Re: Using USB port
« Reply #1 on: 16 / January / 2012, 08:07:43 »
I've done a little work on the USB interface recently  ( http://chdk.setepontos.com/index.php?topic=7127 ) and am a little surprised to hear this. 

Bear in mind that the port is only sampled every 10 mSec so you should see some jitter.  The values are also not buffered in anyway.   What kind of values do you get back ? 

And BTW - the new CHDK USB v2 will support both mark & space measurements (buffered) so that might help you.   If you build the latest code and turn on USB debugging, one of the things displayed is the last 16 mark / space times.  USB Remote V2USB Remote V2
Ported :   A1200    SD940   G10    Powershot N    G16

Re: Using USB port
« Reply #2 on: 16 / January / 2012, 16:55:58 »
Hi,

Many thanks for the info.  I will give it a try, sounds like just what I need.  The jitter I see is +/- 1 or 2 (10 to 20 ms) in monostable mode but I get readings from 1 to say 15 when running as astable with say 30 ms space and mark time of about 60 ms (sorry didn't write them down, I tried several combinations).  Could be I was doing something wrong.

Cheers 
Steve

Re: Using USB port
« Reply #3 on: 18 / January / 2012, 18:24:17 »
I've looked a little more at astable timings and it looks to me that if the loop reading the USB port is less than 100 ms the get_usb_power can give variable results, although I think this also seems to be a function of pulse length.  If you put a long delay, say sleep 1000 the result always is in range of +/- 1 (10 ms).

Waterwingz, you mention get_usb_pulse_count and get_usb_width but my version of CHDk 1.0.0.1504 doesn't appear to recognise these commands am I missing something?


Re: Using USB port
« Reply #4 on: 18 / January / 2012, 18:54:12 »
I've looked a little more at astable timings and it looks to me that if the loop reading the USB port is less than 100 ms the get_usb_power can give variable results, although I think this also seems to be a function of pulse length.  If you put a long delay, say sleep 1000 the result always is in range of +/- 1 (10 ms)
Strange - the code only sets a new pulse width value after a clean 0->1->0 sequence.  The rate at which the result is read should not affect the value.

Waterwingz, you mention get_usb_pulse_count and get_usb_width but my version of CHDk 1.0.0.1504 doesn't appear to recognise these commands am I missing something?
You are not missing anything - the unreleased documentation is ahead of the actual code release (for a change).  I'm working on that now but could be a week or two before the next update.
Ported :   A1200    SD940   G10    Powershot N    G16

Re: Using USB port
« Reply #5 on: 19 / January / 2012, 01:43:06 »
If anyone is contemplating in building an automated USB Port trigger, be aware that the standard analogue range of 555 timers will misfire on the first pulse. You will need to use a precision range of 555 timer chip for accuracy; usually they are low power CMOS chips. 

Refer to the manufacturer’s data sheet for details. Some of the data sheets give an explanation why the 555 timers will misfire and methods to circumvent the issue. It usually works out cheaper to use a precision low power 555 timer chip. 

Free manufacturer’s datasheets are available at : http://www.datasheetcatalog.com/datasheets_pdf/

Re: Using USB port
« Reply #6 on: 23 / January / 2012, 10:47:44 »
This may be useful for others, as I have now been more systematic in my look at get_usb_power with a 555 timer running in astable mode. 
I increased voltage suppy to approx 10 V in case using around  5V with a standard 555 was a bit low (I will try the cmos version when I get a chance).  All connections now soldered rather than breadboard and timer running before script started.
I took a 100 samples for each loop time delay to give a mean and standard deviation of the measured pulse width.  The minimum time for a sample loop is 40 ms assuming that a for, next instruction takes 10 ms and I need to sum the result  and sum result squared as well as the get_usb_ power instruction.  The next delay puts a sleep command in the loop and from then on increasing by 10 ms for each set of 100 tests.
I used a 23 ms space and 23, 40 and 75 ms mark.
For a 23 ms mark the minimum 40 ms sample loop averaged a reading of 1 but by  the time  I got to 60 ms loop I was getting an average reading of 2 with s.d. of 1.4.  It didn't really change from then on.
For a 40 ms mark I had to get to a 70 ms loop before I got an average reading of 4 and s.d. of 2.  By the time I got to a loop of 130 ms  I was consistentltygetting an s.d of 1 ( still average reading 4)
For the 75 ms Mark, The average was 6 or less (s.d. greater than 4) until the loop was more than 90 ms.  Above 150 ms the average was 8 with s.d. down to less than 3.

I take from this that if I want to distinguish a 75 ms pulse  from a 40 ms pulse with any degree of certainty I need a get_usb_power measurement loop that is at least 100 ms, preferably 150 ms long.

I will try with a cmos 555 when I get one.

Re: Using USB port
« Reply #7 on: 23 / January / 2012, 11:19:55 »
FYI ... the current main dev trunk USB remote code now implements "buffered" mark & space measurement.

Preliminary documentation is here :  USB remote V2 scripting interface
Ported :   A1200    SD940   G10    Powershot N    G16


Re: Using USB port
« Reply #8 on: 23 / January / 2012, 12:19:10 »
I keep thinking about this and something does not make sense.  Would you please post the code you are using ?
Ported :   A1200    SD940   G10    Powershot N    G16

Re: Using USB port
« Reply #9 on: 25 / January / 2012, 13:19:00 »
I keep thinking about this and something does not make sense.  Would you please post the code you are using ?

@title Zoom test variable time
@param m mean
@default m 8
@param z delay
@default z 0
@param a time
@default a 0
@param b step
@default b 1
@param c square
@default c 0

print "interval",z
m = 0
c = 0
for b = 1 to 100
  a = get_usb_power()
  m = m + a
  c = c + a*a
next b
m = m/100
print "mean", m
c = c/100
print "squared", c
sleep 2000

do
print "interval", z
m = 0
c = 0
for b = 1 to 100
  a = get_usb_power()
  m = m + a
  c = c + a*a
  sleep z
next b
m = m/100
print "mean", m
c = c/100
print "squared", c
sleep 2000
z = z + 10
until z > 2000
end

I don't know if sleep 0 is different to sleep 10, but don't think that significantly alters my conclusion.  Also my s.d. is square root of ( c minus m sqared ).

 

Related Topics