* THE FORUM FOR ALL THOSE INTERESTED IN BUILDING AND OPERATING MODEL SUBMARINES *



Join the AMS - Registered Forum users can become members of the AMS and it's free ...... To join register on the forum first then follow the forum link to our membership form which is on our website


For further details of any events shown here also see the "Shows and Events" section on the forum

Let us know of your plans for 2019 and we will promote them on this Forum

.

,
.
.

. ,

,

.
.
.

.

.

,,,,

.That's it for this year, folks! See you all in 2019.

Who is online?

In total there are 3 users online :: 0 Registered, 0 Hidden and 3 Guests :: 1 Bot

None


Most users ever online was 37 on Sun Mar 13, 2011 11:27 am

Latest topics

»  Alexander Engel Russian typhoon Submarine
Yesterday at 10:33 pm by deepseadiver

» 915mhz / 868mhz as a viable frequency for submarines.
Sun Dec 09, 2018 3:48 am by tsenecal

» Resurgam, Nordenfelts II & IV - George Garrett's works.
Tue Nov 27, 2018 6:20 pm by david f

» Newcomer to the forum?
Tue Nov 27, 2018 5:42 pm by david f

» 40Mhz Activity - waterfall display
Sun Nov 25, 2018 3:22 pm by timgarrod

» Tadcaster Pool Dive In, November 2018
Sun Nov 25, 2018 3:21 pm by timgarrod

» PIC and Arduino microprocessors
Fri Oct 26, 2018 10:49 am by david f

» Control yoke
Tue Oct 23, 2018 11:38 pm by merriman

» brushed motors
Mon Oct 22, 2018 11:47 am by merriman

Statistics

Our users have posted a total of 10694 messages in 1756 subjects

We have 793 registered users

