element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Personal Blogs
  • Community Hub
  • More
Personal Blogs
John Wiltrout's Blog Process Duration Timer Part (4) The Brain and Proof of Concept
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: jw0752
  • Date Created: 6 Aug 2017 4:22 AM Date Created
  • Views 1697 views
  • Likes 10 likes
  • Comments 3 comments
  • diytestequipch
  • process duration timer
Related
Recommended

Process Duration Timer Part (4) The Brain and Proof of Concept

jw0752
jw0752
6 Aug 2017

The purpose of the Process Duration Timer (PDT) is to provide a means to set up an experiment and time a process, whether it is the discharging of a battery, the discharging of a capacitor or some other process that one does not want to sit around and watch. The PDT allows the experimenter to set up the experiment and walk away. The PDT watches the voltages and pushes the button on the stop watch the second that the process voltage crosses the target goal.

 

In the last three blogs we have built the power supply, the clock circuit , and the interfaces have been designed and bread boarded. Today we will work with the Arduino.

 

All I need at this point to hook things together and test the PDT idea to see if it will work is a properly programmed Arduino. A couple years ago I built a multiple unit project using the Arduino Duemilanove and since I still have several of these boards, this will be the board that I will try to program. I say try to program as this is the part of this project that I am the least comfortable with.

 

I always begin a programming project with a flow chart that takes me on a step by step path through the logic of what I want to do. As you will see the logic needed for this project is very straight forward and even I should be able to program it.

 

Here is a list of the flow chart:

 

Initialize the Timer so that it resets to 00:00:00

Begin Program Loop

     Begin sub loop

          Read the analog pin for the Test Voltage

          Repeat this process 10 times

          Sum the individual readings

          Exit the sub loop

     Divide summed value of Test Voltage by 10 and Store

     Begin sub loop

          Read the analog pin for the Target Voltage

          Repeat this process 10 times

          Sum the individual readings

          Exit the sub loop

     Divide summed value of Target Voltage by 10 and Store

     Test to see if the Test Voltage is lower than the Target voltage

     If "No" start Main loop again

     If "Yes" do the following:

          Turn on the Clock suspend timing relay

          Begin a Sub loop with no logical exit.

 

I got out my arduino programming books, I booted up the Arduino website and got out my notes from previous efforts to program the Arduino. Because it was a very simple program it wasn't long before I had something put together. I also added the ability to print my analog pin readings to the computer monitor so that during the Proof of Concept test I would be able to watch the numbers that would be used by the Arduino to represent my voltage levels. Here is the program that I came up with:

 

/* Program to Zero a clock and then begin reading the voltage from a Test Voltage and comparing
it to a Target Voltage. If the Target Voltage exceeds the Test Voltage the Pin 12 is pulled 
which stops the clock */


const int CLOCK = 10;        // assign the Clock reset function to Pin 10
const int SUSP = 12;          // assign the Suspend function to Pin 12
const int TEST = 0;          // Assign TEST to Analog 0
const int TARGET = 1;        // Assign TARGET to Analog 1
int valtest = 0;
int valtarg = 0;
int vte = 0;
int vta = 0;                // initialize the variables


void setup()
{
  Serial.begin(9600);
  pinMode(CLOCK,OUTPUT);
  pinMode(SUSP, OUTPUT);
  digitalWrite(SUSP,LOW);
  digitalWrite(CLOCK,LOW);
  delay(2000);
  digitalWrite(CLOCK,HIGH);
}


void loop()
{
  vte = 0;
  for(int x=0; x<10; x++)
  {
    valtest=analogRead(TEST);
    vte=vte+valtest;
  }
  valtest = vte/10;
  
  vta = 0;
  for ( int x=0; x<10; x++)
  {
    valtarg = analogRead(TARGET);
    vta = vta + valtarg;
  }
  valtarg = vta/10 ;
  
  Serial.print("Test Voltage:   ");
  Serial.print(valtest);
  Serial.print("     Target Voltage:   ");
  Serial.println(valtarg);
  delay(2000);
  
  if (valtarg > valtest)
  {
    digitalWrite(SUSP,HIGH);
    while(valtarg = valtarg)
    {
      delay(1000);
    }
  }
}

 

This program works but it probably could use some polish. Ideas and suggestions are welcome. I have only improved my knowledge on this site thanks to the great ideas and suggestions for improvement offered to me by my fellow members.

 

Now that I had a programmed Arduino I used my bread boarded interface circuits to put together a working prototype that I could test to see if the Arduino would accept the voltages and make the correct decisions with respect to controlling the clock. Here is a short video of the proof of concept test.

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

 

Now that I have a working prototype the next project will be to build the interfaces onto a shield that will mount to the Arduino and then connect it up to the rest of the systems. In the mean time I have completed the mechanics of mounting the switches, Clock and input jacks to the project enclosure. Here are a few pictures of the progress to date:

 

image

 

image

 

image

 

image

As you may have noticed in the second picture above the strain relief I was using was on the mains cord was not conventional nor adequate. I have since rectified this problem with a more sturdy and conventional anchor.

 

In the next and final Blog the interface shield will be built and wired into the system. The wiring will be completed to the switches and controls and I will make a video of the unit in operation.

 

John

 

https://www.element14.com/community/people/jw0752/blog/2017/08/08/process-duration-timer-final-chapter-assembly-and-testing

  • Sign in to reply

Top Comments

  • shabaz
    shabaz over 7 years ago +2
    Hi John, Nice looking code!! The loop with no logical ending is very cool too : ) That's actually a fun thing to see, how different people implement such things. The one I use a lot is "while (forever…
  • mcb1
    mcb1 over 7 years ago +1
    It looks like it is getting there. The only comment I would make in your sketch is to shift the delay(2000) on line 50 to between 59 and 60. The reasoning is that you serial print the result then wait…
  • jw0752
    jw0752 over 7 years ago in reply to mcb1 +1
    Hi Mark, Thanks for checking it out. I appreciate your input. John
  • shabaz
    shabaz over 7 years ago

    Hi John,

     

    Nice looking code!!

    The loop with no logical ending is very cool too : ) That's actually a fun thing to see, how different people implement such things. The one I use a lot is "while (forever)" where forever is defined to be 1. Looks like there is a whole wikipedia page on the various ways to do it: https://en.wikipedia.org/wiki/Infinite_loop

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • jw0752
    jw0752 over 7 years ago in reply to mcb1

    Hi Mark,

    Thanks for checking it out. I appreciate your input.

    John

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mcb1
    mcb1 over 7 years ago

    It looks like it is getting there.image

     

    The only comment I would make in your sketch is to shift the delay(2000) on line 50 to between 59 and 60.

    The reasoning is that you serial print the result then wait 2 secs before entering the never ending loop.

     

    I presume you want to record the result as soon as you detect it, rather than adding 2 secs.

     

     

    Cheers

    Mark

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube