Show Posts
Pages: [1]
1  Using Arduino / Sensors / Re: Encoder interrupts not working right when I use a shift register... on: August 01, 2014, 08:30:44 pm
Since my project doesn't really NEED an encoder, I decided instead to use Up and Down keys along with "Enter" and "Cancel" buttons. The reason I originally wanted a knob was so that I could move quickly by spinning the knob fast, and get right on the money by turning it slow (in other words, a pseudo-analog type of control). But, I discovered I could do that by having the incrementing of the minutes speed up the longer the button is held.

One solution I contemplated, but never actually tried, was to have an ATtiny84, whose job was basically just reading the encoder and talking back to the ATmega.

In a nutshell, the ATtiny would count pulses from the encoder, hold the "Forward" or "backward" pin HIGH until it gets an ACK from the ATmega, then it would subtract a count and momentarily turn off the direction pin, then turn it back on when the ACK input goes low.

This would prevent timing issues with the ATmega from interfering with the encoder process, as well as negating the need for interrupts (Not that they're necessarily bad, but there's quite a few specific things to keep track of that newcomers might find daunting. As I said, I did get it to work, but it quit when I added on to my program).

However, if you're reading an encoder for feedback purposes rather than a user interface (i.e. some kind of automated machine with precise positioning needs) you'd probably need either a faster processor, more efficient code, or both. One could also have a separate MCU for reading the encoder(s) and controlling the appropriate motor(s), which would simply listen for commands from the main computer.
2  Using Arduino / Sensors / Re: Encoder interrupts not working right when I use a shift register... on: August 01, 2014, 11:34:07 am
Here's a schematic as well.
3  Using Arduino / Sensors / Re: Encoder interrupts not working right when I use a shift register... on: August 01, 2014, 10:51:30 am
Here's the ISR for the encoder.


void encoder()
{

  if( digitalRead(ENCB) == LOW )
  {
    Pos++; //if B and A are on at the same time, the knob is moving one way
  }
  else
  {
    Pos--; //else it's moving the other way
  }

  if(sendCnt)
  {

    if(Pos > 1)
    {
      Cnt++;
      Pos = 0;
      //increase Count by 1 and reset position to 0
    }
    else if(Pos < -1)
    {
      Cnt--;
      Pos = 0;
      //decrease Count by 1 and reset position to 0
    }

  }

}

END ENCODER CODE

Here's the code for the shift register:

void ReadSws()
{
  
  CSIS = SrIn();

  for(int z = 0; z < 8; z++)
  {
    Sw[z] = bitRead(CSIS, z);
  }
  if(PSIS != CSIS)
  {
    if(millis() - lastDb > DbTime)
    {
      if(debug == true)
      {
        Serial.print("Debounced switch status: ");
      }
      for(int z = 0; z < 8; z++)
      {
        DbSw[z] = Sw[z];
        if(debug == true)
        {
          Serial.print(DbSw[z]);
        }
        
        
      }
     if(debug == true)
    {
     Serial.println(" ");
    }
      PSIS = CSIS;
      lastDb = millis();
      
      if(DbSw[Knb] == false) //If active low switch is on
      {
        KnobPressed = true;
        DbSw[Knb] = true; //Reset DB variable to off
      }
    }
  }
  else
  {
    lastDb = millis();
  }



}


byte SrIn(){
  byte x;
    digitalWrite(CE, HIGH);
  digitalWrite(PL, LOW); //Tells shift register to read inputs
 delayMicroseconds(UsecD1);
  digitalWrite(PL, HIGH); //Tells shift register to store input status
  digitalWrite(CE, LOW);
  for(int z = 0; z < 8; z++)
  {
  
  bitWrite(x, z, digitalRead(Din) );
  digitalWrite(ClkIn, HIGH);
  digitalWrite(ClkIn, LOW);
  
  }
  return x;
}

END SHIFT REGISTER CODE

PartClockMenu3 is a functional build, which does not include code for the shift register.

Nw_ShiftRegClock is the one that is having the problem with the encoder only reading in one direction. It includes the shift
register code. The shift register must be somehow related because when I comment out the call to the shift register read
function, the knob works fine.

