Show Posts
Pages: [1] 2 3 ... 54
1  Using Arduino / Programming Questions / Re: knock sensor problem on: September 10, 2014, 08:04:24 am
Quote
would expect the analog reading to be zero if the piezo is not being touched and there is a 1 meg to ground, yes?
No.
Quote
Or is he seeing leakage from the A/D converter circuitry that a 1 meg can't swamp out?
It is not leakage it is pick up interference. In effect this input is floating.

The 328p data sheet (Rev. 8271H – 08/2013, page 301) states that the leakage current of any I/O pin is 1 microampere (max) for both low and high level.

So, a 1uA current through a 1 meg resistor is 1 volt. With an A/D output range of 0 to 1023, 1 volt would show as a reading of around 205 (decimal). The OP was getting a reading of 322...327 which makes me suspect that he WAS seeing leakage.

Also, the datasheet says that something driving the A/D input should have an output impedance of 10K ohms or less, to swamp out the internal capacitance and leakage current of the input.

Lastly, how can you say that a pin connected to VCC or GND through a 1 meg resistor is "in effect, floating"? Floating means there is nothing defining it's state (i.e. a resistor or an active driver) or in other words an OPEN, UNCONNECTED input.

1 meg is less than ideal for most digital uses (bias for a cmos inverter crystal oscillator circuit being one exception) but it certainly doesn't result in a "floating" input.

I agree with you though....... that piezo circuit as posted is a LOUSY design.
2  Using Arduino / Programming Questions / Re: knock sensor problem on: September 10, 2014, 07:42:06 am
I will try what Krupski suggested but I really don't want to tie up 2 analog pins.

Well what would work even better is an op-amp. Connect the piezo between the inverting and non-inverting inputs and setup the gain to give you a nice strong (volts range) signal from the piezo when a knock is detected.

I would suggest using an op-amp that is designed for single supply use, then run it from the 5 volt rail of the Arduino and bias the non-inverting pin at 1/2-1/2.

Pros:
(1) Single supply op-amp does not need a biploar supply.
(2) Protection - the op-amp output cannot swing below zero nor above 5 volts, thereby protecting the analog input pin
(3) Better signal - the differential connection of the piezo will give you the common mode noise rejection you need, and the gain will give the Arduino a nice, reliable signal. You can even add a few capacitors and resistors to make a high-pass or band-pass filter to further clean up the piezo signal.
(4) You will then only need one analog input on the Arduino.

Cons:
(1) More parts
(2) More cost


