A timing question

wapo54001

Senior Member
If the chip is a Picaxe 28X2 running at 32MHz

and the code is

HIGH Drive_Pin
INPUT Drive_Pin
RETURN

then, how long is Drive_Pin held HIGH?
 

AllyCat

Senior Member
Hi,
how long is Drive_Pin held HIGH?
For an M2, switching back to Low, it is about 50 us. I wouldn't expect an X2, or switching to input (tri-state), to be very different. For better accuracy you'll probably have to measure it (with a pull-down resistor). ;)

Cheers, Alan.
 

PhilHornby

Senior Member
I just tried it on an 08M2 and a 20X2 (don't possess a 28X2) ... measuring it with my 'scope.

I got 42uS on the 08M2 and 64uS on the 20X2.

So ... about 50uS ;)
 

wapo54001

Senior Member
Gentlemen, thank you for your replies. I'll take it as somewhere between 40 and 60 micro seconds.

That value is the adjustment per loop that my circuit makes to stabilize a precise current driving an LDR (nls32sr2) circuit. The HIGH and LOW switching drives the gate of a mosfet through a 1M resistor to charge a 1uF tantalum capacitor directly coupled to the gate without a pull up or pull down. I know that the resulting control is very precise but I had no idea how long the HIGH or LOW circuit was connected and I wanted to know.

Again, thanks.

PS I have no idea how you measure such a thing. Glad someone does . . .
 

AllyCat

Senior Member
Hi,

If the timing delay depends on the Threshold voltage of a FET, it won't be very precise, because the Threshold voltage varies with temperature. ;) It's "well known" that the Vbe of a bipolar transistor changes by about -2mV / degreeC (in ~600mV) and I just looked up that for a typical 2N7000 FET at 1mA the Vgs threshold appears to be a very linear -0.27% / C (i.e. proportionally quite similar). But at higher currents and with multiple devices, it can get "complicated".

On the topic of PICaxe code timings, I think the 08M2 is about 10 - 15% "faster" than the other M2s, probably because it has a smaller (RAM) address range, and also the 14/20 pin chips have to "re-map" their three "internal" (base PIC software) Ports (A , B and C) to the PICaxe's two "external" Port.pins (B and C). Presumably that's also (some of) the reasons why the X2s are proportionally (even) slower. For "output" effects such as HIGH/LOW, PULSOUT, etc., its easy to measure with an Oscilloscope, or often a second PICaxe chip (using PULSIN). But to "measure" the time of specific PICaxe instructions (e.g. PAUSE{US} 0), I have posted a Code Snippet, but it must still use a "real" PICaxe chip, not the simulator.

Cheers, Alan.
 

wapo54001

Senior Member
AllyCat, I think I don't understand what you are saying about the mosfet, but in my case the output pin drives the mosfet to a very specific level (measured each cycle with an input feedback pin), the combination of which controls current through the LED portion of an LDR module (NSL-32SR2).

In my opinion, an LDR-based volume control sounds far better than a simple pot or even a stepped attenuator.

My circuit uses four LDR devices to simulate a stereo volume control which requires each LDR to hold a very specific resistance. I use a Picaxe to control the current to each device by setting an output pin either high or low or off to adjust mosfet drive, and a second input pin to measure the actual current flowing through the LDR-mosfet combination to provide feedback. The goal is to achieve a perfect 25K or 50K logarithmic resistance curve stereo volume control using current with values ranging from 10ma to vanishingly small. Also, the LDR resistance curve is nonlinear.

The Picaxe is necessary because the LDR's manufacturing tolerances are notoriously loose and so four random modules cannot be used where precise matching is required as in a volume control. The Picaxe permits precision matching of resistances via pre-calibration and storage of current-resistance relationships in ROM coupled with on-the-fly lookup tables and interpolation so that virtually any four LDR modules can be made to operate as though they were perfectly matched.

Once the volume "pot" stops changing, the math routines are bypassed and target resistances are achieved by increasingly smaller corrections and then maintained by minimum corrections which could be no action at all or a single HIGH or LOW command followed immediately by the INPUT command. I estimate that I get feedback resolution of 12 bits or more by running the 28X2 outside it's specifications so the corrections are pretty accurate even at low current levels. I wanted to know approximately how long the duration of the smallest possible correction could be that maintains truly small levels of current which was why I asked the original question.