I don't have the actual LCD programmed in yet, but I was planning ahead with the shift register so that I wouldn't have to program multiple things in at once. (The shift register and the LCD) In other words, I was planning on adding the LCD when I was certain that everything else was working as expected. The way I am viewing the results of the program at the moment is via Serial.print()
4  Using Arduino / Sensors / Encoder interrupts not working right when I use a shift register... on: July 31, 2014, 10:37:44 am
I'm trying to use a mechanical 2 channel rotary encoder as a user interface device. I had one of the switches connected to interrupt 0 with the input pullup turned on, and the other one connected to pin 3, which is set up as a regular input pullup (without the interrupt). Pin 3 is read within the interrupt function, using an "if-else" statement to decide whether to increase or decrease the counting variable.

Up until recently, I had it set up with one button to select stuff, but the project in question (an alarm clock using a character LCD) will need more I/O pins than the ATMEGA328P itself has. I figured shift registers would do the trick. So, I set up the "supporting code" for an input shift register in a separate function that is called at the beginning of the main loop. Now, the interrupt service routine still gets triggered, but it never seems to read the second switch on the encoder as it should within the interrupt function. As a result, I can only turn the knob in one direction.

Since I did do quite a bit of rewiring, I checked the wires to the encoder as well as it's ground connections. Then, to rule out the relatively small chance of the ATmega328 itself being broken, I connected the wire for the second switch directly to ground and spun the knob with only the first one connected. Then, it turned only in one direction, but opposite of what it was doing before, so this proved that both the software and the hardware were still able to read pin 3-but maybe not reliably enough to catch a momentary pulse...

I did comment out the shift register function to ensure that the encoder, itself, was still working properly (Hardware and software wise, since I had to mess with both to add the shift register) Without the shift register code, the encoder works as it should, reading rotation in either direction.

Although I have things in my shift register code that I don't have elsewhere (A few For loops and bitRead() and bitWrite() ) I've read the references to those functions and see nothing that suggests that they will interfere with interrupts.

At this point, I'm lost. All I know is that it must be some kind of software issue because commenting out the shift register code makes the encoder work again.  If the encoder didn't use an interrupt, I would suspect that my code was "too long" for the processor to catch the encoder pulses...
5  Using Arduino / Microcontrollers / Re: Arduino Pro 8mhz bootloader problem (ATmega328p) on: March 19, 2014, 12:35:50 pm
Never mind, it turned out to be a PEBKAC error. I didn't hook up AVCC properly (the wire was loose so there was no actual voltage on that pin) and for whatever reason, this caused the chip to work on 5v but NOT on 3.3v. I didn't think to check the power and ground connections simply because it worked fine on 5v  smiley-mr-green

Not sure why AVCC (for the analog to digital converter) would be required ONLY for 3.3v operation. I guess only the AVR engineers would know- or maybe not  smiley-mr-green

Somewhat embarrased, but I figured that I can't be the only one who had this problem and I was hoping to "save" someone from this very situation  smiley-mr-green
6  Using Arduino / Microcontrollers / Arduino Pro 8mhz bootloader problem (ATmega328p) on: March 10, 2014, 11:26:18 am
Hey,

I'm having an issue with an ATmega328p. I was planning on using it in a project that runs on 3.3v instead of 5v, so I got an 8 MHZ crystal (with capacitors) and an ATmega328p. I was planning on using the Pro 8mhz bootloader on it. The bootloading process seems to go over without a hitch, at which point I do the "upload using programmer" option to upload my "blink" sketch to the chip. (I changed the blinking LED to pin 9 so that it would not be using the SCK pin)

The blink sketch works just fine running off of the 5v from my Arduino Uno. However, when I disconnect the Uno and attempt to power the chip with a 3.3v regulator, it is totally inert. I've checked the voltages everywhere when the 3.3v regulator is on, and it's not a power problem.  It's not the LED/resistor combination either because if I connect them across 3.3v, the LED lights up.

I thought maybe it was a bug in the bootloader program, like it didn't set the "brownout detect" fuse to the correct value or something like that. I can tell that my external crystal is working and the chip is running off of it, because it only works (on 5v) when said crystal is connected. I've already checked and rechecked the "board" and "programmer" options.
7  Using Arduino / General Electronics / Re: Electrical contact lube? on: November 27, 2013, 05:21:06 pm
I think I'm understanding you. The contacts in question are "logic" switches and thus, do not carry a great deal of current. Thus, the "non-conductive-ness" of the grease probably wouldn't have much effect.
8  Using Arduino / General Electronics / Electrical contact lube? on: November 27, 2013, 03:09:38 pm
Hey, all you engineers out there,
I just took apart an electric piano (Casio CTK-500) because one of the switches broke. I figured, if I can't fix it, I'll circuit bend it. I believe I will be able to fix it, so that's not really my question.

