Random or Pseudorandom Analog Meter Movement Project – I’m Stumped!

OBW0549

Joined Mar 2, 2015
3,566
So neither of you have a link that shows a PIC IN A CIRCUIT, and text that treats the programming and shows the IO of the chip in context? I am getting CLSE to the most rudimentary grasp of these, but would like to see one actually doing something that looks like "analog". Just the way my brain learns.
Keep reading, especially the datasheet for the appropriate PIC (I'm thinking either the PIC10F322 or the PIC12F1572).

Also, the user documentation for the XC8 C compiler (or the MPASM assembler), the MPLAB-X integrated development environment (IDE), and the PICKIT 3 programmer/debugger tool.

Meanwhile, I'll try to whip up a schematic for you and post it, probably Monday or Tuesday.
 

djsfantasi

Joined Apr 11, 2010
9,163
Just thinking out loud, but a non-microprocessor solution could be a pseudo random number generator built from a shift register, connected to a D2A converter built from an R2R ladder connected to the meter...
 

GopherT

Joined Nov 23, 2012
8,009
@Dibubba
You can run a stepper motor with a 555 timer. The stepper motor has a black paper platter (8 to 12" diameter). The plater has some slits of various size. A IR LED on one side and a photo transistor on the other. Ach about an inch or two from the platter so you get some good 'shadows' and masking from the patterns cut in the paper.


You could add a second motor and use a visible light and a LDR with a platter. Connect this one to the 555 timer that drives the stepper motor. It will randomly delay the cycle time of the 555. The combination of variable timing of the 555 along with various intensity from the second wheel gives a very random output.
 
Last edited:

blocco a spirale

Joined Jun 18, 2008
1,546
OBW0549 and Blocco:

All day long, when not actively-engaged with the Honeydew Subroutine, I've had my head stuffed into the iPad, reading-up on the links you sent. Lots to Learn.

So neither of you have a link that shows a PIC IN A CIRCUIT, and text that treats the programming and shows the IO of the chip in context? I am getting CLSE to the most rudimentary grasp of these, but would like to see one actually doing something that looks like "analog". Just the way my brain learns.

I'll keep reading in the meantime... But thanks to you (and all others here!) for your support!! :)
I haven't written any PIC code for a long time but about 14 years ago I wrote a simple routine for driving RGB LEDs for someone who wanted a colour-changing lamp. The PIC has three PWM outputs that ramp slowly toward random values every few seconds i.e. it is exactly what you need. I'll take a look at the code and remind myself how it all works. I believe it was written for a 16F84 but was modified to run on the smaller OTP 8-pin 12C509. Once the PIC is programmed you can glue it down dead-bug-style and wire directly to the pins. Then, test it and cover it with a blob of epoxy resin or hot-glue.

The best way to learn PIC programming is to just do it; buy a programmer and a few common inexpensive flash memory PICs. Copy some very simple LED flashing .asm code from the internet, compile it to a .hex, and program the device. It may take a few attempts to get it all set up but it is very easy to do. You can then modify timings, reassign ports, add more outputs, more LEDs, add inputs etc. and see the results of your changes. You can always go backwards when it doesn't work. The point is, every time you make a change you will have learned an essential programming skill. You will be amazed by how quickly you pick it up and are able to take control of the device.

Start with something like this:

http://www.pcbheaven.com/picpages/A_Simple_LED_Flasher/
 
Last edited:

DickCappels

Joined Aug 21, 2008
10,180
If you want to keep it analog, you can make a noise generator by reverse biasing the emitter-base collector of a transistor, couple that noise to an AC amplifier, low-pass filter the noise, then put it through an absolute value circuit. The absolute value circuit drives the meter movement.
 

Sensacell

Joined Jun 19, 2012
3,449
I built exactly this device as an art project- PIC10F220 microcontroller with a pseudo-random bit sequence generator that drives a PWM output.
I wrote code that makes the meter hang at a random value for a random time, it's really fun to watch. The thing runs from 2 D cells for at least a year, a voltage reference and a pot sets the full-scale deflection on the meter, the reference keeps the position from changing as the battery dies.

Trying to achieve this with analog will take 20X the effort and parts.

The hardest part of the analog approach is the low-frequency randomness that you want, white noise will not produce the behavior you seek.
 

atferrari

Joined Jan 6, 2004
4,770
How would you get usable random noise (for this project) using low voltage like 3?

A small PIC is a good idea and could be good for more than one meter.
 

Sensacell

Joined Jun 19, 2012
3,449
How would you get usable random noise (for this project) using low voltage like 3?

A small PIC is a good idea and could be good for more than one meter.
A pseudo-random number generator with a nice long shift register produces randomness that for this application is totally sufficient.
In point of fact, the sequence is always the same, but it's so long and complex you could never tell the difference.

The supply voltage is irrelevant, it just powers the chip.
 

Sensacell

Joined Jun 19, 2012
3,449
Ok, here is another way:

Wire up a bunch of 74C14's as asatable square wave oscillators with differing frequencies. (random resistor and cap values)


Wire the outputs into a summing junction with resistors, the voltage of this junction will vary step-wise every time an oscillator changes state.
The oscillators will always run in random phase, temperature changes etc. will ensure some true randomness.

12 oscillators will produce 4096 different voltages.
 

atferrari

Joined Jan 6, 2004
4,770
A pseudo-random number generator with a nice long shift register produces randomness that for this application is totally sufficient.
In point of fact, the sequence is always the same, but it's so long and complex you could never tell the difference.

The supply voltage is irrelevant, it just powers the chip.
I failed to say "using analog techniques". Reversed junctions are hard to work with at low voltages like 3V.
 

djsfantasi

Joined Apr 11, 2010
9,163
I guess Analog Kid liked my idea of using a shift register. Here's a schematic of using an 8 bit pseudorandom number generator from a shift register, with a 4 bit R2R DAC to generate a random voltage to drive your meters. The schematic shows individual flip flops, but can be realized with a CMOS 4015 dual 4-stage shift register chip.pRNG Meter Drive.PNG When copying the schematic, the connection to both inputs of the unused XOR gate disappeared. Both inputs should be grounded.
 

OBW0549

Joined Mar 2, 2015
3,566
I'll try to whip up a schematic for you and post it, probably Monday or Tuesday.
Here's my version of a "no frills" circuit using a PIC10F322:

Widget.png
There's not much to it:
  • J1 is a 5.5mm barrel jack for power (nominally 7-15 VDC from a wall-wart), though you could use whatever you prefer for power entry.
  • U1, C1 and C2 regulate incoming power down to +5 VDC for the PIC. You can eliminate these components if you prefer to operate the device off a 5 VDC wall-wart or from a battery.
  • C3 is a ceramic decoupling cap soldered directly at the PIC socket.
  • The PIC, U2, is configured with RA0 and RA1 as PWM outputs, RA2 as an analog input, and RA3 as a digital input with internal pullup enabled.
  • S1 is a pushbutton switch. Your code can be written to make something interesting happen when it is pushed.
  • R3 is shown as a potentiometer, but can also be a resistor string voltage divider with a rotary switch selecting which tap is connected through to the PIC's RA2 input. Your code can have the PIC measure the voltage on this pin and make stuff happen based on the result.
  • M1 is your analog meter movement, with R1 setting the full-scale current appropriately.
  • LED1 is your jeweled panel lamp, with R2 setting its full-scale current level.
Using a PIC12F1572 instead of a PIC10F322 would give you two additional pins for inputs or outputs. It would also give you 2.0K of code space, rather than 0.5K, allowing you to code more interesting behavior.
 

AnalogKid

Joined Aug 1, 2013
11,048
If you don't pink noise filter the LFSR output before the D/A, I think there still will be too much high-frequency movement (jitter) in the output.

ak
 

Bernard

Joined Aug 7, 2008
5,784
Mondays are chopped up with group breakfast & bowling with finger pain but did manage a 161 on one game & still finished breadboard including self induced problems. Strange things are going on, random pulse generators seem to be learning a pattern, but same cure as used in " Fire Fly in Bottle" might work- tomorrow.
 

OBW0549

Joined Mar 2, 2015
3,566
Here's another possible approach. If you like the flexibility of the microcontroller approach but don't want to expend the time and effort (and hair-pulling) involved in climbing the learning curve with PICs and the MPLABX development system, one of these might be the answer:

https://www.adafruit.com/products/1501

Essentially, it's a low-cost "mini-Arduino" with 5 GPIO pins that can be configured in various ways, giving you multiple analog inputs and PWM outputs. It uses the super-simple Arduino IDE (https://www.arduino.cc/en/Main/Software) for programming, which is done in C/C++ via a USB port on your PC.

There's also a tutorial for this gizmo, at https://learn.adafruit.com/introducing-trinket.

At $6.95 apiece, it's about $5 more than the cost of an 8-pin PIC and a quality IC socket, but the drastic reduction in time, effort and frustration might more than make up for the higher hardware cost.

I have a love/hate (mostly hate) relationship with the Arduino and its clones such as this one, but there's no denying that for some applications, it can be just the ticket-- and this is one of those applications. And even if you end up deciding to save $$$ by using a PIC in the end, this device might be a good platform for developing the software and trying out different schemes to see how they look.

Something to consider, anyway...
 
Last edited:

Roderick Young

Joined Feb 22, 2015
408
And one more choice to consider is a PICAXE, which is a PIC, but with useful routines pre-programmed. If you have a serial port on your computer, you don't even need a chip programmer, as the chip can be programmed through the serial port. Oh, and the programs are written in BASIC, so it's real easy to make changes. On the low end, an 08M2 PICAXE is about $3.
 

Bernard

Joined Aug 7, 2008
5,784
Here is my version: U4 is still misbehaving, it likes stage 2, pin 4 & ignores 3 &4.
In comparison to a PIC there are a lot of connections, so if I needed more than one, believe PIC would win
As shown, on power-up nothing happens, so a 2 m R is added from U2-7 to + supply so that U2 will start pulsing after about a minute delay
If working, there are 5 V steps, 3 filter positions & 3 time settings.
Unless you have an interest in this thing, it's going on a back burner to stew for awhile but will keep breadboard intact for now.DANCING METER 00000.jpg
 

Thread Starter

Dibubba

Joined May 15, 2015
16
Wow, I HATE auto- complete!!

I sounded snarky last post, my apologies! I MEANT to say: "Do either of you have a link that shows a PIC in a circuit...."

Yeesh, sorry!
 

Thread Starter

Dibubba

Joined May 15, 2015
16
Here is my version: U4 is still misbehaving, it likes stage 2, pin 4 & ignores 3 &4.
In comparison to a PIC there are a lot of connections, so if I needed more than one, believe PIC would win
As shown, on power-up nothing happens, so a 2 m R is added from U2-7 to + supply so that U2 will start pulsing after about a minute delay
If working, there are 5 V steps, 3 filter positions & 3 time settings.
Unless you have an interest in this thing, it's going on a back burner to stew for awhile but will keep breadboard intact for now.View attachment 90574

DANG, Bernard! That's impressive! :)

May we assume the caps are u, unless otherwise notated? I'll bb this up and see how it looks. It IS complex, yes... But man, I really appreciate the idea! A PCB would sort that part out.

Thank you again!
 

Thread Starter

Dibubba

Joined May 15, 2015
16
And one more choice to consider is a PICAXE, which is a PIC, but with useful routines pre-programmed. If you have a serial port on your computer, you don't even need a chip programmer, as the chip can be programmed through the serial port. Oh, and the programs are written in BASIC, so it's real easy to make changes. On the low end, an 08M2 PICAXE is about $3.
Grazie, Roderick! Yeah, I remember serial ports. As a kid, we'd drop them in a bowl, pour milk and sugar on them... Crunchy and tasty, and a nutritious start to the day! :)

Seriously, though... I'm sure I can get an adapter.

So... On the digital front - an area I have never been to - I'm faced with differing technologies (PICs vs. PICAXE vs. BASIC-stamp vs. Arduino vs...). Upon which should I focus my learning curve? Arduino is out, just because of costs for this one project. But in general?

Teach a man to fish. Opinions? Experiences? Jaded rank Editorial? :)
 
Top