Welcome
Username or Email:

Password:


Missing Code




[ ]
[ ]
Online
  • Guests: 59
  • Members: 0
  • Newest Member: omjtest
  • Most ever online: 396
    Guests: 396, Members: 0 on 12 Jan : 12:51
Members Birthdays:
One birthday today, congrats!
Th3_uN1Qu3 (33)


Next birthdays
06/17 Th3_uN1Qu3 (33)
06/19 sio2 (50)
06/20 Sparrow338 (35)
Contact
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.
Forums
4hv.org :: Forums :: Electromagnetic Projectile Accelerators
« Previous topic | Next topic »   

V3 Coil Carbine

Move Thread LAN_403
Yandersen
Wed Mar 20 2013, 07:20PM
Yandersen Registered Member #6944 Joined: Fri Sept 28 2012, 04:54PM
Location: Canada
Posts: 340
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.
Back to top
Maxwell
Thu Mar 21 2013, 12:06PM
Maxwell 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.
Back to top
Yandersen
Thu Mar 21 2013, 10:18PM
Yandersen Registered Member #6944 Joined: Fri Sept 28 2012, 04:54PM
Location: Canada
Posts: 340
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...
Back to top
ben5017
Fri Mar 22 2013, 01:50AM
ben5017 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.
*/

///////////////////////////////////////////////// //////constants/////////////////////////////////// //////////////

// optical sensor constants:

// 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




//////////////////////////////////////// //////////////variables/////////////////////////// /////////////////////////////////////////////////

// optical sensor variables:

// stage 1
int sensorValue1 = 0; // the sensor value
int sensorMin1 = 500; // minimum sensor value
int sensorMax1 = 1; // maximum sensor value

// stage 2
int sensorValue2 = 0; // the sensor value
int sensorMin2 = 500; // minimum sensor value
int sensorMax2 = 1; // maximum sensor value

// stage 3
int sensorValue3 = 0; // the sensor value
int sensorMin3 = 500; // minimum sensor value
int sensorMax3 = 1; // maximum sensor value


////////////////////////////////////////// /////////optical sensor code stage 1///////////////////////////////////////////////// ////////////////////

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

digitalWrite(6, HIGH);
else
digitalWrite(6, LOW);

///////////////////////////////////////////////// //optical sensor code stage 2///////////////////////////////////////////////// ////////////////////


// 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

digitalWrite(4, HIGH);
else
digitalWrite(4, LOW);

////////////////////////////////////////////////// /optical sensor code stage 3///////////////////////////////////////////////// //////////////////////////


// 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

digitalWrite(2, HIGH);
else
digitalWrite(2, LOW);
}
}
}
}

///////////////////////////////////////////////// /////////start of injector code////////////////////////////////////////////// //////////////////////
Back to top
Maxwell
Fri Mar 22 2013, 12:06PM
Maxwell 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.
Back to top
ben5017
Fri Mar 22 2013, 01:24PM
ben5017 Registered Member #3315 Joined: Thu Oct 14 2010, 04:23PM
Location:
Posts: 156
Max:

I am using a IR transistor and IR emiter

The code seemed to work well befor I added the other 2 stages.

Little more info on how my setup is misbehaving

-const int ledPin1: Dim, fades wit increase blocking (used to be bright, and faded before other 2 stages added)

-const int ledPin2: dim, does not fade

-const int ledPin3: bright, does not fade

The only pin outputting correctly is
const int driverinput1 = 6
Back to top
Yandersen
Sat Mar 23 2013, 05:40AM
Yandersen Registered Member #6944 Joined: Fri Sept 28 2012, 04:54PM
Location: Canada
Posts: 340
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?..
Back to top
ben5017
Sat Mar 23 2013, 08:37PM
ben5017 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.
Back to top
ben5017
Mon Apr 08 2013, 04:46PM
ben5017 Registered Member #3315 Joined: Thu Oct 14 2010, 04:23PM
Location:
Posts: 156
Chirp Chirp Chirp (crickets)
Back to top
Maxwell
Mon Apr 22 2013, 11:41PM
Maxwell Registered Member #8497 Joined: Tue Dec 04 2012, 06:24PM
Location:
Posts: 74
@Ben5017,

My sincerest apologies - work has been very very exhausting lately. I've only been able to reconsider this thread now.

Can you, again for memory, describe what you would like to happen so I can start from fresh?


Max.
Back to top

Moderator(s): Chris Russell, Noelle, Alex, Tesladownunder, Dave Marshall, Dave Billington, Bjørn, Steve Conner, Wolfram, Kizmo, Mads Barnkob

Go to:

Powered by e107 Forum System
 
Legal Information
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.