Welcome
Username:

Password:


Remember me

[ ]
[ ]
Online
Guests: 83, Members: 0 ...

most ever online: 333
(Members: 3, Guests: 330) on 06 Jun : 15:15

Members: 3396
Newest member: ghilinta.daniel
Members Birthdays:
All today's birthdays', congrats!
Reaching (32)
ryanshow (30)


Next birthdays
07/23 Will (30)
07/23 Arlecchino (33)
07/24 Jim_VE7UV (57)
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 thread | Next thread >>   

V3 Coil Carbine

Go to page  1 2 [3] 4 5 6
Author Post
ben5017
Thu Mar 07 2013, 02:57PM
Registered Member #3315
Joined: Thu Oct 14 2010, 04:23PM
Location:
Posts: 154
Yan:

About my firing topology. I actually have the sensor triggering a 555 which in turn, puts the output low then to the inverting igbt gate driver.

As for my bug. Turned out I had a bad 555 timer, (a good portion of the 555's I just got of mouser were defective so I kept replacing a bad one with a bad one.... as well as a shaky at best breadboard).

That being said could the sensor still cause the same issues on the 555 as on the igbt driver?

What is a good way to protect the sensors?
-Would making the sensor housing out of powdered ferrite help isolate the phototransistor from the emi?

MAXWELL:
I just bought a few microprocessors (mega 8 I think couple others) to mess around with, but I have never used one and don’t know where to start... Maybe taking the time to learn and replacing all my firing circuits with a microchip might be the way to go, I am a bit intimidated to try as I have no idea where to begin.

NEW ISSUES:
1) Injector sometimes (maybe 1 out of 10) fires when I release the trigger? ( Topology, adjustable pulse length 555 edge trigger mono stable, connected to 422 driver)
Any thoughts?