It would be very interesting to know how many corrective loops happen per second. Is there a software method I can use to measure that without an oscilloscope (which I gave up when we last moved). It seems to me that any code that I insert will throw the result off.
 

wapo54001

Senior Member
I went to the website, DPScope seems to be no more (see attached screen capture). Maybe you're referring to PCBscope sold by Rev Ed?

I could temporarily reprogram another pin to send a pulse once per loop and use a scope, yes. I think I need something more than the Rev Ed scope, plus shipping from the UK would cost something more and would cause a delay. I'm thinking something inexpensive from Amazon that I can get in a couple of days . . .
 

Attachments

AllyCat

Senior Member
Hi,

For 50us real-time triggering, you might need to use the PCB Scope in Logic Analyser mode, so you may as well just use a "spare" PICaxe (with a PULSIN in a loop). To avoid upsetting the existing software/hardware, use an ac coupling (capacitor) from the PICaxe "pulse output" pin to a "bias" pot (adjustable around 1.4 volts) and to a pin of the "measuring" PICaxe. Set the bias a little above 1.4 volts for the "Low" pulses or below 1.4 volts for the "High" pulses. This couldn't measure the width of both (possible) pulses at the same time, but a software loop with two input pins could count the number of high and low pulses, for example by using the "Interrupt on Change" (SFR) Flags.

Also, all the modern PICaxes have internal comparators linked to their "DAC" (bias chain), so the measurement could be done "automatically" with just a capacitor linking the pins of the two PICaxes. Or there are various "low cost" 'scopes on Amazon/ebay, etc. but they tend to have significant disadvantages such as shipping time, self-assembly, power requirements, only a single channel (maybe acceptable for this particular application) and very probably not actually meeting their "specification".

Cheers, Alan.
 

Flenser

Senior Member
I've just done an oscilloscope measurement like PhilHornby on my 14M2, 18M2 & 20X2 chips.
This is a 100 sample average using my DPScope at 400k sample/sec (i.e. 2.5 uS resolution).

With this code:
setfreq M32
main:
HIGH B.2
LOW B.2
goto main

The high pulse length is 14M2: 51.68 us, 18M2: 42.27 us, and 20X2; 69.38 us

and with this code:
setfreq M32
main:
LOW B.2
HIGH B.2
goto main

The low pulse length is 14M2: 51.33 us, 18M2: 42.63 us, and 20X2: 69.81 us
 

PhilHornby

Senior Member
I don't know if it makes a difference, but I used INPUT, rather than LOW, like @wapo54001. (I also used DO...LOOP).

I did notice one interesting thing - that I glossed over at the time...

My Siglent SDS 1052DL, has a 'Measure' function, that can be set to show pulse widths. You can also freeze the display and use manual 'Cursors' to measure an individual pulse.

For the 20X2, these gave identical readings, but for the 08M2 there was a slight discrepancy. From memory, the 'cursor' measurement gave 42µS, but the 'Measure' function said (something like) 43.08µS.

Thinking about it, that must surely mean that the 08M2's pulses were not all exactly the same, as the 'Measure' function would be computing an average.
 

Flenser

Senior Member
Phil,

DPScope has cursors but it also has a measurement window that can be opened to display things like period and the duration of the high and low portions of the pulse which is more convenient so I use it.

I see the same behaviour as you describe when I am collecting the average of 100 samples using the DPScope. The displayed values for these measurements are constantly changing by a little bit as the average is continuously re-calculated as the number of samples increases. I've always assumed that this variation is due to the variations in the amount of work that the PICAXE firmware has to do in the background while it is running the basic commands.

The DPScope has a "Pre Trigger Mode" that allows you to display the pulse with the rising edge at a fixed point on the display (e.g. with the rising edge trrigger point always at 1 division from the left hand side).
When it runs continuously in this mode the left hand edge of the pulse is at a fixed point and you can clearly see the right hand edge of the pulse move back and forward by small amounts because the pulses are not exactly the same duration.
 