Here's how the switches work. There is a plastic block with metal contacts glued to it. The contacts ride on the circuit board below, connecting the right "tracks" together for a given position, but there is a ball bearing on a spring lined up with grooves to provide an artificial "detent" when moving the switch. There is some kind of grease on the contacts and on the circuit board. But, so many sources I've read have warnings saying NOT to lubricate electrical contacts. When I think about it, that does make sense for a number of reasons:
1. If the lube doesn't conduct well, of course the switch won't work well (or at all)
2. If the lube is conductive, it might let current go through paths that it shouldn't (in a multi-position or multi-pole switch) causing erratic or unexpected operation, or worse, the lube could "run" or "creep" into areas where it shouldn't be and connect two things that shouldn't connect, ruining the device. Over-lubricating mechanical components can also have this effect if the lube "runs"
3. A lot of lubricants (oil in particular) are flammable. Flammable liquids probably aren't a good thing to have around a powered circuit.   smiley-grin
4. Many lubricants attract dust and grime over time, and dirty contacts make for poor/intermittent connections.

With all that in mind, I was somewhat surprised to see the contacts greased like they are. At least there's not too much where "creepage" would be a problem, but how does it allow the contacts to work, without shorting the tracks at the same time? Having said that, I am somewhat surprised, based on the mechanism employed (metal contacts sliding on a circuit board) that the switches haven't had more problems, even with lubrication. The piano is around 16 years old.
9  Using Arduino / General Electronics / Re: LM317 regulating voltage but no current! on: February 10, 2013, 05:30:02 pm
Remember the golden rule: If so many things are wrong that you fail to understand how they can be so wrong, check the ground connections smiley-mr-green

Also, make sure the regulator isn't getting hot when it's sitting regulating voltage w/o load (and with load as well) because the LM317 has thermal overload protection to protect fools from themselves. If it is getting hot, use a heat sink, even an alligator clip on the top may do the trick! Remember, the bigger the difference between the input and the output voltage, the more heat is going to be dissipated. So, if you're regulating 30 volts down to, say, 9 volts, you'll be putting out a lot of heat even under a small load.

One more thing, look at *THEIR* example circuits on the data sheet ("they" being the makers of the voltage regulator) and compare them with yours.

If all else fails and you're sure your circuit is correctly wired (or you've corrected any "mistakes") then it's possible that the regulator is broken (age, prolonged overheating, incorrectly wired on power-up, etc.)

Often when I'm shopping for electronic components, if they're cheap enough, I'll get one more than I need in case I break one.  smiley
10  Using Arduino / Motors, Mechanics, and Power / Resistor in series with MOSFET gate? on: August 19, 2012, 11:07:01 am
Hey, this is just a quick question.

On another post, I was having trouble with a mosfet and a motor and I mentioned the fact that I just had the output line hooked directly to the mosfet. Someone recommended having a 100-ohm resistor in series with the gate. What is the purpose of that? Is it just to protect the arduino in case you connect the wire into the wrong hole on the breadboard (e.g. the drain of the mosfet instead of the gate?) I had one of those "inductive spike suppressing" diodes. I thought that the fact that the gate is isolated and controlled by voltage instead of current was the advantage of a mosfet over a regular transistor.
11  General Category / General Discussion / UL listed appliance with no fuse? How can this be? on: July 04, 2012, 11:07:41 am
I recently took apart a fan for someone who wanted me to fix it. It was UL listed according to the label on the back. However, I took it apart and I discovered that the motor is NOT protected against over load in any way, shape or form. A motor that has gummed up lubrication or failing bearings can eventually seize and this causes the motor to be "stalled" i.e. attempting to run but not able to turn. A stalled motor usually draws excessive current (but not enough to blow a 15 amp fuse in the electrical panel!) and this can overheat the windings, which damages the motor, and at higher voltages (such as from the wall socket) this could cause a fire!

Now, I'm fairly certain that since a stalled motor draws more power than a normal one, a properly sized slow-blow fuse would blow before a catastrophic failure occurred, right? Sure, it could blow due to a temporary condition such as a kid sticking something in it, but I'd rather put in a new fuse (or even get a new fan) than have my house burn down because I failed to periodically lubricate a <$20 fan! A thermostat mounted to the (usually metal) case of the motor would also work, though that might be more expensive than a fuse.