2) I hooked up my injector and fired a few shots, ever since then the Resistance on my igbts when open is 14K ohms, (same on all igbts (3 stages +injector))?? As you can imagine this drastically reduced velocity. I have tried everything to figure out what’s going on (changed 555, drivers, IGBT's) I still cannot figure it out.
Back to top
Maxwell
Thu Mar 07 2013, 06:26PM
Registered Member #8497
Joined: Tue Dec 04 2012, 06:24PM
Location:
Posts: 74
ben5017 wrote ...


MAXWELL:
I just bought a few microprocessors (mega 8 I think couple others) to mess around with, but I have never used one and don’t know where to start... Maybe taking the time to learn and replacing all my firing circuits with a microchip might be the way to go, I am a bit intimidated to try as I have no idea where to begin.





If you have $25 and a USB cable laying around, buy any arduino you can easily get your hands on. I'll write the timing code for you. Real simple coding. FYI - the DUO utilizes the microUSB connector - which breaks easily.

Atmega8's will require an external programmer - something I don't venture off into.
Back to top
ben5017
Thu Mar 07 2013, 06:35PM
Registered Member #3315
Joined: Thu Oct 14 2010, 04:23PM
Location:
Posts: 154
That would be awesome Maxwell. I will buy one today after I get out of work. Will any arduno work? Which one would you recommend? It’s long over due for me to start playing with the microchips. You think I could "reverse engineer" the code to learn how to program them?

Do you think changing to digital would have any significant effect on performance?
Back to top
ben5017
Thu Mar 07 2013, 08:18PM
Registered Member #3315
Joined: Thu Oct 14 2010, 04:23PM
Location:
Posts: 154
just picked up an arduino mega 2560, now just waiting for that code maxwell haha
Back to top
Yandersen
Thu Mar 07 2013, 09:25PM
Registered Member #6944
Joined: Fri Sep 28 2012, 04:54PM
Location: Canada
Posts: 340
I gave up with optical sensing already as even full metal shielding doesn't solve the problem completely. So the sensor must be as far from coil as possible. Either use laser diodes to stretch the beam, or optical cable to drive it away from coil to somewhere where EMI is low enough to not interfere with sensor. I would recommend optical cables as you can stretch all optowires in one place where all sensors and microcontroller are located - no low-current electronics works near the high pulsed magnetic fields.

Issue 1 is not surprising - common problem caused by mechanical switch. Hardly solvable - switch always glitches a little when contacts are connected or disconnected giving some false signals due to microvibrations. You can involve microcontroller to filter those false pulses: after triggering occurs make it insensitive for any other state changes for some period of time. For example...
My solution is two push buttons and a 555 timer - one button switches power supply on, another - switches it off and initiates firing sequence.
If you think smg may be wrong with yours IGBT, measure it outside the circuit, having gate and emitter connected. 14K may be given by other elements or some small floating positive voltage on gate.
Back to top
Maxwell
Fri Mar 08 2013, 02:40AM
Registered Member #8497
Joined: Tue Dec 04 2012, 06:24PM
Location:
Posts: 74
Quick Reply: Modifying my code for you to be able to understand. I'll have it posted (edited here) before midnight.

Code is posted below.
I haven't used the Mega in a year or two - but it should like this code.

Serial communications are established thru USB (make sure the baud rate on the arduino side is 9600)

variable delta x is the distance between photogates in mm.

Digital pin 3 is declared as an input. It will accept 0-5v (use a high impedance voltage divider just for safety for your trigger). When a HIGH signal is read, a de-bounce code pauses for 225ms (what I found to be fool-proof for my simple mechanical switches. IF you are doing a direct contact you may drop this down to 1 or 2ms).

Digital pins 10,11 are the photogate pins. They have a timeout in the speed_trap function that will declare an error if nothing passes between within 500ms. When the signal goes high to a pin from the photogate, the timers are triggered.



Variable 'engage' is the modular part - you can set the Arduino to jump to different functions by the number assigned to engage. I assumed engage 0 to mean waiting for trigger, engage 1 is trigger actuated.
Back to top
ben5017
Fri Mar 08 2013, 03:14AM
Registered Member #3315
Joined: Thu Oct 14 2010, 04:23PM
Location:
Posts: 154
You are the man. I love this place...
Back to top
Maxwell
Fri Mar 08 2013, 03:58AM
Registered Member #8497
Joined: Tue Dec 04 2012, 06:24PM
Location:
Posts: 74
//Okay, so I down-compiled my code into this small format.
//Ask if you have any questions.
//It's not running 100% efficient but it is modular.

volatile byte engage; //Declare 'interrupts' as volatile
byte tabA;
byte darkA;
byte darkB;
unsigned int deltax; //Timer spacing in mm
unsigned int thrutime;
unsigned long dlaytimeA;
unsigned long dlaytimeB;

void setup()
{
Serial.begin(9600); //Reserve Digital Pins 0 and 1 for Serial
//on Duemillanove but not on Leonardo.

darkA=0; //Set initial Speedtrap ADC values
darkB=0;
engage=0; //Trigger status flag

pinMode(3,INPUT); //Pseudo-Interrupt pin (trigger)
pinMode(10,INPUT); //PhotoGate Entry
pinMode(11,INPUT); //PhotoGate Exit

deltax = 80; //Speedtrap light spacing in mm

}


void loop()
{


if(digitalRead(3)==HIGH && tabA==0)
{dlaytimeB=millis()+225; tabA=1;} //digital de-bounce script (225ms)
if(millis()>(dlaytimeB))
{tabA=0;}
if(tabA==1 && millis()>dlaytimeB && digitalRead(3)==HIGH)
{Serial.println("Trigger Action Detected."); engage=1; tabA=0;}



if(engage==1)
{
speed_trap(10,11); //digitalPin# entry, digitalPin# exit
}

if(engage==2)
{ if(thrutime==0)
{ Serial.println("Timing error. No timer activity detected."); }
else
{ calculations(); }
engage=0; //reset fire sequence
}

}




void speed_trap(int vinpinA, int vinpinB)
{ unsigned long enter; unsigned long exit;
unsigned long error; int errorcount = 0;
unsigned long errortime;

errortime=millis()+500; //500ms timeout for non-speedtrap triggering.

while(darkA==0 && errorcount!=1)
{ darkA=digitalRead(vinpinA); error=millis();
if(error>errortime){errorcount=1;}
}
enter=micros();


while(darkB==0 && errorcount!=1)
{ darkB=digitalRead(vinpinB); error=millis();
if(error>errortime){errorcount=1;}
}
exit=micros();


if(errorcount==0)
{ thrutime=(exit-enter); } //time in microseconds (1000us in 1ms)
else
{ thrutime=0; }

engage=2;
}


void calculations()
{
float velocity;
velocity = (deltax/1000.0) / (thrutime/1000000.0);
Serial.print("Thrutime (us): "); Serial.println(thrutime);
Serial.print("Velocity (m/s): ");Serial.println(velocity);
Serial.println("calculations function completed.");
}
Back to top
ben5017
Fri Mar 08 2013, 02:56PM
Registered Member #3315
Joined: Thu Oct 14 2010, 04:23PM
Location:
Posts: 154
Thanks alot. What do you think about me changing all my firing circuit into arduino? worth it?
Back to top
Maxwell
Fri Mar 08 2013, 04:29PM
Registered Member #8497
Joined: Tue Dec 04 2012, 06:24PM
Location:
Posts: 74
My full code controls the charging, triggering, speedgates and efficiency calculations.

I have a high-impedance voltage divider measuring charge voltage.

I use the Atmega's interal SRAM to take ~100 instantaneous voltage measurements during the discharge (make-shift oscilloscope) before my code jumps to measure velocity.

False triggering and spontaneous charging is somewhat an issue. In my next build, I will implement optocouplers to the HV and charging circuits. For now, i have some transistors that ground out all critical gates after the firing process completes.

The mega is very very capable. Lots of I/O and a large amount of memory.

Try not to fry pins - it makes programming a little more complicated. ;) I found out that they don't like direct exposure to 400v.