Last edited:

wapo54001

Senior Member
I'm ready to buy an inexpensive USB scope from Amazon, thinking -- Picoscope 2204A -- and everthing looks fine to me except I wonder about the 8-bit vertical resolution. Is that good enough? It seems entirely inadequate . . .
 

Flenser

Senior Member
My understanding is that oscilloscopes are for accurately measuring time. They are not intended to be highly accurate voltmeters, hence 8-bit vertical resolution is not generally an issue. I'm sure I have seen scopes with a greater vertical resolution but they were probably more expensive models.

I wouldn't take my word on this. I think that if you took a look at the specs of the different range of models for a couple of brands you would be able to find out pretty quickly what vertical resolution you can expect to get at each price range,

Perhaps another forum member with more experience with oscilloscopes could give you a more definitive answer.
 

julianE

Senior Member
In my opinion, an LDR-based volume control sounds far better than a simple pot or even a stepped attenuator.

My circuit uses four LDR devices to simulate a stereo volume control which requires each LDR to hold a very specific resistance. I use a Picaxe to control the current to each device by setting an output pin either high or low or off to adjust mosfet drive, and a second input pin to measure the actual current flowing through the LDR-mosfet combination to provide feedback. The goal is to achieve a perfect 25K or 50K logarithmic resistance curve stereo volume control using current with values ranging from 10ma to vanishingly small. Also, the LDR resistance curve is nonlinear.
I have experimented with LDR volume control circuits but never achieved smooth control. Please keep us updated with your progress and share any schematics. I have used PWM to control the LED in the LDR and it worked reasonably well. My other plan was to use a very precise D/A converter and control the LED brightness by varying the voltage.
 

wapo54001

Senior Member
JulianE,

I designed and produced my LDR-based volume control maybe 10 years ago now. Unfortunately, as I started to market it I found a new interest in photography which sucked away all my energies, and also I found that all my customers were from -- literally -- all over the world, everywhere except the USA where I live! Figuring shipping and insurance was a pain in the neck and shipping was very expensive, and yadda yadda.

Schematics are all very well and not remarkable, but I needed to discover that I could operate the 28X2 outside published specs which led me to 12-bit or better resolution, and then it took me maybe two years of messing around to really perfect the software to make it work with both speedy change (think slamming the volume control back-and-forth) and then also extreme accuracy once a target is reached. 'Course, I'm a total amateur, no training, only did this because I wanted to show up some people at diyaudio.com, and that's why it took me so long.

Best way to look at my work is to go to www.diyaudio.com and do a search on the two threads initiated by me -- wapo54001 -- but attached is an image of most of the system, with control via IR remote & encoder. The OLED has many more screens that display a variety of information -- balance, current into the LDRs, % calibration finished, Input #1~4, etc. Also not shown is the input selector board itself. All connect with I2C or serial. Picture shows extra connections at top for serial ports for programming the chips, since this was my testbed.

Mainboard control is I2C or 0~5V linear potentiometer (converted to log with math within the chip). Control board manages main board, display, and input selection.

Have done a little more since those days -- added a 4-way input selector and increased the information available on the OLED, plus made it possible to dim the display per the discussion of modifying the display to do that elsewhere in the Rev-Ed forums.

BTW, I believe PWM is nowhere near accurate enough for this application. As I've said above, my final control is via a voltage that is probably 2.5 volts above or below the gate, and correction is delivered finally in 60uS bursts through a 1M resistor. Very delicate corrections. And you need 12 bit resolution in the feedback circuit.
 

Attachments

Last edited:

premelec

Senior Member
FWIW note that LED brightness is better controlled with current rather than voltage.... an op amp and MOSFET converted a DAC to current output [I used 2 LM324s and 8 2N7000 in 8 channel DAC conversion units I made - serial from 08M2 to DAC].
 

julianE

Senior Member
wapo54001,

thank you for the detailed explanation of your project, very well done. i am at a point in life where i simplify things and know what i like. when i go back to the project i will have at most half a dozen positions on the volume control, of course i do want maximum fidelity and close to perfect tracking between the channels.

