If you need assistance, please send an email to forum at 4hv dot org. To ensure your email is not marked as spam, please include the phrase "4hv help" in the subject line. You can also find assistance via IRC, at irc.shadowworld.net, room #hvcomm.
Support 4hv.org!
Donate:
4hv.org is hosted on a dedicated server. Unfortunately, this server costs and we rely on the help of site members to keep 4hv.org running. Please consider donating. We will place your name on the thanks list and you'll be helping to keep 4hv.org alive and free for everyone. Members whose names appear in red bold have donated recently. Green bold denotes those who have recently donated to keep the server carbon neutral.
Special Thanks To:
Aaron Holmes
Aaron Wheeler
Adam Horden
Alan Scrimgeour
Andre
Andrew Haynes
Anonymous000
asabase
Austin Weil
barney
Barry
Bert Hickman
Bill Kukowski
Blitzorn
Brandon Paradelas
Bruce Bowling
BubeeMike
Byong Park
Cesiumsponge
Chris F.
Chris Hooper
Corey Worthington
Derek Woodroffe
Dalus
Dan Strother
Daniel Davis
Daniel Uhrenholt
datasheetarchive
Dave Billington
Dave Marshall
David F.
Dennis Rogers
drelectrix
Dr. John Gudenas
Dr. Spark
E.TexasTesla
eastvoltresearch
Eirik Taylor
Erik Dyakov
Erlend^SE
Finn Hammer
Firebug24k
GalliumMan
Gary Peterson
George Slade
GhostNull
Gordon Mcknight
Graham Armitage
Grant
GreySoul
Henry H
IamSmooth
In memory of Leo Powning
Jacob Cash
James Howells
James Pawson
Jeff Greenfield
Jeff Thomas
Jesse Frost
Jim Mitchell
jlr134
Joe Mastroianni
John Forcina
John Oberg
John Willcutt
Jon Newcomb
klugesmith
Leslie Wright
Lutz Hoffman
Mads Barnkob
Martin King
Mats Karlsson
Matt Gibson
Matthew Guidry
mbd
Michael D'Angelo
Mikkel
mileswaldron
mister_rf
Neil Foster
Nick de Smith
Nick Soroka
nicklenorp
Nik
Norman Stanley
Patrick Coleman
Paul Brodie
Paul Jordan
Paul Montgomery
Ped
Peter Krogen
Peter Terren
PhilGood
Richard Feldman
Robert Bush
Royce Bailey
Scott Fusare
Scott Newman
smiffy
Stella
Steven Busic
Steve Conner
Steve Jones
Steve Ward
Sulaiman
Thomas Coyle
Thomas A. Wallace
Thomas W
Timo
Torch
Ulf Jonsson
vasil
Vaxian
vladi mazzilli
wastehl
Weston
William Kim
William N.
William Stehl
Wesley Venis
The aforementioned have contributed financially to the continuing triumph of 4hv.org. They are deserving of my most heartfelt thanks.
C'mon, Ben, that will not work. If you don't want to put protection code in software preferring the hardware way, then the only solution is to distance sensors away of coils by use of optocables (I believe we discussed that already). I would use both ways - hardware to remove false signals, software to control error conditions such as voltage downdrops, latch-up, triggering level adjustments (external light and IR sources like fire may interfere also), ensure consequence switching and so on. Later on you will find plenty of things to control and doing them all in hardware way may lead to a huge PC board.
Registered Member #8497
Joined: Tue Dec 04 2012, 06:24PM
Location:
Posts: 74
I've witnessed the sensitivity as well. I see two options - completely isolate the two circuits with optocouplers and digital signals.
Or
Use a bunch of digital de-bounce code. This will slightly slow down the arduino, but should work. If you ever get your hands on the new duo, it has a crazy fast clock on it - you could include high/low pass digital filters no problem.
I have 0 exp with microcontrollers, but common sense dictates that each optosensor should be actually listened in a specified timeframe. EMI from one stage may affect wires of ALL optosensors acting like an antennas. As I once checked everything with oscilloscope, even if optosensor lays 5cm away from coil, still it can receive few dozens uA of current when coil get switched on and off (mention no galvanic connection between coil board and a sensor board - pure EMI through air). So if any coil is to be switched on or off, first thing to do is to cut out all inputs for a dozen of us, then continue with coil switching, and after a pause resume checking inputs. I have no idea how could it be done, as I have 0 exp with MC...
Registered Member #3315
Joined: Thu Oct 14 2010, 04:23PM
Location:
Posts: 156
Max: if you get a chance take a look at my code. Only 1 stage is working. I probably messed up when adding the code for the extra stages.
/* Calibration
calibrates the optical sensor input. The sensor takes a reading during the first 2.5 seconds of startup to set the minimum and maximum of expected values of the sensor. */
// stage 1 const int sensorPin1 = A3; // pin that the sensor 1 is attached to const int ledPin1 = 10; // pin that the LED1 is attached to const int driverinput1 = 6; //injector driver 1 input
//stage 2 const int sensorPin2 = A5; // pin that the sensor 2 is attached to const int ledPin2 = 8; // pin that the LED1 is attached to const int driverinput2 = 4; //injector driver 2 input
//stage 3 const int sensorPin3 = A7; // pin that the sensor 3 is attached to const int ledPin3 = 12; // pin that the LED1 is attached to const int driverinput3 = 2; //injector driver 3 input
void setup() { // turn on LED to signal the start of the calibration period: pinMode(12, OUTPUT); digitalWrite(12, HIGH); // calibrate during the first five seconds while (millis() < 2500) { sensorValue1 = analogRead(sensorPin1); // record the maximum sensor value if (sensorValue1 > sensorMax1) { sensorMax1 = sensorValue1; } // record the minimum sensor value if (sensorValue1 < sensorMin1) { sensorMin1 = sensorValue1; } }
// signal the end of the calibration period digitalWrite(12, LOW); } void loop() { // read the sensor: sensorValue1 = analogRead(sensorPin1);
// apply the calibration to the sensor reading sensorValue1 = map(sensorValue1, sensorMin1, sensorMax1, 0, 255);
// in case the sensor value is outside the range seen during calibration sensorValue1 = constrain(sensorValue1, 0, 255);
// fade the LED using the calibrated value: analogWrite(ledPin1, sensorValue1); { pinMode(6, OUTPUT);
if (sensorValue1 < 250) // Change value to adjust sensitivity 1-255 increasing the value, increases the sensitivity
// turn on LED to signal the start of the calibration period: pinMode(10, OUTPUT); digitalWrite(10, HIGH); // calibrate during the first five seconds while (millis() < 2500) { sensorValue2 = analogRead(sensorPin2); // record the maximum sensor value if (sensorValue2 > sensorMax2) { sensorMax2 = sensorValue2; } // record the minimum sensor value if (sensorValue2 < sensorMin2) { sensorMin2 = sensorValue2; } }
// signal the end of the calibration period digitalWrite(10, LOW);
// read the sensor: sensorValue2 = analogRead(sensorPin2);
// apply the calibration to the sensor reading sensorValue2 = map(sensorValue2, sensorMin2, sensorMax2, 0, 255);
// in case the sensor value is outside the range seen during calibration sensorValue2 = constrain(sensorValue2, 0, 255);
// fade the LED using the calibrated value: analogWrite(ledPin2, sensorValue2); { pinMode(4, OUTPUT);
if (sensorValue2 < 250) // Change value to adjust sensitivity 1-255 increasing the value, increases the sensitivity
// turn on LED to signal the start of the calibration period: pinMode(8, OUTPUT); digitalWrite(8, HIGH); // calibrate during the first five seconds while (millis() < 2500) { sensorValue3 = analogRead(sensorPin3); // record the maximum sensor value if (sensorValue3 > sensorMax3) { sensorMax3 = sensorValue3; } // record the minimum sensor value if (sensorValue3 < sensorMin3) { sensorMin3 = sensorValue3; } }
// signal the end of the calibration period digitalWrite(8, LOW);
// read the sensor:
sensorValue3 = analogRead(sensorPin3);
// apply the calibration to the sensor reading sensorValue3 = map(sensorValue3, sensorMin3, sensorMax3, 0, 255);
// in case the sensor value is outside the range seen during calibration sensorValue3 = constrain(sensorValue3, 0, 255);
// fade the LED using the calibrated value: analogWrite(ledPin3, sensorValue3); { pinMode(2, OUTPUT);
if (sensorValue3 < 250) // Change value to adjust sensitivity 1-255 increasing the value, increases the sensitivity
Registered Member #8497
Joined: Tue Dec 04 2012, 06:24PM
Location:
Posts: 74
Hi Ben. I read through your code.
1. I think I may know why it's not working. 2. We're going to improve your calibration. 3. Very nice work writing that by yourself! Learning C code is fun and can be entertaining to debug sometimes.
First, we need to separate these actions into functions. Remember when I used a variable called 'engage' in my above code? I used this variable to tell functions when it's acceptable to run.
It appears you have included the calibration as part of your setup code. We should to write a function to run the calibration only once in the main code. This may be as simple as:
voild loop() { if engage==0{calibration();} engage=1; }
void calibration() { //calibration commands }
What kind of optical gate are you using? You may not need a calibration code at all. I'm using digital gates - output high or low. So I can use a digital pin. Per documentation, "It takes about 100 microseconds (0.0001 s) to read an analog input, so the maximum reading rate is about 10,000 times a second." At 10KHz, you shouldn't miss anything, but the mapping and calculations you run between analog reads slows down your code. If you can use a digital input, the likelihood of missing something drastically decreases. This maybe a voltage divider to the base of a transistor that triggers the arduino's digital pin.
If you're already using functions, chances are somethings running a lot which is causing you to miss gate signals.
Ben, I'll keep being a PItA, okay? So far, what will happen to your system if any dirt will cover the sensor or any external object, or bullet will jamm, or IR LED will get a pin accidentally detached due to vibrations or smg else? Will the coil stay happily energized forever or will melt and get switch burnt or will blow the battery, or will cause a critical voltage dropdown with unpredictable repercussions? Protection from latch-up is a must - if sensor is dim for longer than x ms, then coil must be switched off. So when reading the sensor input tells you that bullet is inside the gate, store the time value when switch-on happened, and if the same value keep being read even after the defined timeout, compulsory switch off all coils and exit with error. Otherwise clear the flag and switch to reading the next sensor gate.
P.S.: oh, I just mentioned the actual firing code from Maxwell few posts above. So there is 225ms timeout limit here already, is it right?
I have a lot of exp with C++ though, I would write a firing somehow like that:
//Declare and define all variables int Stage = 0; //ID of a currently monitored stage int StageMax = 2; //Max value of stage ID number (IDmax=2 for 3 stage system) int TimeStart = 0; //Time point when coil was switched on int TimeMax = 12345; //Max time coil is allowed to stay energized int TimeMin = 123; //Min time coil should be kept energized (for noise suppression) bool Engage = false; //Start the loop do{ if(ReadPin(Stage)) //If bullet is detected by a currently monitored sensor... { if(!Engage){ SetPin(Stage,HIGH); TimeStart=TimeNow(); Engage=true; } else { if(TimeNow()-TimeStart > TimeMax){ /*Switch off all coils and exit with error*/ } } } else//If sensors sees nothing... { if(Engage)if(TimeNow()-TimeStart > TimeMin){ SetPin(Stage,LOW); Engage=false; Stage++; if(Stage>StageMax)Stage=0; } } } }while(true); //This is an infinite loop
This code includes a latch-up protection, oscillation-supression, ensures consequtive coil switching and as I think as a pure programmer, should run fast?..
Registered Member #3315
Joined: Thu Oct 14 2010, 04:23PM
Location:
Posts: 156
Max: I am having a little trouble incorporating your suggested changes into my program. Can you be a little more specific about where to insert the code, and more importantly why. I feel like i need to read up on the basic layout and setup of code.
Yan: Bring it on. It will only make the final product that much better. I have a separate fuse for each stage. So no burned batteries or IGBT, Just a pile of blown fuses. I agree about adding the timeout code, And something similar will 100% be in the final code. but first I need to learn to program and get the simplified firing code done, as I have 0 experience aside from the handful of hours messing around with the arduino.
This site is powered by e107, which is released under the GNU GPL License. All work on this site, except where otherwise noted, is licensed under a Creative Commons Attribution-ShareAlike 2.5 License. By submitting any information to this site, you agree that anything submitted will be so licensed. Please read our Disclaimer and Policies page for information on your rights and responsibilities regarding this site.