The newest registered user is Gazztank

    Arduino proportional control of a piston tank

    Share
    avatar
    david f
    AMS Treasurer

    Posts : 1996
    Join date : 2010-11-10
    Age : 68
    Location : Cumbria

    Arduino proportional control of a piston tank

    Post  david f on Thu Dec 07, 2017 10:02 am



    Just done a bit more work on this inspired by Eric Weber's work on the SubCommittee Forum.

    Eric's hardware choice works nicely and it is ready built from an eBay supplier, so no need for a soldering iron!

    The software, as shown, works with a Hall Switch to count revs and has a failsafe. The piston tank is protected by limit switches - I prefer the separate circuit for this with diodes across the switches, as shown in Norbert Bruggen's book.

    I am quite a convert to the Arduino, by the way. My original routine using PICs took about a year to get going. This version on the Arduino - not much time spent over 2 months. It uses an Arduino Nano - my favourite.

    Some health warnings this version has only worked on the bench, so far, not yet in a model submarine. Use it at your own risk.

    A short video showing the controller working with a home made piston tank built for my Nordenfelt subs.

    https://www.youtube.com/watch?v=fFd_BKnzCe4&t=102s

    The software is best downloaded from my site on Github (my first attempts at this!):

    https://github.com/rdforrest/submarine-proportional-pistontank/blob/piston-tank/New_Piston4e.ino

    The sketch follows but you are best going to the Github:

    /*
    Proportional Piston Tank Controller by David Forrest based on work by Eric Weber and Gabriel Staples. 24/10/2017
     My code changes are labelled RDF. This version New_Piston4e (5/12/2017)
     Hall switch (A1104 from Allegro) used to count revolutions and give proportional control.
     An error signal is generated from the Hall switch count and the r/c input pulse.
     This is fed to the H bridge and motor (It is a servo really)
     When the unit is switched on it has 35 seconds to empty the piston tank and set the switch counter to zero.
     Loss of r/c signal (Failsafe) empties the piston tank and resets the switch counter.
     The Hall effect sensor is switched on when the south pole of a magnet comes close to the front tapering face of the sensor.
     Hall switch needs +5v supply.
     Nov 2017 Put pullup in software this seems to eliminate the need for a pullup resistor.
     Nov 2017 Built In LED now shows forward & reverse
     AnalogSmooth routine not actually used.

     Notes by Gabriel Staples
     Pulse_reader_w_pin_change_interrupt_singleCh.ino
     -read in any pulsing signal on Arduino pin INPUT_PIN (defined below), to get its period (us) & freq (Hz), with a time resolution of 0.5us
     --you can read in any pulse, including standard PWM signals, Radio Control (RC) PWM signals, etc.
     -I am using some low-level AVR code, which requires using some built-in Arduino macros to do pin-mapping.
     -this code only reads in a single channel at a time, though it could be expanded to read in signals on every Arduino pin, digital and analog, simultaneously.
     --this would be lots of work, so for now I'll leave that up to you.
     -this code should be able to read in any pulse between approximately 10~20us and 35.79 minutes; I'll let you experiment
     to find the actual shortest pulse you can measure with it

     By Gabriel Staples
     http://www.ElectricRCAircraftGuy.com/
     -My contact info is available by clicking the "Contact Me" tab at the top of my website.
     Written: 28 Nov. 2013
     Updated: 21 March 2015

     Some References:
     -to learn how to manipulate some of the low-level AVR code, pin change interrupts, etc, these links will help
     --http://www.gammon.com.au/interrupts
     --ATmega328 datasheet: http://www.atmel.com/Images/Atmel-8271-8-bit-AVR-Microcontroller-ATmega48A-48PA-88A-88PA-168A-168PA-328-328P_datasheet.pdf
     --http://playground.arduino.cc/Main/TimerPWMCheatsheet
     --See the *many* very helpful links at bottom of this article: http://www.electricrcaircraftguy.com/2014/01/the-power-of-arduino.html
     --reference the Arduino source code, ex:
     ---C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino\Arduino.h
     ---C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino\wiring_digital.c
     ---C:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard\pins_arduino.h
    */

    /*
     Circuits:

     Option 1) To measure the pulses from an Arduino PWM pin, ex: pin 5 or 9, connect Pin 5 or 9 (a PWM output) to INPUT_PIN (the pulse reader input)
             -see the setup() function for commanding the PWM output to begin, so you can have something to read in

     Option 2) To measure an RC PWM servo-type signal coming from an RC Rx:
     -Power the Rx by connecting 5V to + on the Rx, and GND to - on the Rx
     -Connect the channel signal you want to measure on the Rx to the INPUT_PIN on the Arduino
    */

    #include <AnalogSmooth.h>

    /*
     Smooths signal jitter on analog inputs by averaging
     concurrent readings. The number of readings averaged can
     range from 1 (no smooting) to 100.

     The more readings you average the more consistent the signal
     becomes. At the same time it takes longer to detect actual
     changes in the signal.
    */

    #include <eRCaGuy_Timer2_Counter.h>

    //#include <avr/wdt.h>    // Include watch dog timer

    //macros
    #define fastDigitalRead(p_inputRegister, bitMask) ((*p_inputRegister & bitMask) ? HIGH : LOW)

    //Global Variables & defines
    const byte INPUT_PIN = A5; //RDF changed to A5 .you can change this to ANY digital or analog pin, ex: 10, 8, A0, A5, etc,
    //EXCEPT A6 and A7 (which exists on the Nano and Pro Mini, for example, and are NOT capable of digital operations)
    byte input_pin_bitMask;
    volatile byte* p_input_pin_register;

    //volatile variables for use in the ISR (Interrupt Service Routine)
    volatile boolean output_data = false; //the main loop will try to output data each time a new pulse comes in, which is when this gets set true
    volatile unsigned long pulseCounts = 0; //units of 0.5us; the input signal high pulse time
    volatile unsigned int pd = 0; //units of 0.5us; the pulse period (ie: time from start of high pulse to start of next high pulse)

    // Simple counter from below (RDF)

    int ip_pulse = 0;  // Variable from TX pulse by RDF

    int errsig = 0; // Error signal for servo action (Hall count minus PWM input)

    //https://quarkstream.wordpress.com/2009/12/11/arduino-4-counting-events/

    int state = LOW;

    int lastState = LOW;

    int count = 0;

    int reverse = 15;

    int failsafe_count = 1;

    //Digital input pin 8 for Hall switch input.

    unsigned long duration;

    int analog = errsig ;

    float analogSmooth;

    // Defaults to window size 10
    AnalogSmooth as = AnalogSmooth();

    // Window size can range from 1 - 100
    AnalogSmooth as100 = AnalogSmooth(100);


    void setup() {
     // put your setup code here, to run once:

     pinMode(8, INPUT_PULLUP);// Put Pullup on Hall switch input

     state = digitalRead(8);

     pinMode(INPUT_PIN, INPUT_PULLUP); //use INPUT_PULLUP to keep the pin from floating and jumping around when nothing is connected

     //configure timer2
     timer2.setup();

     //prepare for FAST digital reads on INPUT_PIN, by mapping to the input register (ex: PINB, PINC, or PIND), and creating a bitMask
     //using this method, I can do digital reads in approx. 0.148us/reading, rather than using digitalRead, which takes 4.623us/reading (31x speed increase)
     input_pin_bitMask = digitalPinToBitMask(INPUT_PIN);
     p_input_pin_register = portInputRegister(digitalPinToPort(INPUT_PIN));

     configurePinChangeInterrupts();

     //start PWM output (to read in its pulses, for use in Circuit 1 as described above)
     pinMode(5, OUTPUT);
     pinMode(9, OUTPUT);
     analogWrite(5, 10); http://976.5625Hz, with high pulses of ~1/976.5625 x 10/256 = 40us; Connect pin 5 to INPUT_PIN and open serial monitor & you will see approximately this
     analogWrite(9, 128); http://490.20Hz, with high pulses of ~1/490.2 x 128/256 = ~1020us; Connect pin 9 to INPUT_PIN and open serial monitor & you will see approximately this
     /*
       PWM Notes:
       -PWM on pins 5 & 6 occurs at 976.5625Hz; see here: http://playground.arduino.cc/Main/TimerPWMCheatsheet
       -PWM on pins 9 & 10 occurs at 490.20Hz
     */


     Serial.begin(9600);   //RDF changed from 115200
     Serial.print(F("Begin waiting for pulses on pin ")); Serial.print(INPUT_PIN);
     Serial.println(F(".\nData will be printed after each pulse is received."));

     // Test.connect motor controller pins to Arduino digital pins
     // motor one
     // https://tronixlabs.com.au/news/tutorial-l298n-dual-motor-controller-module-2a-and-arduino

     int enA = 3;
     int in1 = 2;
     int in2 = 4;

     // set all the motor control pins to outputs
     pinMode(enA, OUTPUT);
     pinMode(in1, OUTPUT);
     pinMode(in2, OUTPUT);

     //Test. This will be used for piston tank initial setup

     digitalWrite(in1, HIGH); //Swap in1 & in2 to reverse motor
     digitalWrite(in2, LOW);
     digitalWrite(enA, HIGH); //High runs motor

     delay(35000); //35 second delay to get piston tank empty from the start.

     //set rev counter to zero

     count = 0;

     // initialize digital pin LED_BUILTIN as an output.
     pinMode(LED_BUILTIN, OUTPUT);

     // Setup code finishes here
    }

    void loop() {
     // put your main code here, to run repeatedly:

     //local variables
     static float pulseTime = 0; //us; the most recent input signal high pulse time
     static float pd_us = 0; //us; the most recent input signal period between pulses
     static float pulseFreq = 0; //Hz, the most recent input signal pulse frequency

     if (output_data == true) //if a pulse just came in
     {
       //turn off interrupts, grab copies of volatile data, and re-enable interrupts
       noInterrupts();
       output_data = false; //reset
       unsigned long pulseCountsCopy = pulseCounts; http://0.5us units
       unsigned long pdCopy = pd; http://0.5us units
       interrupts();

       //do calculations
       pulseTime = pulseCountsCopy / 2.0; //us
       pd_us = pdCopy / 2.0; //us
       pulseFreq = 1000000.0 / pd_us; //Hz

       //failsafe_count = ++failsafe_count; //Increment failsafe count by RDF
       //if ( pulseTime > 1000 ) {
       //  failsafe_count = 0;  // set counter to zero if pulses are > 1000
       // }

       //print values
       //(optionally, add extra code here to not print after EVERY pulse is received, as this can result in serial data coming in excessively fast when pulses come in at a high freq)
       //Serial.print(F("pulsetime(us) = ")); Serial.print(pulseTime);
       //Serial.print(F(", pd_us(us) = ")); Serial.print(pd_us);
       //Serial.print(F(", pulseFreq(Hz) = ")); Serial.println(pulseFreq);

       Serial.print(F("  Hall Count=")); Serial.println(count);
       Serial.print(F("IP Pulse=")); Serial.print(ip_pulse);
       //Serial.print(F("Error signal = ")); Serial.print(errsig);
       //Serial.print(F("reverse = ")); Serial.print(reverse);
       //Serial.print(F("Failsafe = ")); Serial.print(failsafe_count);

       // Hall switch counter, with increment/decrement depending on direction of rotation by RDF

       int enA = 3;
       int in1 = 2;
       int in2 = 4;

       if (state == HIGH && lastState == LOW) {

         //  if (reverse > 0 ) { ++count; } else { --count; }
         if (reverse > 0 ) {
           --count;
         } else {
           ++count;
         }
       }

       lastState = state;

       state = digitalRead(8);
     }

     // Calculations here

     ip_pulse = (((pulseTime - 1005) / 7) - 20); // For a screw length of about 250 revs. 25 is stick trim factor

     //AnalogSmooth section not used and commented out

     //int analog = ip_pulse; // put ip_pulse into AnalogSmooth

     // Defaults to window size 10
     //AnalogSmooth as = AnalogSmooth();

     //int analogSmooth = as.smooth(analog);

     //ip_pulse = analogSmooth;

     errsig = count - ip_pulse;

     // Testing motor output pins

     int enA = 3;
     int in1 = 2;
     int in2 = 4;

     // If errsig is negative, reverse the motor

     if (errsig < 0) {
       digitalWrite(in1, LOW);   //Swap in1 & in2 to reverse motor
       digitalWrite(LED_BUILTIN, HIGH);   // turn the Built In LED on (HIGH is the voltage level)
       digitalWrite(in2, HIGH);
       digitalWrite(enA, HIGH);    //High runs motor
       reverse = -7;
     }

     // If absolute value of errsig is less than 20, stop the motor

     if ((errsig < 10) && (errsig > -10))
     {
       digitalWrite(in1, HIGH);   //Swap in1 & in2 to reverse motor
       digitalWrite(in2, LOW);
       digitalWrite(enA, LOW);    //High runs motor
       reverse = 2;
     }

     //Set motor to forward
     if (errsig > 0) {
       digitalWrite(in1, HIGH);   //Swap in1 & in2 to reverse motor
       digitalWrite(LED_BUILTIN, LOW);   // turn the Built In LED off(HIGH is the voltage level)
       digitalWrite(in2, LOW);
       digitalWrite(enA, HIGH);    //High runs motor
       reverse = 8;
     }

     // If Failsafe triggered - set piston to empty
     if ((pulseFreq > 53) || (pulseFreq < 49) && (failsafe_count > 1000))
     {

       failsafe_count = ++failsafe_count; //Increment failsafe count by RDF

     //Failsafe routine (like piston tank initial setup.)

     digitalWrite(in1, HIGH); //Swap in1 & in2 to reverse motor
     digitalWrite(in2, LOW);
     digitalWrite(enA, HIGH); //High runs motor

     delay(35000); //35 second delay to get piston tank empty.

     //set rev counter to zero

     count = 0;

       digitalWrite(in1, HIGH);   //Swap in1 & in2 to reverse motor
       digitalWrite(in2, LOW);
       digitalWrite(enA, HIGH);    //High runs motor
       Serial.print(F("Failsafe = ")); Serial.print(pulseFreq);
     }

     //else {failsafe_count  = 0;
     //}

    } //end of loop()

    ////Use macro instead
    //boolean fastDigitalRead(volatile byte* p_inputRegister,byte bitMask)
    //{
    //  return (*p_inputRegister & bitMask) ? HIGH : LOW;
    //}

    void pinChangeIntISR()
    {
     //local variables
     static boolean pin_state_new = LOW; //initialize
     static boolean pin_state_old = LOW; //initialize
     static unsigned long t_start = 0; //units of 0.5us
     static unsigned long t_start_old = 0; //units of 0.5us

     pin_state_new = fastDigitalRead(p_input_pin_register, input_pin_bitMask);
     if (pin_state_old != pin_state_new)
     {
       //if the pin state actualy changed, & it was not just noise lasting < ~2~4us
       pin_state_old = pin_state_new; //update the state
       if (pin_state_new == HIGH)

       {
         t_start = timer2.get_count(); http://0.5us units
         pd = t_start - t_start_old; http://0.5us units, the incoming pulse period
         t_start_old = t_start; http://0.5us units; update
       }
       else //pin_state_new == LOW
       {
         unsigned long t_end = timer2.get_count(); http://0.5us units
         pulseCounts = t_end - t_start; http://0.5us units
         output_data = true;
       }
     }
    }

    //Interrupt Service Routines (ISRs) for Pin Change Interrupts
    //see here: http://www.gammon.com.au/interrupts

    //PCINT0_vect is for pins D8 to D13
    ISR(PCINT0_vect)
    {
     pinChangeIntISR();
    }

    //PCINT1_vect is for pins A0 to A5
    ISR(PCINT1_vect)
    {
     pinChangeIntISR();
    }

    //PCINT2_vect is for pins D0 to D7
    ISR(PCINT2_vect)
    {
     pinChangeIntISR();
    }

    void configurePinChangeInterrupts()
    {
     //Pin Change Interrupt Configuration
     //see ATmega328 datasheet, ex: pgs. 73-75
     //also see: C:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard\pins_arduino.h for the macros used here
     //1st, set flags on the proper Pin Change Mask Register (PCMSK)
     volatile byte* p_PCMSK = (volatile byte*)digitalPinToPCMSK(INPUT_PIN); //pointer to the proper PCMSK register
     *p_PCMSK = _BV(digitalPinToPCMSKbit(INPUT_PIN));
     //2nd, set flags in the Pin Change Interrupt Control Register (PCICR)
     volatile byte* p_PCICR = (volatile byte*)digitalPinToPCICR(INPUT_PIN); //pointer to PCICR
     *p_PCICR |= _BV(digitalPinToPCICRbit(INPUT_PIN));

     //  //ex: to use digital pin 8 as the INPUT_PIN:
     //  //turn on PCINT0_vect Pin Change Interrupts (for pins D8 to D13); see datasheet pg. 73-75.
     //  //1st, set flags on the proper Pin Change Mask Register
     //  PCMSK0 = 0b00000001; //here I am setting Bit0 to a 1, to mark pin D8's pin change register as on; for pin mapping see here: http://arduino.cc/en/Hacking/PinMapping168
     //  //2nd, set flags in the Pin Change Interrupt Control Register
     //  PCICR |= 0b00000001; //here I am turning on the pin change vector 0 interrupt, for PCINT0_vect, by setting the right-most bit to a 1
    }

    timgarrod
    AMS Website Webmaster

    Posts : 226
    Join date : 2013-04-23
    Age : 38

    Re: Arduino proportional control of a piston tank

    Post  timgarrod on Thu Dec 07, 2017 5:58 pm

    Cheers David,

    this was something i was planning to do but wasn't sure were to start.

    Cheers

    Tim

    tsenecal
    Guest

    Posts : 106
    Join date : 2015-04-01

    Re: Arduino proportional control of a piston tank

    Post  tsenecal on Fri Dec 08, 2017 4:38 am

    looks very good... would it be possible to have a list of parts? I liked the youtube video as well... seems nice and stable, no "hunting" once the piston position is matched to the stick position.
    avatar
    david f
    AMS Treasurer

    Posts : 1996
    Join date : 2010-11-10
    Age : 68
    Location : Cumbria

    Re: Arduino proportional control of a piston tank

    Post  david f on Fri Dec 08, 2017 9:20 am

    For hardware details I'm best just quoting Eric's words over on the SubCommittee:

    "Here is what you need:
    1x Arduino Nano Board - ~2 USD
    (purchase of ebay. Example: http://www.ebay.com/itm/1-2-5-10PCS-...o/282228063941 )

    Motor Speed Controller:


    Option 1 – H-Bridge (use the first code sample and wiring diagram below) – NOTE: current is limited with the below module to 2A. My tank pulled more amps so I want with the ESC instead.
    1x H-Bridge – L298N - ~2 USD
    (purchase of ebay. Example: http://www.ebay.com/itm/Stepper-Moto...o/170926726867 )"

    His full thread is here:

    http://subcommittee.com/forum/showthread.php?37060-DIY-Piston-Tank-Controller-with-an-Arduino-Board

    There are not many other bits. The Allegro Hall switch (A1104 ) I got on eBay. I have a couple of ordinary diodes (but 10amp!) wired across the microswitches.

    You make an interesting point Tim T about the lack of "hunting".

    I used a 40Mhz receiver for most of the trials because it is more prone to interference and "glitching" than a 458 one.

    All the software has is a "deadband" of  +/- 10 counts. The original pic software had a low speed approach to the set point and a few other things as well.

    They are not really necessary as long as you have a fairly slow geared motor. The tank in the video uses a 30:1 geared motor. This also keeps the current down. (less than 0.2 amps for the one in the video)

    A slow speed tank is OK with proportional control, I think. You just set the stick and go and do something else.

    I really like piston tanks but the thing that still holds them back is making them. Probably impossible without a lathe.

    Many thanks for the interest!

    David

    tsenecal
    Guest

    Posts : 106
    Join date : 2015-04-01

    Re: Arduino proportional control of a piston tank

    Post  tsenecal on Fri Dec 08, 2017 5:23 pm

    eric's words on subcommittee ring absent in my case.... even though i have an account on their forum, i am not a member of the subcommittee, and that thread is in their restricted "private" area, accessible to members only.

    that also explains why i never saw the original posting on subcommittee when it was first posted...
    avatar
    david f
    AMS Treasurer

    Posts : 1996
    Join date : 2010-11-10
    Age : 68
    Location : Cumbria

    Re: Arduino proportional control of a piston tank

    Post  david f on Wed Aug 15, 2018 2:26 pm

    Tim G pointed me towards one of these:



    They are very cheap (about £5) and easily available. They are quite a beast in their specification - purportedly being able to switch 43 Amps. That would be a very large piston tank or a "Robot Wars" type of servo!

    This photo shows the two Arduino proportional piston tank controllers. The original (2 Amps, I think) on the L.H.S and the new one on the right. Similar footprint but deeper to include a large heat sink.



    The H bridge doesn't come with any instructions (what can you expect for a fiver?) and the pinouts are a little confusing, but to use it as an H bridge for a single motor you do the following: (I have extracted this from the comments section of the software I have just put up on GitHub. (There is no change to the actual software, Arduino pins etc.):

    Semiconductor Motor Driver Auto BTS7960 43A H-Bridge PWM Drive For Arduino BF

    // Summary of pin connections when using IBT-2 Double BTS7960 H-bridge by RDF
    //On Arduino Nano:
    // A5 to receiver output
    // D8 to Hall switch counter
    //On IBT-2 Double BTS7960 H-bridge:
    // Connect pin 7 to +5v on Arduino
    // Connect pins 3 & 4 together and connect to D3 on Nano (These pins turn the motor on)
    //Connect pin 1 to D4 on Nano (These pins set the direction of rotation of the motor.)
    //Connect pin 2 to D2 on Nano ( These pins set the direction of rotation of the motor.)


    Some health warnings: I haven't used this software or hardware in the wet in a submarine yet. (I still use the original H bridge boards with John Robinson's additions controlled by a PIC processor. They just "work" in all my subs.)

    But nowadays, it is so much easier and cheaper for someone to simply buy one of these IBT-2 boards and control it with an Arduino.

    I will be taking both boards to Haydock Park (and a couple of Tom C's electric torpedoes) if any one wants to see them.

    David


    Last edited by david f on Thu Aug 16, 2018 10:04 am; edited 3 times in total

    timgarrod
    AMS Website Webmaster

    Posts : 226
    Join date : 2013-04-23
    Age : 38

    Re: Arduino proportional control of a piston tank

    Post  timgarrod on Wed Aug 15, 2018 6:24 pm

    How did you find these.

    I designing a twin version for my gato but works the same as the Tmax board.
    avatar
    david f
    AMS Treasurer

    Posts : 1996
    Join date : 2010-11-10
    Age : 68
    Location : Cumbria

    Re: Arduino proportional control of a piston tank

    Post  david f on Thu Aug 16, 2018 10:00 am

    Well I have only tried it on the bench, so far, and I certainly haven't put 43 Amps through it!

    Seems very rugged (these modern ones seem to have much better electronic protection on them - those are the things that John R added) and it is not much bigger than the 2 amp ones so I think they should be the starting point for anyone. (And I still can't believe its only £5)

    David



    timgarrod
    AMS Website Webmaster

    Posts : 226
    Join date : 2013-04-23
    Age : 38

    Re: Arduino proportional control of a piston tank

    Post  timgarrod on Thu Aug 16, 2018 9:09 pm

    thats good to know, will order a couple and have a play. still need to convert the two piston tanks to have a linear pot.

    tsenecal
    Guest

    Posts : 106
    Join date : 2015-04-01

    Re: Arduino proportional control of a piston tank

    Post  tsenecal on Tue Sep 11, 2018 3:32 pm

    David,

    i finally got around to testing this code, and it will not compile...

    #include <AnalogSmooth.h>

    #include <eRCaGuy_Timer2_Counter.h>

    these are two libraries that are not standard..... can you provide links to them?
    avatar
    david f
    AMS Treasurer

    Posts : 1996
    Join date : 2010-11-10
    Age : 68
    Location : Cumbria

    Re: Arduino proportional control of a piston tank

    Post  david f on Tue Sep 18, 2018 1:21 pm

    Hi Tim,

    Thanks for pointing these problems out.
    I have uploaded a modified version of the sketch to Github:

    Piston_4g
    https://github.com/rdforrest/submarine-proportional-pistontank/blob/master/Piston_4g.ino

    What I have done is remove all reference to AnalogSmooth (I didn't use it anyway.)

    The details for Gabriel Staples are below: (copied from the sketch)

    "By Gabriel Staples
     http://www.ElectricRCAircraftGuy.com/
     -My contact info is available by clicking the "Contact Me" tab at the top of my website.
     Written: 28 Nov. 2013
     Updated: 21 March 2015
     http://www.electricrcaircraftguy.com/2014/02/Timer2Counter-more-precise-Arduino-micros-function.html
     David Forrest note: Seems to need $5 donation now(18/9/2018)
     https://github.com/ElectricRCAircraftGuy/eRCaGuy_Timer2_Counter
    "

    He does seem to need a $5 donation now. (I don't remember that when I started on this!)

    I am still finding out about the Arduino and libraries!

    Hope this works OK now. (I have just checked and the same sketch works for both the low current H bridge and the 43A beast! (I would go with the beast, it is only slightly bigger physically)

    Probably best to point out that is only bench tested not "in the wet"as yet. (My winter project after I get Tom's torpedoes running straight and hot!)

    David

    tsenecal
    Guest

    Posts : 106
    Join date : 2015-04-01

    Re: Arduino proportional control of a piston tank

    Post  tsenecal on Tue Sep 18, 2018 3:23 pm

    I am going to do a little more research on this...

    after i posted the reply to you about the two different libraries, i did find a github repository with an older version of the eRCaGuy_Timer2_Counter library available for free.

    it appears the reason for the eRCaGuy_Timer2_Counter library is that it provides a much nicer, less "jittery" calculation for the receiver PWM signal coming into the arduino. in my code that i use on things like my robbe multi-prop decoder, i simply use the standard microseconds call.

    what i have found is the eRCaGuy_Timer2_Counter library only works on atmega 328p processors, commonly found in arduino mini and nano devices and clones. i primarily use the atmega 32u4 based sparkfun pro micro clones... the free version of the eRCaGuy_Timer2_Counter library will not compile on the pro micro clones...

    the reason this guy wrote his library is because the standard micros "system" call is shut off when interrupts are disabled, so the micros call is not guaranteed to be 100% accurate. you can see in the code, the disable/enable interrupts call is being used in the main loop when the "pulseCountsCopy" variable is being set. granted inside that block, two variables are being set, so not alot of time is spent there, but if we can remove it, micros might work well enough. I will keep you posted on what i find.

      Current date/time is Wed Dec 12, 2018 9:13 pm