Back to top
ben5017
Fri Mar 08 2013, 05:32PM
Registered Member #3315
Joined: Thu Oct 14 2010, 04:23PM
Location:
Posts: 154
can you send me triggerin code pretty please
Back to top
Maxwell
Fri Mar 08 2013, 06:42PM
Registered Member #8497
Joined: Tue Dec 04 2012, 06:24PM
Location:
Posts: 74
Just the part to trigger an SCR?

Thats only like 3 new lines of code:

pinMode(4,OUTPUT); //SCR Gate Output (through TIP-120 transistor)


if(engage==1)
{
digitalWrite(4,HIGH); //pin 4 goes high to transistor
delay(1); //delay 1ms
digitalWrite(4,LOW);
speed_trap(10,11); //digitalPin# entry, digitalPin# exit
}
Back to top
ben5017
Fri Mar 08 2013, 07:57PM
Registered Member #3315
Joined: Thu Oct 14 2010, 04:23PM
Location:
Posts: 154
need to link up my optical sensors to the arduino then output to igbt
Back to top
ben5017
Fri Mar 15 2013, 01:07AM
Registered Member #3315
Joined: Thu Oct 14 2010, 04:23PM
Location:
Posts: 154
max, how about an adjustable one shot timer?
Back to top
Maxwell
Fri Mar 15 2013, 01:19PM
Registered Member #8497
Joined: Tue Dec 04 2012, 06:24PM
Location:
Posts: 74
@ben5017 - I just saw your post.
Explain specifically the order in which you would like things to happen and I can code it up for you no problem
Back to top
ben5017
Sun Mar 17 2013, 06:55AM
Registered Member #3315
Joined: Thu Oct 14 2010, 04:23PM
Location:
Posts: 154
Max this is what I need

Phase 1:
1: pulling the trigger activates a 1shot trigger output with an adjustable pulse length.
2:when a switch is flipped, pulling and holding the trigger no longer oneshots but puts it into astable output with adjustable on/off times.
3:(x5) sensor setups that will be connected to the output of my optical gates (IR diode + opamp) which when a slug blocks the beam the arduino will send a signal to my igbt gate drivers.