The scary thing is that the fan claims to be UL listed! How is that even possible? I thought UL was a SAFETY certification! How can an appliance with an unfused, non-overheat-protected 110v motor possibly meet any kind of safety standard??? Seriously, I'd hate to see an appliance that ISN'T UL listed! Does UL no longer even so much as look inside the appliance before approving it? How bad would it have to be to NOT be listed?

Besides, what bean-counter decided that they would rather face a wrongful death lawsuit due to a fire than raise the cost of the product by a measly 25 cents???
12  Using Arduino / General Electronics / Low battery voltage detector? (9v total battery voltage, 5v regulator) on: June 11, 2012, 12:53:40 pm
I was going to try and make a low battery voltage indicator using an LM339, and after I figured out the circuit itself I would connect it to an Arduino input, and make my program to give a visible indication of a low battery. What I was going to attempt was to have a 5v voltage regulator connected to "input 1 minus", using a voltage divider circuit with a 10-ohm resistor and a 4.7 k, to make the voltage go down by a very small amount. (voltage drop of like 0.1v on the 10 ohm resistor). Then, the 9v is hooked to a 2.2K resistor, then to ground through a 4.7K resistor, with the "input 1 plus" pin connected in between them. I use a 5k potentiometer to simulate voltage changes. The output can only sink current, so I have an LED wired to 5V, through a 470-ohm resistor then to the output.

The circuit does not seem to work as I intended. I wanted to voltage-drop the 9v through resistors to be close to 5v, so that when the battery voltage started to drop, the voltage that the chip would see would be lower than the reference voltage, causing the output to change. My LED just stays on all the time until the voltage is too low to actually light it up. That's not exactly what I'm aiming for. Am I missing something here? This circuit is currently on a bread-board by itself, I just wanted to figure out if my idea worked. So far, it doesn't.

If you use a series resistor voltage divider circuit, could you bring the battery voltage within the range of the analog inputs on the Arduino, and then just use the analog read function to check the battery level?
13  Using Arduino / Motors, Mechanics, and Power / Re: 9v Motor + Mosfet + Arduino = timing errors/crashes? on: June 05, 2012, 05:32:50 pm
Thanks. In an electronics class that I took previously, we were told that putting capacitors in parralel will result in increased total capacitance. I have a number of different values and about 6 of each, so I will add a 470 uf cap between 9v and ground, in addition to changing the batteries. If that doesn't help, I'll hook a few more caps in parralel with the 470 to increase the total capacitance and thus the noise/sag supression capability.
14  Using Arduino / Motors, Mechanics, and Power / 9v Motor + Mosfet + Arduino = timing errors/crashes? on: June 05, 2012, 11:01:16 am
Hey everyone

I just recently got an arduino along with a bread-board and some additional control circuits (and of course a power supply, in my case it's just an AA battery pack, 6 AA's, which add up to 9 volts) and I made a circuit where there are 3 leds, controlled by the arduino. I hooked diodes on two of the outputs because I wanted to make the Mosfet, and thus, the motor, turn on when two of the lights were on, but not when the third light was on. I didn't have anything else hooked up because I just wanted to figure out how to control a motor with an Arduino, before I tried to combine motor control with more interaction. The LEDs change at a pre-determined interval, that doesn't use the delay() function, because I know delay() prevents the arduino from reading any other inputs (except interrupts).

It worked fine for a while, and I experimented with other ideas, then re-set up the same system again and re-loaded the program.
The problem I'm currently having is that occasionally, the starting and stopping of the motor causes strange things to happen. Sometimes, the LEDs appear to miss a step or change out-of-time, other times the arduino seems to crash and require a power cycle or a press of the reset button.

I have a diode to prevent a voltage spike from the motor from damaging the mosfet, and I had that last time as well. The mosfet's gate is connected directly to the two outputs (through diodes) without a resistor.

I have been using the same battery for a while and I'm wondering, could a low battery cause timing errors or system crashes when something like a motor turns on and off? Since I haven't had the arduino for that long, I don't know what the effects of a momentary voltage sag are. My other question is, if it's not likely to be a battery problem, would adding a cap between 9V and ground (on the breadboard) help? Or, should I use an external 5V voltage regulator with decoupling capacitors and attach that to the 5v input of the Arduino? (provided, of course, that I verify that the voltage is correct) because I thought the arduino had caps on the board already! Are those not big enough to smooth out the kind of noise that a motor might generate? The biggest caps I have are 470uf, 25v (my battery is only 9v)
Pages: [1]