Lastly, you may want to add a snubber (two 1N914 or 1N4148 diodes in parallel, opposite directions) to clamp the piezo output to approximately +/- 0.7 volts. A piezo can produce very high voltages if given a step input (that's how gas grill igniters work!). An accidental tap or touch on the piezo could burn out the op-amp without the diodes.

|--->|---|
|---|<---|

Above is what I mean... back to back diodes.

Hope this helps.
3  Using Arduino / Programming Questions / Re: Calculate RPM and Speed / Store to varibale on: September 09, 2014, 09:52:42 am
Quote
I would need something similar, a snippet which I can include in my code to invoke it something like.

ReadValues(rpm, kmh);

To store the value to a variable.
So, fire up the IDE and start writing. The homework hotline is closed for vacation. It'll open again in 6 months.

If you look at his past posts (follow the link he posted) you will see that this is obviously not homework.
4  Using Arduino / Programming Questions / Re: knock sensor problem on: September 09, 2014, 09:15:22 am
Quote
I get a value fluctuating between 322 and 327 even if the piezo is not being 'knocked'.
That sounds fine.
The load resistor of 1M is too high to reduce all the interference getting into the pin, so there will be some background variations.

I would expect the analog reading to be zero if the piezo is not being touched and there is a 1 meg to ground, yes?

Or is he seeing leakage from the A/D converter circuitry that a 1 meg can't swamp out?
5  Using Arduino / Programming Questions / Re: knock sensor problem on: September 09, 2014, 09:13:52 am
Hello,

I am experimenting with this project and followed exact instruction and code from the site (http://arduino.cc/en/tutorial/knock).  I am using a Radio Shack 12V piezo (273-065).  However, when printing to serial port, I get a value fluctuating between 322 and 327 even if the piezo is not being 'knocked'.  

I tripled checked the circuit which is a trivial one (I have piezo +ve to A0, -ve to ground and a 1M resistor in parallel with the piezo), leaving me puzzled as to why I am not getting this.  

Should I have a different piezo?

Thanks for your help in advance.

Al

I've never tried that circuit or code, but if I were going to do it, I would do a few things:

(1) Bias the analog input about 1/2 and 1/2 with a pair of large value (like 1 megohm) resistors. The piezo can output a negative or positive charge depending on which direction it's deflected.

(2) POSSIBLY average a few analog readings to clean up the signal. You would have to play with the averaging amount, because averaging is equivalent to a low pass filter. A door knock is likely to be more of an impulse (high frequency) signal, so too much averaging would "low pass" it away.

(3) Use a twisted pair of wires between the Arduino and the piezo.

Also, connect it in a differential manner (that is, between two analog inputs, not one input and ground). Then look for the DIFFERENCE between the two analog readings.

Note that any common mode noise (like 60 hz noise) will be ignored because it will cause the same signal on both inputs, the difference being, of course, zero.

So a differential input will ignore noise and only read the piezo.


Hope this helps.

(edit to add): Added diagram for differential mode
6  Using Arduino / Programming Questions / Re: How to generate repetitive characters? on: September 09, 2014, 09:04:45 am
What happens if you do

Code:
const char *options[3][20] = {
    "voltage",
    "current",
    "power"
};

There will be space after the strings but I'm not sure what values will be inserted. Maybe that doesn't matter unless you really need 0s.

______
Rob


Thanks. Interesting idea. I'm not sure that it would work though, because I need to insure that the zeros come immediately after the string in memory.  With your method, I think the compiler would put the variables anywhere it wanted to (and not necessarily in a contiguous manner) right?
7  Using Arduino / Programming Questions / Re: Programming stepper motor drivers on: September 09, 2014, 09:01:32 am
Quote
And I am wondering whether I can control this with stepper library or not ?
No. The Stepper library can not control that picture.

Really?
8  Using Arduino / Programming Questions / Re: Programming stepper motor drivers on: September 09, 2014, 08:53:32 am
Hi !
I recently wanted to make a little project that involves driving stepper motors , which requires drivers .
I wanted to use ULN2003 modules OR maybe the famous EasyDriver  smiley-grin  But I had a question about programming them :
Can I program both/any with Stepper library ? Or does it need some sort of special library ? Because I'm not a professional programmer so I want to do something simple .
And can I use Unipolars with EasyDriver ?
Thanks !!

If you are going to "bit bang" the stepper by individually driving each lead (with an H bridge or darlington array), you need to write your own sequencing code to turn the coils on and off in the proper order (and whether you are using a unipolar or bipolar motor).

BTW, I suggest using a bipolar motor.

If you use a stepper driver chip or stepper driver breakout board (HIGHLY recommended!), then all you do is send it a digital level for direction (CW or CCW) and one pulse per step. Super easy.


Here's a simple bit-banger that I wrote. It's probably not the best, but it works well - use it if it helps you.

Code:
// map arduino pins to motor driver leads
// don't forget to enable "enable" pins if necessary!
const uint8_t pins[] = {
    _OUT1_PIN, _OUT3_PIN, _OUT2_PIN, _OUT4_PIN
};

const uint8_t bits[] = {
    0b1000, //0b1100, // uncomment for half step
    0b0100, //0b0110,
    0b0010, //0b0011,
    0b0001, //0b1001,
};

uint8_t sop = (sizeof (pins) / sizeof (*pins)); // size of pins
uint8_t sob = (sizeof (bits) / sizeof (*bits)); // size of bits
volatile uint8_t POS; // position (relative)

// steps can be negative or positive to control direction
// for a 200 ppr motor, "rotate (200)" turns 1 revolution
// "rotate (-200)" turns 1 revolution in the opposite direction
void rotate (long int steps)
{
    uint8_t x;
    int8_t dir = (steps < 0) ? -1 : 1;
    long int y;
    long int z;
    z = abs (steps);

    for (y = 0; y < z; y++) {
        x = sop;
        while (x--) {
            digitalWrite (pins[x], bits[POS%sob] & (0x01 << x));
        }
        POS+=dir; // change to POS -= dir; to swap CW and CCW
        _delay_ms (3); // adjust for desired step rate
        // or use _delay_us () for finer control
    }
}


(edit to add): If you use the code above and your motor only turns one step back and forth instead of rotating, change the ORDER of the motor pins. For example, instead of "_OUT1_PIN, _OUT3_PIN, _OUT2_PIN, _OUT4_PIN", you may need "_OUT1_PIN, _OUT2_PIN, _OUT3_PIN, _OUT4_PIN".  The sequence will be obvious once you look at it.
9  Using Arduino / Programming Questions / How to generate repetitive characters? on: September 09, 2014, 08:40:08 am
Hi all,

If I have a piece of code like this:

Code:
const char *options[] = {
    "voltage\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
    "current\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
    "power\0" "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
};

Instead of manually counting and typing all the "\0" characters, is there a way to do something like this:

Code:
const char *options[] = {
    "voltage\0" rep "\0", 16,
    "current\0" rep "\0", 16,
    "power\0" rep "\0", 16,
};

Or even better:

Code:
const char *options[] = {
    "voltage\0" rep "\0", sizeof (double),
    "current\0" rep "\0", sizeof (double),
    "power\0" rep "\0", sizeof (double),
};


Lastly, notice that there is NOT a comma between "voltage\0" and "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",. The array "options" has only 3 elements, not 6 as it appears at first glance.

Thanks!

-- Roger
10  Using Arduino / Programming Questions / Re: Compiler math bug 2*60*1000 = -11072 on: August 11, 2014, 11:59:52 am
Range for unsigned int is actually 0 to (2^16)-1, or 65535, or 0xFFFF.
Similarly unsigned long os 0 to (2^32)-1, easier to write as 0xFFFFFFFF.

Very true. But I didn't say UNSIGNED INT. I said INT.

And, when trying to figure out how much a 16 bit int (or register for that matter) will roll over, you deal with 65536, not 65535.
11  Using Arduino / Programming Questions / Re: Compiler math bug 2*60*1000 = -11072 on: August 11, 2014, 11:53:16 am
Hi all,

I just found a bug that cost me some headache because I would have never thought this calculation could be executed the wrong way. Here is the code:

You used an INT which on the Arduino is 16 bits. Since an INT is signed, it can hold from +32767 to -32768.

Trying to store a value of 120000 in a 16 bit signed int leaves you with a value of 120000 mod 65536 or 54464.

But since the int is SIGNED, a value greater than +32767 is a negative number. What number?  54464 - 65536 = -11072.

The solution to your problem is to use a larger variable... try uint32_t.

By the way, that "65536" number is 2^16 (16 bits).
12  Using Arduino / General Electronics / Re: Transformer / Rectifier question on: August 10, 2014, 07:39:16 pm
Actually somewhere around 1.4 times the current.  The losses in the secondary
windings are proportional to I-squared so having half the winding resistance allows
root-2 times more current for the same losses in the secondaries.

However the primary losses are also important as well so the factor is probably less
than 1.4


Well, I wasn't worrying about the nitty-gritty of transformer winding resistance or the loss across diodes in a bridge... I was thinking that somehow I wasn't using 1/2 of the transformer's capability.... and as it turns out Grumpy_Mike was right and then I saw it as plain as day.
13  Using Arduino / General Electronics / Re: Transformer / Rectifier question on: August 08, 2014, 01:18:54 am
Quote
(specifically, that the top circuit provides all the transformer current where the bottom one only provides half)
Yes that is it.

They are both full wave rectified but the top one will provide twice the current of the bottom one.

Yup. I see it now. Why it eluded me until now I have no idea, but now I get it.
14  Using Arduino / General Electronics / Re: Transformer / Rectifier question on: August 08, 2014, 01:16:01 am
The voltage are a little bit lower from the top one.
Powerloss in the rectifier are twice .

Current are lower for the bottom one, if not compensated with thicker winding wire

Pelle

The answer suddenly came to me... looking at my own drawing. The bottom circuit could be done identically with 1/2 of a bridge rectifier. This implies that a "mirror image" circuit (another capacitor on the other side of the bridge supplying a negative voltage) is available, whereas the top circuit has no "unused negative side" (if this makes any sense).

So, as Mike said above, yes the top circuit does indeed provide twice the current (i.e. all the transformer current) because it has no "unused negative side".

For what it's worth, the reason I'm doing this is that I'm building a high current (10 amp) adjustable linear power supply and I intend to use a relay to switch between 9 VAC and 18 VAC depending on the setting of the output voltage (to limit regulator dissipation at low output voltage settings).

In other words, if I get about 12.7 volts DC peak from the 9 volt winding, I would do something like this:

Output voltage - Winding used
1.2 - 9
3.3 - 9
5 - 9
6 - 9
9 - 18
12 - 18
15 - 18

Somewhere around the 6 to 7 volt output range, the regulator input would switch from "low voltage" to "high voltage" (with hysteresis of course to prevent a "bad spot" where the selection can't make up it's mind and it chatters).

This whole project is just for fun... it's going to use an Arduino controller, a stepper motor and 10 turn pot to set the output voltage, a graphic VFD display for voltage, current, regulator temperature, an LM-317 plus PNP power BJT's for the regulator, Arduino controlled fan, etc...

Completely useless... just something to play with.  smiley
15  Using Arduino / General Electronics / Transformer / Rectifier question on: August 08, 2014, 12:45:08 am
Please see the attached drawing... my question is: Is there any difference between the two circuits?

I traced the current flow paths for each half cycle and found no difference, yet my "gut feeling" is telling me that there IS a difference (specifically, that the top circuit provides all the transformer current where the bottom one only provides half).

This is one of those things that I've been looking at for too long and thinking about too much and I'm blanked out.

So, what's the verdict?

Thanks!

-- Roger
Pages: [1] 2 3 ... 54