SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By StaticDet5
#142017
OK. Another reality check, telling me I need to slow down.
When I went to try the resistor to the 5v rail, I stopped and checked my connections with a voltmeter. The voltage rails on the breadboard appear to be wonky, somewhere. The voltage rails appear to be disconnected somewhere... but not where I would expect. I bridged the "halfway" point on the rails, but I was not getting a reading with the voltmeter. It's bizarre, to say the least.

I checked everything again, made sure that I had access to the 5v and ground rail, and ran the tests with the resistor between the sensor pin and the ground pin.

69 hits with the pull-up disabled (no "digitalWrite HIGH" code). 1511 hits with the pull-up enabled (digitalWrite code enabled). I'm going to try wiring the signal pin to the 5v rail with the 1k resistor...
By StaticDet5
#142018
OK!
Here's the new data.
The change in the circuit:
A 1K ohm resistor is between the signal pin from the photo-interrupter (Arduino digital pin 2) and the 5v pin. I'm attaching the code here so that we have a "break-point" where we can see what is being done:
Code: Select all
/*
    BasicAmperageMonitorWithBarrelSensor
    3-28-2012

    The circuit:
    * LED on board at pin 13
    * Motor control on pin 3 (PWM pin)
    * pushbutton attached to pin 7 from +5V
    * 10K resistor attached to pin 7 from ground
    * ADC on analog pin 0
    * The photo-interrupter on pin 2

    Serial settings:
    Bits per second 115200

    */

    #include <TimerOne.h>

    const int buttonPin = 7; //Trigger switch attached to digital pin 7
    const int ledPin = 13; //onboard LED on pin 13
    const int MotorPin = 3; //Motor drive pin (on MOSFET) connected to PWM pin at pin 3
    const int CurrentSensor = 0; //Current flow sensor attached to Analog 0
    const int MotorSpeed = 255; //PWM value for motor, max 255
    volatile int BBdetect = 0; //BB seen or not

    int fireTime = 0;
    int buttonState = 0; // Trigger button state
    volatile int IMain = 0; // Direct ADC reading from current sensor
    long ReadAmpsInterval = 1000; // This will provide 10 readings per AEG cycle

    void setup() {
    Serial.begin(115200); // High output rate to accept about 25 samples per motor cycle
    pinMode(MotorPin, OUTPUT); //Set the MotorPin as an output
    analogWrite(MotorPin, 0); // make sure that the MotorPin is Off
    //digitalWrite(2, HIGH);  //  Turn on internal pull-up

    pinMode(ledPin, OUTPUT); // Set the LED Pin as an output
    pinMode(buttonPin, INPUT); // set the trigger pin as an input

    Timer1.initialize(ReadAmpsInterval); //set up the interrupt timer to read at the ReadAmpsInterval
    
    attachInterrupt(0, ReadBB, FALLING);  // The BB ISR
    }

    void loop() {

    /* A simple loop to drive the motor while the trigger is held down */

    buttonState = digitalRead(buttonPin);
    // Only set fireTime if the current timer is 0 and the button was pressed
    if(buttonState && !fireTime)
    {
      Timer1.attachInterrupt(ReadAmps); //The function to call every interval
      fireTime = 1500;
    }
    while(fireTime > 0) {
      analogWrite(MotorPin, MotorSpeed);
      digitalWrite(ledPin,HIGH);
      }

    analogWrite(MotorPin, 0);
    digitalWrite(ledPin, LOW);
    }


    void ReadAmps() //this is the interrupt function
    {

    if(fireTime > -10)
    {
      fireTime--;
    } else {
       Timer1.detachInterrupt(); //stop recording data 10msec after the last motor pulse
    }

    IMain = analogRead(CurrentSensor); //simply reads the CurrentSensor and stores the value in IMain

    /* Write out the sensor reading, MSB then LSB */
    //Serial.print(IMain,DEC);
    Serial.write(48 + IMain/100);
    Serial.write(48 + (IMain%100)/10);
    Serial.write(48 + IMain%10);

    /* Send a tab */
    Serial.write(0x09);

    // Write the state of the BB int
    Serial.write(48 + BBdetect%10);
    BBdetect = 0;  // reset BBdetect for this msec

    /* Write out the millisecond count (repeats after 50 days of run time) */
    // unsigned long currentTime = millis();
    //Serial.print(currentTime,DEC);

    /* Send a carriage return */
    Serial.write(0x0D);
    }

    void ReadBB() //this is the interrupt function for photo-interrupt
    {
    BBdetect = 1;
    }
There are some double hits in the log. I'm going to do a run with the internal pull-up enabled.

Finally, folks, if I'm using the wrong terminology, please tell me.
You do not have the required permissions to view the files attached to this post.
By StaticDet5
#142020
I think we're losing ground. I may sit down and just read about pull-up and pull-down resistors tonight.
This is the log data with the internal pull-up enabled. 32 hits, with a fair amount of erratic behavior.

I'm going to take a break for a little bit.
You do not have the required permissions to view the files attached to this post.
By Mee_n_Mac
#142032
Looking at the V2 Test3 data I see 3 false detections (see red spikes below), all were separated in time from true detections. The closest was 9 msec after the true detection @ time = 439 msec. So does that mean the pull-up to 5V helped ... or that you just got lucky this run ? I'll look at the other data. I am concerned about the "wonkiness" you mention. That could be a source of the random false detections. Can you describe your breadboard setup and wiring a bit more ? Or did you get everything all sorted out ?
M16V2Test3.jpg
You do not have the required permissions to view the files attached to this post.
By dkulinski
#142033
StaticDet5 wrote:Dan, awesome to hear that the lasertag project is moving forward. I'm going to beg, borrow and steal ideas from that.
At some point I'll be posting circuit diagrams, BOM lists and even the PCB schematic. If you haven't had a chance to check out where I am now, loot at my thread I started:

viewtopic.php?f=14&t=31938

I really don't enjoy breadboards, I have found that they can cause headaches just as much as they can ease development. Luckily working with through hole parts I can just solder onto a protoboard. Of course that can produces headaches too.

If you are ready to take the next step in prototyping I would suggest a move to protoboards over breadboards. A little more permanence and you can start to see your circuit take shape away from the rigid structure the breadboard creates.

I started to cobble together some PWM ramps for your trigger. I would like to throw it in for the tests. It isn't quite ready yet. Basically it will use the current msec timer and ramp from 80% to 100% in the space of 50msec, hopefully this will get rid of the huge inrush spike and allow for a less complex set of monitoring levels.

Dan

Dan
By Mee_n_Mac
#142034
StaticDet5 wrote:I think we're losing ground. I may sit down and just read about pull-up and pull-down resistors tonight.
This is the log data with the internal pull-up enabled. 32 hits, with a fair amount of erratic behavior.

I'm going to take a break for a little bit.
Looking at the Test5 data there are 8 falses, the closest to another true detection was some 6 msec away. I did see 2 false detections separated by only 2 msec ... not the same "extended" detections we've seen before. Seems a little higher amount of random false detections than normal but there's been 6 falses a few times in the past. So is motor noise causing these or ??? I'd like to see a couple of tests with the detector held off barrel but the wiring to the detector running the same way as before. If there's consistently no falses with these tests then I have to believe the detector is "seeing" something (since any motor noise/pickup on the wiring should be the same). What the something is I can only guess at ATM.
M16V2Test5.jpg
Again I'd point out from the above is that every cycle shot a BB, which was detected. All 8 falses were filtered out using a 45 msec "too soon" threshold.
You do not have the required permissions to view the files attached to this post.
By StaticDet5
#142036
Soldering is dicey for me. What I need to do is build another work table just for electronics. Even then, it's going to always be an uphill battle (you should see my handwriting).
When I get to the point where the basic functions are implemented, I want to build the backpack. Until then, I'm probably going to have to stick with the breadboarding. Right now, there are too many changes going on.

Here's the first batch of test data with the sensor off the barrel (4 hits). I'm going to do a second set in just a second. Any recommendations for driving the number of false hits down? I'll keep running tests until I get clean data, but I really don't have any idea where to go.

I'm going to work on documenting the circuit better tonight or tomorrow. I think I have the Fritzing software down to the point that I can document the whole circuit.
You do not have the required permissions to view the files attached to this post.
By StaticDet5
#142037
Six hits with this test data. I'm going to do two more quick tests, playing with the resistor value.
You do not have the required permissions to view the files attached to this post.
By StaticDet5
#142038
This one has 8 hits. I changed the resistor value to 500 ohms (2x 1k ohm resistors in parallel).
You do not have the required permissions to view the files attached to this post.
By StaticDet5
#142039
Eleven hits with this data. I changed the resistor value to 2000 ohms (2x 1k ohm resistors in series).
You do not have the required permissions to view the files attached to this post.
By StaticDet5
#142040
Three hits with a 100 ohm resistor in place. I think tomorrow I'm going to play in that realm. Also, I just figured out how to attach multiple files to one post (I think), so I won't have to spam the board with posts with to load multiple files.
You do not have the required permissions to view the files attached to this post.
By Mee_n_Mac
#142045
The pull-up resistor won't cure all the false detections, only those caused by line ringing due to improper line termination. These are the ones that look like the BB was detected twice, where one detection immediately followed another. What the above data tells me is that the random falses aren't due to the detector seeing something blocking the light, but rather because noise is creeping in on it's power supply or on the line taking the signal to the Arduino or some flaky ground connection. A good 1uF cap across the detector Vcc and ground terminals, at the detector, is the 1'st step to take. I think you've already done that. The next step might be to shield the signal line from the detector to the Arduino. Shielded twisted pair wiring is pretty common and easy to get ahold of (commonly called microphone wire). Use the twisted pair for the signal and the ground to the detector and tie the shield to the Arduino ground at the Arduino only.
By StaticDet5
#142067
I got the false hit count progressively lower. At 12ohms I got my first "zero count". I just took it down to 9.5ohms and I''ve gotten a couple of zeros.
However, mounting the sensor at 9.5 yielded only two hits... Whoops. Too far.

Way too far. A test at 30 ohms yields no hits (real or otherwise). A test at 100ohms yields 27 hits. A test at 50 ohms yields 26 hits. I'm attaching that data below (Everything else is saved as log files, and I'm keeping a daily Excel spreadsheet of tests as well).

I think this is as far as I can get with the resistor side of things. Next I'm going to clean up the cabling. I'm going to head to my local Home Depot. They've surprised me several times with their wiring selection. Failing that, I'll build a cable out of something on hand (USB?).

If you folks have any ideas, shoot them out. I'll be back on in a couple of hours.
You do not have the required permissions to view the files attached to this post.
  • 1
  • 21
  • 22
  • 23
  • 24
  • 25
  • 32