i am also starting to have serious doubts about my hearing acuity, shocking how difficult it is to hear slight differences in sound, i was convinced that there was a massive difference between tube (valve) audio and solid state, i went and built an AB comparison switch and the difference was very slight. on the other hand the difference between digital and vinyl is obvious, well made vinyl bests and digital audio format. i still listen to a lot of digital files, it's just too convenient.
 

wapo54001

Senior Member
FWIW note that LED brightness is better controlled with current rather than voltage.... an op amp and MOSFET converted a DAC to current output [I used 2 LM324s and 8 2N7000 in 8 channel DAC conversion units I made - serial from 08M2 to DAC].
premelec,

I don't know if this will meet your criteria for current monitoring or not, but my circuit is

+5 --> LDR --> mosfet --> resistor --> GND

I take my feedback from between the mosfet and the resistor, measuring the voltage drop across the resistor and from this, I calculate the current flow through the overall circuit. I use this feedback to control the drive to the mosfet gate. One of my customers back in the day reported that he measured my design as producing a log curve with 0.1 db accuracy across the entire volume control resistance range. I had/have neither the skill nor the equipment to verify that for myself but the fellow was deeply involved in equipment analysis so I'm guessing it must be a good measurement.

An important point -- my control method has no drive "steps" as changes in PWM would create. Mosfet gate drive is driven up or down or stabilized entirely according to feedback information delivered very precisely. This permits the circuit to achieve extremely accurate resistance values.

A commercial outfit -- Tortuga Audio -- achieves similar results with multiple chips including 12-bit devices as compared to my single 28X2 and four mosfets. They charge $850 ~ $1999 for their preamp.
 
Last edited:

wapo54001

Senior Member
i am also starting to have serious doubts about my hearing acuity, shocking how difficult it is to hear slight differences in sound, i was convinced that there was a massive difference between tube (valve) audio and solid state, i went and built an AB comparison switch and the difference was very slight. on the other hand the difference between digital and vinyl is obvious, well made vinyl bests and digital audio format. i still listen to a lot of digital files, it's just too convenient.
JulianE,

I started this project just to show fellow enthusiasts at diyaudio that they didn't need to buy 50 LDRs to select four that had similar characteristics. My goal was to design a circuit where I could take just about any four LDRs and calibrate them to perform flawlessly as a stereo volume control. I didn't expect any particular step up in my hifi system when I inserted this circuit in lieu of my high-end Yamaha preamp, but I was blown away by the new transparency. The rest of my system was still upper-mediocre by an enthusiast's standard, but the step up in sound quality was totally obvious. If you haven't heard an LDR passive preamp, you might consider making that happen.
 

julianE

Senior Member
when I inserted this circuit in lieu of my high-end Yamaha preamp, but I was blown away by the new transparency.
that's phenomenal, i have tried my own LDR volume control and couldn't tell much of a difference from an Alps pot. I have a very good system but nothing spectacular, other than the Dynaudio speakers. I'm sure my hearing has tapered off with the passing years. I hope you do well selling your well thought out design.
 

wapo54001

Senior Member
that's phenomenal, i have tried my own LDR volume control and couldn't tell much of a difference from an Alps pot. I have a very good system but nothing spectacular, other than the Dynaudio speakers. I'm sure my hearing has tapered off with the passing years. I hope you do well selling your well thought out design.
LOL! I have about twenty circuit cards that have been sitting in their static-proof bags all this time. My heirs will probably have to dispose of them when I'm gone.

Now, I'm really into making superb digital copies of positive and negative film images for people of my generation who want to pass on their history to their children. Locally, I do it for free and ask that, if they're satisfied, recipients recognize the service by contributing to local charities who are supporting the oh-so-many people who are in deep trouble right now. Many of my generation (senior geezer) have thousands of images that will be lost unless they get converted. I use the assembly shown below -- a 1960s vintage Honeywell Repronar purchased off Ebay, electronics gutted and replaced with LED strips and vertical upright moved back to accommodate a modern DSLR with lateral adjustment rail.
 

Attachments

Last edited:

premelec