the above is the minimum things I need right now to fire the x3cc.

Phase 2:
After that I will be working on the drum magazine which will hold 30+ slugs. I plan on connecting it to a continuous rotation servo or a dc/gear reducer motor, or maby a stepper, haven't decided yet. these will be controlled by the arduino which will read a signal from a hall effect sensor that will detect the presence of a slug. The arduino will rotate the motors as soon as it doesn't detect anything, until it does. the sensitivity will need to be adjustable as well to dial the feeding system in.

phase 3:
The frame will be the final step after it is firing/feeding acceptable and i get my cnc router fully operational.

Hope this helps.

Back to top
ben5017
Tue Mar 19 2013, 03:16AM
Registered Member #3315
Joined: Thu Oct 14 2010, 04:23PM
Location:
Posts: 154
update:

phase 1: #3 Done

got the firing code for one of my optical sensors working, along with an auto calibration of the sensor upon program start up to set expected max min values, along with a manual sensitivity adjustment 0-255. still have to add the rest of the stages. The sensor is super sensitive. cant wait to see If it makes it shoot any faster. (Would the arduino digital output be that much quicker than a 555?)

next up is the triggering code. I messed around with modifying a De-bouncing trigger code for a bit today. trying to act as a adjustable pulse "one shot", with out much luck. Haven't given much thought to the select fire yet either.(max where you at bro??)

Back to top
Maxwell
Wed Mar 20 2013, 02:02AM
Registered Member #8497
Joined: Tue Dec 04 2012, 06:24PM
Location:
Posts: 74
Hi ben5017,

Been quite busy with other things at the moment - apologies on the delayed code.

The arduino can output hellafast for what it is - roughly 1059times/millisecond without overhead.

You can use the delaymicroseconds command to turn on/off very quickly:
"
digitalWrite(outPin, HIGH); // sets the pin on
delayMicroseconds(50); // pauses for 50 microseconds
digitalWrite(outPin, LOW); // sets the pin off
"
Back to top
Yandersen
Wed Mar 20 2013, 10:27AM
Registered Member #6944
Joined: Fri Sep 28 2012, 04:54PM
Location: Canada
Posts: 340
How about some noise-supression to prevent possible false-triggering? ALL inputs must become insensitive to ANY signals for a dozen microseconds every time after ANY of the coils got energized or switched off, as this process emits high level EMI.
Back to top
ben5017
Wed Mar 20 2013, 05:12PM
Registered Member #3315
Joined: Thu Oct 14 2010, 04:23PM
Location:
Posts: 154
yan:

1 step ahead of you. Have a few picked out. I dunno how to size them though. Take a look if you get a chance http ://www.mcmaster.com/#emi-rfi-shielding-cable-clamps/=lynjj6

Max: gonna mess around with the injector driver code tonight. Ill keep you posted. Thanks for the tips. Any more commands you think might be usefull? links to a good refrence?
Back to top
Yandersen
Wed Mar 20 2013, 07:20PM
Registered Member #6944
Joined: Fri Sep 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
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
Registered Member #6944
Joined: Fri Sep 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
Registered Member #3315
Joined: Thu Oct 14 2010, 04:23PM
Location:
Posts: 154
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
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
Registered Member #3315
Joined: Thu Oct 14 2010, 04:23PM
Location:
Posts: 154
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
Registered Member #6944
Joined: Fri Sep 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
Registered Member #3315
Joined: Thu Oct 14 2010, 04:23PM
Location:
Posts: 154
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
Registered Member #3315
Joined: Thu Oct 14 2010, 04:23PM
Location:
Posts: 154
Chirp Chirp Chirp (crickets)
Back to top
Maxwell
Mon Apr 22 2013, 11:41PM
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
Go to page  1 2 [3] 4 5 6

Moderators: Chris Russell, Noelle, Alex, Tesladownunder, Dave Marshall, Bjørn, Dave Billington, Steve Conner, Wolfram, Kizmo, Mads Barnkob

Jump:     Back to top

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.