Strange get_usb_power inconsistency - Script Writing - CHDK Forum  

Strange get_usb_power inconsistency

  • 19 Replies
  • 4555 Views
Strange get_usb_power inconsistency
« on: 18 / June / 2010, 16:24:24 »
Advertisements
Hi all,

I'm putting together a lengthy uBasic script for an sd1000 camera.  I'm controlling the camera using a microcontroller, applying commands using pulses of different widths and then measuring those widths in script.  I'm aware of the variable nature of get_usb_power and so I've implemented ranges to accurately capture commands (25 to 35 for 300ms pulse width etc.).  Anyway, recently my script has become a little longer and more complex, and now I'm finding that the ranges are failing.  Measured pulse widths are coming in consistently short, so a 300ms width would now be measured around 25 and often lower than this.  Here's how I'm measuring the pulse widths:

Code: [Select]
do
a = get_usb_power
sleep_for 45
i = i + 1
until ((a > 0) or (i > d))

I'm wondering if anyone has experienced something similar, or might have an idea as to why this is happening?

Cheers,

Peter
« Last Edit: 18 / June / 2010, 16:29:08 by crasspm »

Re: Strange get_usb_power inconsistency
« Reply #1 on: 18 / June / 2010, 17:34:05 »
What happens if a pulse occurs while you are sleeping ?

Normally, you use :-

do
  a = get_usb_power
until (a > 0)



David

Re: Strange get_usb_power inconsistency
« Reply #2 on: 18 / June / 2010, 17:47:47 »
I gave that a shot, but it looks like the measurements are coming in even shorter now... 

I've seen this before as well, within one of my subroutines I had to change my ranges since pulse widths were being measured on average shorter than their actual lengths.

Re: Strange get_usb_power inconsistency
« Reply #3 on: 18 / June / 2010, 18:04:09 »
Is it possible that your pulses do not have fast edges and there is a delay before the processor detects the voltage change ?


(you have a reply to your personal message).
« Last Edit: 18 / June / 2010, 18:10:27 by Microfunguy »


Re: Strange get_usb_power inconsistency
« Reply #4 on: 18 / June / 2010, 18:52:33 »
Scoping the pulses shows a rise time of ~10ns and a fall time of ~5ns, these are being generated by a microcontroller so these times aren't surprising.

Measuring the same pulses with a stripped down script that only measures and prints results is showing accurate and consistent readings. Could length of script have anything to do with this?

Re: Strange get_usb_power inconsistency
« Reply #5 on: 18 / June / 2010, 18:59:56 »
I wonder if uBasic statements really are being executed every 10 msec or whether they are occasionally missed because other Canon tasks interrupt ?


Re: Strange get_usb_power inconsistency
« Reply #6 on: 18 / June / 2010, 19:09:34 »
Quote
I wonder if uBasic statements really are being executed every 10 msec or whether they are occasionally missed because other Canon tasks interrupt ?

That would make sense.  The longer the pulse duration, the more below the mark the measurement is, maybe implying an accumulating error.

But I wonder, why would the same script measure the same pulse width differently in different parts of the script?  That's what I was experiencing when I was measuring both in the main loop and within a subroutine...

Re: Strange get_usb_power inconsistency
« Reply #7 on: 18 / June / 2010, 22:04:51 »
Don't assume that every problem is software related.

I cannot help you with software, I am a hardware guy. I have seen too many instances of faults caused by erratic hardware.

Have you observed every output pulse from the micro-controller on an oscilloscope?

If the timing in the micro-controller is written in software, your output pulses may be dirty and causing erratic behaviour. If you can try generating the same pulses in hardware it may confirm your micro-controller is working properly.

I am not saying it will cure your problem; it will eliminate external factors.
« Last Edit: 18 / June / 2010, 22:06:46 by thepanoguy »


Re: Strange get_usb_power inconsistency
« Reply #8 on: 18 / June / 2010, 23:52:09 »
I will hopefully find time to try something similar to this soon, but using Lua. Have you tried Lua? Perhaps it works better than uBasic for something like this?

Andy

Re: Strange get_usb_power inconsistency
« Reply #9 on: 19 / June / 2010, 04:30:23 »
For various reasons, Peter is using SDM and SDM does not support Lua.


 

Related Topics