Senior Member
Looks like we had the same basic idea for constant current to LED - I just used an op amp loop to control current from voltage set from a DAC that was PICAXE controlled [the DAC latches in and holds the digital] - the feedback being analog rather than back processed through the PICAXE AD conversion. No need to consider Vgth of MOSFET. Years ago I made compressor amps using LDR in a bridge to differential amp... long before using any micros... So many changes since vacuum tubes of yore... [I've been at it for about 72 years - some interesting components have come and gone]. Currently one of my ears is getting worse [both cutoff at 3K - I used to hear to 20K...] and this has led me to think about making a hearing aid headphone setup rather than fiddling with expensive easily lost tiny amplifiers with short battery life... ;-0 Perhaps amps with digipots controlling the frequency curves - set and forget rather than manual pots. I used to strive for linear wide frequency response... no more... Audio finagler rather than audiophile...
 

lbenson

Senior Member
Now, I'm really into making superb digital copies of positive and negative film images for people of my generation who want to pass on their history to their children
Really impressive setup. What I find daunting, though, are my mother's dozens of carousels of slides and the need, with the gear I've looked at, to do each slide individually. And I'm supposing that no one is going to be very interested in photos of bears from our trip to Yellowstone Park in 1959.

I have digitally photographed old photos of my father and his siblings from around 1919.
 

AllyCat

Senior Member
Hi,
Perhaps another forum member with more experience with oscilloscopes could give you a more definitive answer.
"Traditional" (analogue) 'scopes were rarely used for "precision" (voltage) measurements, the "Deflection Sensitivity" of the CRT, and parallax to the graticule in front of the screen just could not allow high resolution/accuracy measurements. It was "difficult" to generate around 10 kVolts (for the CRT) with better than 1% accuracy, and good quality (analogue) meters had a mirror in the scale behind the needle to avoid parallax. Various "bells and whistles" were added for oscilloscope time measurement (e.g. a second, delaying timebase and ten-turn "vernier" pots, etc.), but still not comparable in accuracy to a dedicated (pulse) timer/counter or a Logic analyser.

Of course that has all changed in the "Digital Domain" where the calibration is effectively "attached" to the signal, but we now have the issue of "Quantisation" of the signal(s) producing "Jaggies", and "Sampling Error" giving time errors (or worse). Particularly when using "standard" hardware, the use of 256 ADC levels (i.e. byte-wide) is "obvious", and it can resolve down to +/- 0.2% (rounded). You're unlikely to find a "normal" voltage meter with an Absolute accuracy better than that. A 'scope can certainly do better in its horizontal (time) axis, but rarely as well as a dedicated Logic Analyser.

Note that I believe the "DPScope" (or maybe it's the DPScope II ) mentioned above, is NOT the same as the simpler "DPScope-SE" on which Rev Ed's "PCB Scope" was based. However, the PCB 'scope does have a Logic Analyser mode (4 digital channels) that the DPScope {2} does not. Of course a Logic Analyser works with only two Levels (binary values) , i.e. above and below a threshold level, which might be "TTL" (~1.4v), "CMOS" (Vdd/2) or something else. However, the OP's design uses a tri-state output (i.e. at least 3 levels) which is why I described (in #9) how to arrange the hardware to interface with either the "Active High" or "Active Low" portions of the pulse output.

I just noticed this post, I will have a look, thanks. I guess the main question is what will the software do . . . .
Before SIGLOK was developed, those (remarkably good) little USB Logic Analyser modules originally used to "hijack" the Excellent (and User-friendly) software developed by the American company SALEAE. I don't know if Saleae managed to "protect" their software/IP, but they now appear to have moved on to adding Analogue channels to their (moderately-priced) hardware, i.e. drifting into Oscilloscope territory rather than Vice-Versa. The SIGLOK software seems quite "competent" with more features than you're ever likely to need, but I do still find myself hankering after the "elegance" of the original Saleae User-Interface. For best results, you do need a mouse with a scroll wheel.

Cheers, Alan.
 

wapo54001

Senior Member
What I find daunting, though, are my mother's dozens of carousels of slides and the need, with the gear I've looked at, to do each slide individually. And I'm supposing that no one is going to be very interested in photos of bears from our trip to Yellowstone Park in 1959.
Young(er) people are no longer interested in family heirlooms or family photos, but people of my generation are still pleased to hand digitized photos on, they consider it a duty accomplished. When my wife and I massively downsized via online auction, the auctioneer started the conversation by saying "You can either get rid of your stuff, or you can make some money, but you can't do both." It was true; younger folks travel light and don't accumulate what they can't carry on their back.

The carousels are a good thing, cuts down on handling by holding the slides separate so you can blow the dust off in situ (I use 30psi compressed air) and then pull them one at a time and photograph them. When I get blocks of slides the first thing I do is put them in a carousel to blow the dust off -- really a mandatory step. With the right setup you can blast through a lot of slides in a few hours. To get best color, there's a program called GIMP -- a free version of Adobe Photoshop and just as good -- or Darktable, also free, which is photography specific. Both allow a form of bulk processing of multiple images to enhance color and sharpness while reducing photo graininess.

The Repronar can be had on ebay for around $100 plus shipping. Replace the electronic flash with LED strips which are available in such tight order that I easily got 144 6500K LEDs into a 3"x4" space. It comes with a slide carrier that can be used, or buy a better carrier for $30 more and modify it a little for maximum speed. Up and running for under $200 for everything, assuming you already have the dslr and lens.

EDIT: The lens must be a prime (non-zoom) and macro capable (1:1) for best results.

Really strayed from Picaxe here, sorry!
 
Last edited:

wapo54001

Senior Member
and this has led me to think about making a hearing aid headphone setup rather than fiddling with expensive easily lost tiny amplifiers with short battery life... ;-0
It appears that hearing aid batteries are on their way out. A friend has told me about a hearing aid that you simply place on a wireless charger overnight and you're good to go in the morning. No battery replacement.
 

julianE

Senior Member
Really strayed from Picaxe here, sorry!
i rather like it when the conversation meanders a little. This board is full of brilliant polite people, everyone brings something to the party. I have dedicated film scanners, i was so worried about demise of film that i have 4 film scanners in stock. I have also filled a refrigerator with enough film to last me the rest of my life, the refrigerator has a picaxe temperature sensor that transmits the temperature to a PC that is web accessible.

I need to start a new thread to ask what aids everyone uses to display data graphically on a web page. I do use thingspeak but i would like something simple that i can serve web pages from my internal web server, right now, everything is just plain HTML text.
 

papaof2

Senior Member
I'm still working on digitizing images from my family and my wife's family, some going back to tintypes and the like. Currently near 100K images on the 2GB drive on the tower computer and so far, only 10K or so of those in a database where content can be searched by person's name, place, date, event, etc. There are far more prints than negatives so smaller pictures are done with a flatbed scanner at 1200dpi and with the scanner glass covered by those smaller images - faster to cut and paste the individual images from that one scan to an appropriately named file than to scan them individually. I also have a slide scanner but haven't yet started on those...

I don't know if the descendants will care one way or the other but I'm also the family genealogist and I want pictures in the family tree. If you can print a family tree and take it a family reunion, it can be a good incentive for people to send you more pictures - and add missing people. I did that when a friend let me use his roll-paper plotter and I could print a 30 inch by 24 foot chart (Yes, it covered most of one wall at the rented meeting facility).
Sample converation:
"Why doesn't <whoever> have a picture?"
"I don't have one."
"I'll send you one when I get home."
 

wapo54001

Senior Member
I'm still working on digitizing images from my family and my wife's family, some going back to tintypes and the like. Currently near 100K images on the 2GB drive on the tower computer and so far, only 10K or so of those in a database where content can be searched by person's name, place, date, event, etc.
And you DO have that backed up to at least two other locations, right??!!
 

wapo54001

Senior Member
II also have a slide scanner but haven't yet started on those...
Maybe you are too far along to change horses, but many of us have given up on "scanners" -- far too slow -- and gone the route of the dslr with commercial or homemade slide copying setup with a backlight to photograph negatives and slides. A dslr achieves 4000dpi -- the scanning gold standard -- at 24 megapixels which is pretty inexpensive today. The 1:1 macro lens to provide superb resolution will be a bit more . . .
 
Top