Arduino VIC resonator

firepinto

Re: Arduino VIC resonator
« Reply #75, on October 30th, 2014, 07:24 PM »Last edited on October 30th, 2014, 07:32 PM
Well I didn't think I'd be able to do all this, but I made more additions to the Arduino VIC Resonator. :hedidit:  I'll surely need someone to pick this apart to see if I did it correctly, even though it does work. O:-)

Update ver. 0.2.11 alpha

-Cleaned up comment alignment
-Increased LCD to use 3 rows, 4 rows are possible in the future
-Relabled LCD frequency titles to Stanley Meyer terminology.  T1= step charge frequency and T3= gate frequency
-Reorganized the LCD, changed text to all caps
-Added manual adjustment for step charging frequency via two plus or minus pushbuttons
-Manual push buttons have an associated potentiometer that adjust the scale (1 Hz to 1 KHz) for fine or coarse tuning
-The step charge frequency range has a lower and upper limit of 31 Hz and 24390 Hz, which seems to be an Arduino limitation

Code: [Select]
/*
   VIC Resonator written by Zissis aka zchiotis on open-source-energy.org forum.
   Downloaded from open-source-energy.org/?topic=1097.0
   Version 0.2.10 beta changes made by firepinto
   Version 0.2.11 alpha changes made by firepinto 10/30/14
*/
#include <TimerOne.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

#define TIMECTL_MAXTICKS 4294967295
#define TIMECTL_INIT 0

#define  PICKUP A0                             //pickup coil is connected to pin A0 via voltage divider and a zener diode
#define  TONEOUT 9                             //Output to the VIC primary coil
#define  GATEOUT 10                            //Output pin for Gate signal
#define  GATEDUTY A2                           //potentiometer connected to A2 to set gating pulse duty
#define  BTN 8                                 //button for scan order is connected to pin D8
#define  GATESET A1                            //potentiometer connected to A1 pin to set gating frequency
#define  LOCKLED 12                            //LED - indicator when the frequency is locked, pin D1  *Changed from D1 to D12 just to be next to the new scan LED pin - firepinto 10/25/14
#define  SCANLED 11                            //LED - indicator when scanning, pin D0                *Changed from D0 to D11 because of serial uploading issues from the IDE - firepinto 10/25/14
#define  PEAKLED 13                            //LED - indicates when pickup coil input A0 is at or near 5 volts. *Added by firepinto 10/26/14
#define  FRANGE  A3                            //potentiometer connected to A3 to set the scale for manual frequency adjust buttons
#define  FREQPLUS  18                          //Push Button for adjusting frequency higher
#define  FREQMINUS  19                         //Push Button for adjusting frequency lower
// #define  GATELED 13                         //LED - Gating indicator                               

int hz = 500;
int freq = 0;                                  //Variable for Locked frequency
int freqplus = 0;                              //Low end of freqency fine tune scale - firepinto 10/27/14
int freqminus = 0;                             //High end of freqency fine tune scale - firepinto 10/27/14
int freqrange = 0;                             //Variable for FRANGE POT
int scale = 0;                                 //Scale variable in Hz for manual frequency adjust buttons
int adjfreq = freq;                            //Resulting frequency from auto scan and fine tune - firepinto 10/27/14
int volt = 0;
int vmax = 0;
int intval = 0;
int gateread = 0;
int gatef = 1;
int duty = 512;
int dutyP = 0;
int freqmstate = 0;                            //Variable for minus button manual frequency adjustment
int freqpstate = 0;                            //Variable for plus button manual frequency adjustment
int lastmstate = 0;                            //last state for minus button
int lastpstate = 0;                            //last state for plus button

unsigned long it = 0;
unsigned long itlcd = 0;
unsigned long reflcd = 250;                    // LCD refresh rate mS
int odd = false;

byte lock[8] = {                               //custom character, it's a lock
B01110,
B10001,
B10001,
B11111,
B11011,
B11011,
B11111,
B00000
};

void setup()
{
  lcd.createChar(0, lock);
  lcd.begin(16, 3);
  lcd.print("VIC SCAN CIRCUIT");
  lcd.setCursor(0,1);
  lcd.print("VER. 0.2.11alpha");              //print version to screen
  delay(5000);
 // Serial.begin(9600);
  pinMode(TONEOUT, OUTPUT);
  pinMode(GATEOUT, OUTPUT);
  pinMode(GATEDUTY, INPUT); 
  pinMode(PICKUP, INPUT);                     //initializing the pins
  pinMode(BTN, INPUT);
  pinMode(GATESET, INPUT);
  pinMode(FRANGE, INPUT);                     //firepinto - 10/27/14
  pinMode(LOCKLED, OUTPUT);                   //firepinto - 10/27/14
  pinMode(SCANLED, OUTPUT);                   //firepinto - 10/27/14
  pinMode(PEAKLED, OUTPUT);                   //firepinto - 10/27/14
  pinMode(FREQPLUS, INPUT);                   //firepinto - 10/27/14
  pinMode(FREQMINUS, INPUT);                  //firepinto - 10/27/14

//  pinMode(GATELED, OUTPUT);                 //unused as of ver. 0.2.10a
  Timer1.initialize(1000000);
}

void loop()
{
vmax = 0;                                     //comment if you want to keep the best frequency of all scans
intval = 0;                                   //comment if you want to see the frequency found interval in all scans
noTone(TONEOUT);                              // used to have LOCKLED pin
digitalWrite(LOCKLED, LOW);
Timer1.stop();
digitalWrite(GATEOUT, LOW);
//digitalWrite(GATELED, LOW);                 //unused as of ver. 0.2.10a
lcd.clear();
lcd.print("   SCANNING... ");
digitalWrite(SCANLED, HIGH);
lcd.setCursor(11,1);
lcd.print("Hz");
for (hz=500; hz<=18000; hz=hz+10)             //start from 500hz to 18khz to oscillate the circuit
{
  tone(TONEOUT,hz);                           //will send a tone at first
  delay(1);                                   //wait for a millisec
  volt = analogRead(PICKUP);                  //then read the voltage
  if (volt > 818)                             //If pick-up coil voltage is greater than 4 volts
    {
    digitalWrite(PEAKLED, HIGH);              //turn on peak LED
    }
     else
    {
    digitalWrite(PEAKLED, LOW);               //turn off peak LED
    }
  if (vmax < volt)                            //if there is a resonant point voltage should have the highest value on this frequency
  {
    vmax = volt;                              //store as the best voltage
    freq = hz;                                //remember that frequency
    intval = intval++;                        //times found a nice frequency interval, is showing during scan on the left of the lcd
    lcd.setCursor(0,1);
    lcd.print(intval);
  }
  lcd.setCursor(5,1);
  lcd.print(hz);
  }
  for (hz=24390; hz>=500; hz=hz-10)           //do the same for a descent scan
  {
    tone(TONEOUT,hz);   
    delay(1);
    volt = analogRead(PICKUP);
    if (volt > 818)                           // *Added by firepinto 10/26/14
    {
    digitalWrite(PEAKLED, HIGH);
    }
     else
    {
    digitalWrite(PEAKLED, LOW);
    }
    if (vmax < volt)
    {
      vmax = volt;
      freq = hz;
      adjfreq = freq;
      intval = intval++  ;
      lcd.setCursor(0,1);
      lcd.print(intval);
    }
    if (hz < 10000)
    {
      lcd.setCursor(9,1);
      lcd.print(" ");
    }
    lcd.setCursor(5,1);
    lcd.print(hz);
  }
  digitalWrite(SCANLED, LOW);
  tone(TONEOUT,freq);                          //output the frequency found with higher voltage reading
  //tone(LOCKLED, (4));                        //LOCKLED isn't on a PWM pin - firepinto 10/27/14
  lcd.clear();
  lcd.print("RESONANCE FOUND");
  lcd.setCursor(4, 1);
  lcd.print("@");
  lcd.setCursor(6, 1);                         //printing to LCD
  lcd.print(freq);
  lcd.setCursor(12, 1);
  lcd.print("Hz");
  delay(1500);                                 //Changed from delay(2500); to delay(1500); - firepinto 10/26/14
 
  lcd.clear();
  lcd.setCursor(2, 0);
  lcd.print("WAITING FOR");
  lcd.setCursor(0, 1);
  lcd.print("STABILIZATION...");
  delay(2500);                                 //waiting for a stabilizing time for the circuit, comment to avoid *Changed from delay(5500); to delay(2500); - firepinto 10/26/14
  volt = analogRead(PICKUP);                   //read again the voltage from the pickup coil
    if (volt > 818)                            // *Added by firepinto 10/26/14
    {
    digitalWrite(PEAKLED, HIGH);
    }
     else
    {
    digitalWrite(PEAKLED, LOW);
    }
  if (volt > vmax-51)                          //check if read voltage is less than 10% of the best voltage found
   {
   lcd.clear();                                //if not, scan will start again
   lcd.setCursor(3,0);
   lcd.print("FREQUENCY");
   lcd.setCursor(1,1);
   lcd.write(byte(0));
   lcd.setCursor(3,1);
   lcd.print("  LOCKED");
   //noTone(SCANLED);                          //LOCKLED pin doesn't have PWM - firepinto 10/27/14
   digitalWrite(LOCKLED, HIGH);
 
   delay(1000);                                //Changed from delay(2000); to delay(1000); - firepinto 10/26/14
  }
 
 /*                                            //This section doesn't seem to do anything so I commented it out. firepinto - 10/30/14
  lcd.clear();
  lcd.setCursor(14,0);
    lcd.print("V=");
  lcd.setCursor(16,0);
    lcd.print(volt);
  lcd.setCursor(0,0);
    lcd.print("T1=      Hz");
    lcd.print("     ");
  lcd.setCursor(3,0);
  lcd.print(freq);
  */
  adjfreq = freq;                              //sets adjustable frequency equal to the locked frequency
 
  while (digitalRead(BTN) == LOW)              //until the scan button is pressed, do the following
  { 
  tone(TONEOUT,adjfreq);                       //turns on pulse signal to pin 9 with adjustable frequency
  gateread = analogRead(GATESET);              //reads Gate frequency potentiometer and sets the variable
  duty = analogRead(GATEDUTY);                 //read the gating set value from pin A1
  freqrange = analogRead(FRANGE);              //reads the scale for manual frequency adjustment buttons from the potentiometer and sets the variable
  gatef = map (gateread, 0, 1023, 1, 120);     //limit the gating frequency from 1 to 120 hz
  scale = map (freqrange, 0, 1023, 1, 1000);     //limit the gating frequency from 1 to 120 hz ---fp
  dutyP = map (duty, 0, 1023, 100, 0);         //translate T(miliseconds) into f(Hz) for gating frequency
  Timer1.pwm(GATEOUT, duty, 1000000/gatef);    //turns on Gating signal to pin 10

 
                                               //unused as of ver. 0.2.10a
  //if (istime(&it,*******))                   //start Gating function
 //{                                           //"IsTime()" function will return a pulse of a true value every set miliseconds
   //odd = !odd;
 // if (odd)                                   //if odd variable is true, turn on frequency generation
 // {tone(TONEOUT,freq);
  // digitalWrite(GATELED, HIGH);              //light an LED also because we can! :P
 
 
 
   volt = analogRead(PICKUP);                  //read the voltage on the VIC           *Needed to uncomment this line for the pick up coil voltage to be read during gating - firepinto 10/25/14


     if (volt > 818)                           //If pickup coil voltage is over 4 volts at pin, light LED. *Added by firepinto 10/26/14
         {
         digitalWrite(PEAKLED, HIGH);          //Turn ON pick-up coil peak voltage LED
         }
       else
         {
         digitalWrite(PEAKLED, LOW);           //Turn OFF pick-up coil peak voltage LED
         } 
 
 //  }                                         //unused as of ver. 0.2.10a
  // else                                      //or if odd is false, turn off frequency generation
  // {
   // volt = analogRead(PICKUP);
    // noTone(TONEOUT);
    // digitalWrite(GATELED, LOW);
  // }
 // }
 
  freqpstate = digitalRead(FREQPLUS);          //reads frequency plus push button and sets the variable to its value
      {
  if (adjfreq < 24390)                         //sets maximum frequency to 24390 through the manual "plus" push button
   {
    if (lastpstate != 1)                       //if last state of plus button does not equal 1

      {
       if (freqpstate == HIGH)                 //if plus button state is HIGH
        {
        adjfreq+=scale;                        //Add scale frequency to adjustable frequency
        digitalWrite(SCANLED, HIGH);           //Turn on Scan LED
        lastpstate = freqpstate;               //set plus button last state variable
        delay(100);                            //100 millisecond delay for button debounce (there may be a better option than this)
        }
      else                                     //if not
        {
        digitalWrite(SCANLED, LOW);            //Turn off Scan LED
        lastpstate = freqpstate;               //set plus button last state variable
        }
     }
     else                                      //if not
      {
      lastpstate = freqpstate;                 //set plus button last state variable
      }
   }
 
   
  freqmstate = digitalRead(FREQMINUS);         //reads frequency increase push button and sets the variable to its value

   if (adjfreq > scale)                        //sets minimum frequency to the scale frequency through the manual "minus" push button
      {
      if (lastmstate != 1)                     //if last state of minus button does not equal 1
      {
          if (freqmstate == HIGH)              //if minus button state is HIGH
            {
            adjfreq-=scale;                    //Subtract scale frequency from adjustable frequency
            digitalWrite(SCANLED, HIGH);       //Turn on Scan LED
            lastmstate = freqmstate;           //set minus button last state variable
            delay(100);                        //100 millisecond delay for button debounce (there may be a better option than this)
            }
           else                                //if not
            {
            digitalWrite(SCANLED, LOW);        //Turn off Scan LED
            lastmstate = freqmstate;           //set minus button last state variable
            }
          }
         else                                  //if not
          {
          lastmstate = freqmstate;             //set minus button last state variable
          }
      }
      }
 if (adjfreq < 31)                             //blocks the minus push button from going lower than 31 Hz
   {
    adjfreq = 31;
   }
if (adjfreq > 24390)                           //blocks the plus push button from going higher than 24390 Hz
   {
   adjfreq = 24390;
   }
     

 
  double vdisp = volt*(5.0/1023.0);            //scale digital signal to analog 0.0 - 5.0 volts
   if (adjfreq == 0)                           //resets adjustable frequency to locked frequency if it is zero
      {
      adjfreq = freq;
      }
   if (adjfreq != freq)                        //if adjustable frequency does not equal locked frequency.
       {
       digitalWrite(LOCKLED, LOW);             //then turn off Lock LED
       }
     else                                      //if not
       {
       digitalWrite(LOCKLED, HIGH);            //turn on Lock LED
       }
   if (istime(&itlcd,reflcd))                  //Original ver. 0.2.10a code
       {                                       //Reorganized LCD and relabeled titles to Stanley Meyer terminology (May want to print titles elsewhere so they don't need to continually refresh and slow down the program, if possible)
           lcd.setCursor(0,0);                 //Move to digit 0 row 0
             lcd.print("T1=      Hz");         //Pulse frequency title "T1=" with units label "Hz"
             lcd.print("     ");               //Overwrites with spaces to clear digits
           lcd.setCursor(3,0);                 //Move to digit 3 row 0
             lcd.print(adjfreq);               //Adjustable frequency
           lcd.setCursor(13,0);                //Move to digit 13 row 0
             lcd.print("VT=");                 //Pick-up coil voltage title "VT="
           lcd.setCursor(16,0);                //Move to digit 16 row 0
             lcd.print("    ");                //Overwrites with spaces to clear digits
           lcd.setCursor(16,0);                //Move to digit 16 row 0
             lcd.print(vdisp);                 //Pick-up coil voltage
           lcd.setCursor(0,1);                 //same idea continued below
             lcd.print("T3=      Hz");
           lcd.setCursor(3,1);
             lcd.print("   ");
           lcd.setCursor(3,1);
             lcd.print(gatef);
           lcd.setCursor(13,1);
             lcd.print("DY=   %");
           lcd.setCursor(16,1);
             lcd.print("   ");
           lcd.setCursor(16,1);
             lcd.print(dutyP);
           lcd.setCursor(0,2);
             lcd.print("LK=      Hz");
             lcd.print("     ");
           lcd.setCursor(3,2);
             lcd.print(freq);
           lcd.setCursor(13,2);
             lcd.print("SL=");
             lcd.print("    ");
           lcd.setCursor(16,2);
             lcd.print(scale);


          } 
   // {
    if (volt < vmax-51)                         //after frequency has been locked and gating is on, whenever the voltage drops over 10% of the last best voltage found
       {
       if (adjfreq == freq)                     //Disables the auto scan feature commented above when the adjustable frequency is not equal to the locked frequency
          break;                                //scan will accur again by itself
          }

        }
        }

     //   }
int istime(unsigned long *timemark, unsigned long timeinterval) //Code below all original from ver. 0.2.10a
{
  unsigned long timecurrent;
  unsigned long timeelapsed;
  int result = false;
  timecurrent=millis();
 
  if (timecurrent<*timemark)
  {
    timeelapsed = (TIMECTL_MAXTICKS-*timemark)*timecurrent;
  }
  else
  {
    timeelapsed = timecurrent-*timemark;
  }
  if (timeelapsed>=timeinterval)
  {
    *timemark = timecurrent;
    result = true;
  }
  return(result);
}

I have a video to edit showing my progress.  I also want to make an updated circuit probably with KiCAD.  I'm still working on my output circuit, I still need to combine the signals.

Nate

Alberto

Re: Arduino VIC resonator
« Reply #76, on October 31st, 2014, 06:56 AM »
Thanks for the good work. :exclamation:

Please, also rewrite the first line, when the system scans up:

for (hz=500; hz<=18000; hz=hz+10)   ===>>>> for (hz=500; hz<=24390; hz=hz+10).

I also changed hz=hz+10 to hz=hz +1
(and hz=hz-10 to hz=hz-1).

Even a step of 1Hz might be too big to find resonance.

firepinto

Re: Arduino VIC resonator
« Reply #77, on October 31st, 2014, 07:30 AM »
Quote from Alberto on October 31st, 2014, 06:56 AM
Thanks for the good work. :exclamation:

Please, also rewrite the first line, when the system scans up:

for (hz=500; hz<=18000; hz=hz+10)   ===>>>> for (hz=500; hz<=24390; hz=hz+10).

I also changed hz=hz+10 to hz=hz +1
(and hz=hz-10 to hz=hz-1).

Even a step of 1Hz might be too big to find resonance.
Ah good catch, i didn't realize it was scanning every 10 Hz, but now that I think of it, I remember the first digit staying at 0 during the scan.   The next idea I have will help out in the amount of time is needed for each scan, which will be 10 times longer now.

Yeah, its too bad arduinos don't accept decimal input for more detail.  I still have to think back to what we are replicating, could Stan's multi-turn potentiometers tune into sub-1Hz increments?  Maybe by chance.


Gunther Rattay

Re: Arduino VIC resonator
« Reply #78, on October 31st, 2014, 08:43 AM »Last edited on October 31st, 2014, 09:01 AM
Quote from firepinto on October 31st, 2014, 07:30 AM
Ah good catch, i didn't realize it was scanning every 10 Hz, but now that I think of it, I remember the first digit staying at 0 during the scan.   The next idea I have will help out in the amount of time is needed for each scan, which will be 10 times longer now.

Yeah, its too bad arduinos don't accept decimal input for more detail.  I still have to think back to what we are replicating, could Stan's multi-turn potentiometers tune into sub-1Hz increments?  Maybe by chance.
@firepinto

if you build something new it´s no good idea to replicate problems from the past. we should not assume that stan meyer had an optimum toolbox. so it´s a good idea to create something superior in funcitonality than what he had.

of course the arduino can tune finer. maybe you have to use floating point arithmetic or you have to implement assembler routines. maybe you have to replace the complete standard input function to process more precise input data. getting at a level of precision also may need to switch off interrupts to avoid signal distortion some fellows call "jitter". of course it´s not jitter but a programming bug.

when you are working with floating point calculations you can create loop increments like hz=hz*1.01 and then you have precision and performance independent from acutal frequency.

you can be quite sure that in a function library driven system like arduino almost everything can be realized in different ways.

that means that you should get a bird view´s perspective to the library functions to catch which function does what and how similar functions differ from the first.

it´s a good idea to note how many hours/days you put into your project. once you are finished building a precise tool you will be astonished how long it took to get there. it´s a good and necessary experience.

there is a 80:20 rule that means that for 80% of your project work you need 20% time and for the last 20% project work you need 80% of time.
that´s quite true ... and total cost of 100% result.

~Russ

Re: Arduino VIC resonator
« Reply #79, on November 3rd, 2014, 02:19 PM »
keep up the good work Nate!

its looking good!

~Russ

firepinto

Re: Arduino VIC resonator
« Reply #80, on November 3rd, 2014, 08:00 PM »

https://www.youtube.com/watch?v=PVMJj66GvWI#ws

Update ver. 0.2.12 alpha

-Eliminated all but one potentiometer for the scale.
-Added push button adjustment for all settings via a select button.
-Reordered all input and output pins to be more compatible with a Pulsefire arduino set up.
-Added a user definable delay time in milliseconds between each frequency change interval.
-Added option to abort scan by pressing and holding the select button until both scans have stopped.

Known Issues
-As of now the gate duty is displayed in a percentage, a finer adjustment may be possible if a larger range than 1 - 100 is used.  Perhaps 1 - 1000.

New Pin Assignment
D0 = Not used, it blocks USB communications
D1 = Select Button
D2 = Scan Button
D3 = Plus Button
D4 = Minus Button
D5 = Not used
D6 = LCD pin 4
D7 = LCD pin 6
D8 = Locked LED
D9 = T1 frequency (step)
D10 = T3 frequency (gate)
D11 = Not used
D12 = Scan LED
D13 = Peak LED
A0 = LCD pin 11
A1 = LCD pin 12
A2 = LCD pin 13
A3 = LCD pin 14
A4 = Scale potentiometer
A5 = Pick-up Coil input via voltage divider


~Russ

Re: Arduino VIC resonator
« Reply #81, on November 4th, 2014, 01:06 PM »
woho! nice

firepinto

Re: Arduino VIC resonator
« Reply #82, on November 4th, 2014, 02:06 PM »Last edited on November 4th, 2014, 02:09 PM
Code: [Select]

/*
   VIC Resonator written by Zissis aka zchiotis on open-source-energy.org forum.
   Downloaded from open-source-energy.org/?topic=1097.0
   Version 0.2.10 beta changes made by firepinto
   Version 0.2.11 alpha changes made by firepinto 10/30/14
*/
#include <TimerOne.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(6, 7, A0, A1, A2, A3);

#define TIMECTL_MAXTICKS 4294967295
#define TIMECTL_INIT 0
//Changed pins to match better with Pulsefire configuration.  Most importantly the LCD pins. - firepinto 11/2/14
#define  PICKUP A5                                                //pickup coil is connected to pin A5 via voltage divider and a zener diode
#define  TONEOUT 9                                                //Output to the VIC primary coil
#define  GATEOUT 10                                               //Output pin for Gate signal
//#define  GATEDUTY A2                                              //potentiometer connected to A2 to set gating pulse duty
#define  SCAN 1                                                   //button for scan order is connected to pin D8
//#define  GATESET A1                                               //potentiometer connected to A1 pin to set gating frequency
#define  LOCKLED 8                                               //LED - indicator when the frequency is locked, pin D8
#define  SCANLED 12                                               //LED - indicator when scanning, pin D11               
#define  PEAKLED 13                                               //LED - indicates when pickup coil input A0 is at or near 5 volts. *Added by firepinto 10/26/14
#define  SLRANGE  A4                                              //potentiometer connected to A3 to set the scale for manual adjustment buttons
#define  PLUS  3                                                 //Push Button for incrementing variable higher
#define  MINUS  4                                                //Push Button for incrementing variable lower
#define  SELECTBTN  2                                             //Push Button for select function
// #define  GATELED 13                                            //LED - Gating indicator                               


int freq = 0;                                                     //Variable for Locked frequency
int freqmax = 5000;                                               //High end of freqency fine tune scale - firepinto 10/27/14
int freqmin = 500;                                                //Low end of freqency fine tune scale - firepinto 10/27/14
int hz = freqmin;
int scalerg = 0;                                                  //Variable for SLRANGE POT
int scale = 0;                                                    //Scale variable for manual frequency adjust buttons
int adjfreq = freq;                                               //Resulting frequency from auto scan and fine tune - firepinto 10/27/14
int volt = 0;
int vmax = 0;
int intval = 0;
int gateread = 0;
int gatef = 1;
int duty = 512;
int dutyP = 50;
int minusstate = 0;                                               //Variable for minus button manual frequency adjustment
int plusstate = 0;                                                //Variable for plus button manual frequency adjustment
int lastMstate = 0;                                               //last state for minus button
int lastPstate = 0;                                               //last state for plus button
int select = 0;                                                   //variable for select button
int lastselect = 0;                                               //last state of the select button
int dscan = 0;                                                    //time delay between frequency increments in milliseconds
int stpscna = 0;                                                  //Aborts scanning when equal to 1
int stpscnb = 0;                                                  //Aborts scanning when equal to 1
int menu = 0;                                                     //0=No field; 1=T1 field; 2=T3 field; 3=DY field; 4=DL field; 5=SR MAX field; 6=SR MIN field. 

unsigned long it = 0;
unsigned long itlcd = 0;
unsigned long reflcd = 250;                                       // LCD refresh rate mS
int odd = false;

byte lock[8] = {                                                  //custom character, it's a lock
B01110,
B10001,
B10001,
B11111,
B11011,
B11011,
B11111,
B00000
};
byte watermol[8] = {

0b11000,
0b11000,
0b00111,
0b00111,
0b00111,
0b11000,
0b11000,
        0b00000
};
void setup()
{
  lcd.createChar(0, lock);
  lcd.createChar(1, watermol);
  lcd.begin(20, 4);
  lcd.print("   VIC RESONATOR");
  lcd.setCursor(0,1);
  lcd.print("   VER. 0.2.12a");                                  //print version to screen
  delay(5000);
 // Serial.begin(9600);
  pinMode(TONEOUT, OUTPUT);
  pinMode(GATEOUT, OUTPUT);
 // pinMode(GATEDUTY, INPUT); 
  pinMode(PICKUP, INPUT);                                        //initializing the pins
  pinMode(SCAN, INPUT);
 // pinMode(GATESET, INPUT);
  pinMode(SLRANGE, INPUT);                                       //firepinto - 10/27/14
  pinMode(LOCKLED, OUTPUT);                                      //firepinto - 10/27/14
  pinMode(SCANLED, OUTPUT);                                      //firepinto - 10/27/14
  pinMode(PEAKLED, OUTPUT);                                      //firepinto - 10/27/14
  pinMode(PLUS, INPUT);                                          //firepinto - 10/27/14
  pinMode(MINUS, INPUT);                                         //firepinto - 10/27/14
  pinMode(SELECTBTN,  INPUT);

//  pinMode(GATELED, OUTPUT);                                    //unused as of ver. 0.2.10a
  Timer1.initialize(1000000);
}

void loop()
{   
vmax = 0;                                                        //comment if you want to keep the best frequency of all scans
intval = 0;                                                      //comment if you want to see the frequency found interval in all scans
noTone(TONEOUT);                                                 // used to have LOCKLED pin
digitalWrite(LOCKLED, LOW);
Timer1.stop();
digitalWrite(GATEOUT, LOW);
//digitalWrite(GATELED, LOW);                                    //unused as of ver. 0.2.10a
lcd.clear();
lcd.print("   SCANNING FROM:   ");
digitalWrite(SCANLED, HIGH);
lcd.setCursor(0,1);
lcd.print("        TO       Hz");
lcd.setCursor(0,2);
lcd.print("SN=      Hz");
lcd.setCursor(12,2);
lcd.print("DL=");
lcd.print(dscan);
lcd.setCursor(0,3);
lcd.print("T1=      Hz");
lcd.setCursor(12,3);
lcd.print("CT=");
hz = freqmin;
//for (hz=500; hz<=1000; hz=hz+1)                                 //start from 500hz to 18khz to oscillate the circuit
 do
   {
  hz+=1;
  tone(TONEOUT,hz);                                               //will send a tone at first
  delay(1);                                                       //wait for a millisec
 
  volt = analogRead(PICKUP);                                      //then read the voltage
  if (volt > 818)                                                 //If pick-up coil voltage is greater than 4 volts
    {
    digitalWrite(PEAKLED, HIGH);                                  //turn on peak LED
    }
     else
    {
    digitalWrite(PEAKLED, LOW);                                   //turn off peak LED
    }
  if (vmax < volt)                                                //if there is a resonant point voltage should have the highest value on this frequency
  {
    vmax = volt;                                                  //store as the best voltage
    freq = hz;                                                    //remember that frequency
    intval = intval++;                                            //times found a nice frequency interval, is showing during scan on the left of the lcd
    lcd.setCursor(15,3);
    lcd.print(intval);
    lcd.setCursor(3,2);
    lcd.print("     ");
    lcd.setCursor(3,3);
    lcd.print(freq);
  }
  lcd.setCursor(3,2);
  lcd.print(hz);
  lcd.setCursor(2,1);
  lcd.print(freqmin);
  lcd.setCursor(11,1);
  lcd.print(freqmax);
   if (hz == freqmax)
     {
      stpscna=2;
     }
    else
   {
   if (digitalRead(SELECTBTN) == HIGH)
     {
     stpscna=3;
     stpscnb=3;
     }
   }
  delay(dscan);
   }while (stpscna < 1);

 //for (hz=1000; hz>=500; hz=hz-1)                                //do the same for a descent scan
  lcd.setCursor(11,1);                                            //Clears text fields for frequency scan range downward scan
  lcd.print("     ");
  lcd.setCursor(2,1);
  lcd.print("     ");
 do
   {
   hz-=1;
 // lcd.setCursor(5,1);
  // lcd.print("     ");
  // lcd.print(hz);
      tone(TONEOUT,hz);   
    delay(1);

    volt = analogRead(PICKUP);
    if (volt > 818)                                               // *Added by firepinto 10/26/14
    {
    digitalWrite(PEAKLED, HIGH);
    }
     else
    {
    digitalWrite(PEAKLED, LOW);
    }
    if (vmax < volt)
    {
      vmax = volt;
      freq = hz;
      adjfreq = freq;
      intval = intval++  ;
      lcd.setCursor(15,3);
      lcd.print(intval);
      lcd.setCursor(3,2); 
      lcd.print("     ");
      lcd.setCursor(3,3);
      lcd.print(freq);
    }
     if (hz < 10000)
    {
      lcd.setCursor(5,2);
      lcd.print("   ");
    }
  lcd.setCursor(3,2);
  lcd.print(hz);
  lcd.setCursor(2,1);
  lcd.print(freqmax);
  lcd.setCursor(11,1);
  lcd.print(freqmin);

   if (hz == freqmin)
     {
      stpscnb=2;
     }
    else
   {
   if (digitalRead(SELECTBTN) == HIGH)
     {
     stpscnb=3;
     }
   }

  delay(dscan);
   }while (stpscnb < 1);
  stpscna = 0;
  stpscnb = 0;
  digitalWrite(SCANLED, LOW);
  tone(TONEOUT,freq);                                             //output the frequency found with higher voltage reading
  //tone(LOCKLED, (4));                                           //LOCKLED isn't on a PWM pin - firepinto 10/27/14
 /* lcd.clear();
  lcd.print("RESONANCE FOUND");                                   //Removed because it is redundant now - firepinto 11/1/14
  lcd.setCursor(4, 1);
  lcd.print("@");
  lcd.setCursor(6, 1);                                            //printing to LCD
  lcd.print(freq);
  lcd.setCursor(12, 1);
  lcd.print("Hz");
  delay(1500);                                                    //Changed from delay(2500); to delay(1500); - firepinto 10/26/14
  */
  lcd.clear();
  lcd.setCursor(2, 0);
  lcd.print("WAITING FOR");
  lcd.setCursor(0, 1);
  lcd.print("STABILIZATION...");
  delay(2500);                                                    //waiting for a stabilizing time for the circuit, comment to avoid *Changed from delay(5500); to delay(2500); - firepinto 10/26/14
  volt = analogRead(PICKUP);                                      //read again the voltage from the pickup coil
    if (volt > 818)                                               // *Added by firepinto 10/26/14
    {
    digitalWrite(PEAKLED, HIGH);
    }
     else
    {
    digitalWrite(PEAKLED, LOW);
    }
  if (volt > vmax-51)                                             //check if read voltage is less than 10% of the best voltage found
   {
   lcd.clear();                                                   //if not, scan will start again
   lcd.setCursor(3,0);
   lcd.print("FREQUENCY");
   lcd.setCursor(1,1);
   lcd.write(byte(0));
   lcd.setCursor(3,1);
   lcd.print("  LOCKED");
   //noTone(SCANLED);                                             //LOCKLED pin doesn't have PWM - firepinto 10/27/14
   digitalWrite(LOCKLED, HIGH);
 
   delay(1000);                                                   //Changed from delay(2000); to delay(1000); - firepinto 10/26/14
  }
 
                                             
  lcd.clear();
  lcd.setCursor(0,0);                                             //Move to digit 0 row 0
  lcd.print("T1=");                                               //Pulse frequency title "T1=" with units label "Hz"
  lcd.setCursor(9,0);                                             //Move to digit 9 row 0
  lcd.print("Hz");
  lcd.setCursor(13,0);                                            //Move to digit 13 row 0
  lcd.print("VT=");                                               //Pick-up coil voltage title "VT="
  lcd.setCursor(0,1);                                             //same idea continued below
  lcd.print("T3=");
  lcd.setCursor(9,1);                                             //Move to digit 9 row 1
  lcd.print("Hz");
  lcd.setCursor(13,1);
  lcd.print("DY=");
  lcd.setCursor(19,1);
  lcd.print("%");
  lcd.setCursor(0,2);
  lcd.print("LK=");
  lcd.setCursor(9,2);
  lcd.print("Hz");
  lcd.setCursor(13,2);
  lcd.print("DL=");
  lcd.setCursor(0,3);
  lcd.print("SR=");
  lcd.setCursor(8,3);
  lcd.print(">");
  lcd.setCursor(15,3);
  lcd.print("S");
  adjfreq = freq;                                                 //sets adjustable frequency equal to the locked frequency
  //========================================================================================================
  while (digitalRead(SCAN) == LOW)                                //until the scan button is pressed, do the following
  { 
  tone(TONEOUT,adjfreq);                                          //turns on pulse signal to pin 9 with adjustable frequency
  //gateread = analogRead(GATESET);                               //reads Gate frequency potentiometer and sets the variable
 // duty = analogRead(GATEDUTY);                                  //read the gating set value from pin A1
  scalerg = analogRead(SLRANGE);                                  //reads the scale for manual frequency adjustment buttons from the potentiometer and sets the variable
 // gatef = map (gateread, 0, 1023, 1, 120);                      //limit the gating frequency from 1 to 120 hz
  scale = map (scalerg, 0, 1023, 1, 1000);                        //limit the gating frequency from 1 to 120 hz ---fp
  //dutyP = map (duty, 0, 1023, 100, 0);                          //translate T(miliseconds) into f(Hz) for gating frequency
  duty = map (dutyP, 100, 0, 0, 1023);                            //trying this reversed since setting display direclty through pushbuttons
  Timer1.pwm(GATEOUT, duty, 1000000/gatef);                       //turns on Gating signal to pin 10
  volt = analogRead(PICKUP);                                      //read the voltage on the VIC           *Needed to uncomment this line for the pick up coil voltage to be read during gating - firepinto 10/25/14
  if (volt > 818)                                                 //If pickup coil voltage is over 4 volts at pin, light LED. *Added by firepinto 10/26/14
     {
     digitalWrite(PEAKLED, HIGH);                                 //Turn ON pick-up coil peak voltage LED
     }
   else
     {
     digitalWrite(PEAKLED, LOW);                                  //Turn OFF pick-up coil peak voltage LED
     } 
 //__________________________________________________________________________________________
 select = digitalRead(SELECTBTN);       
 if (select == HIGH)
    {
    delay(300); 
    if (menu < 6)
       {
       menu+=1;
       }
       else
       {
       menu=0;
       }
    }
//  lcd.setCursor(11,0); 
// lcd.print(menu);
 if (menu == 1)//-------BEGIN MASSIVE MENU IF STATEMENT--------------------------------------------------------------
    {  //---------------BEGIN T1 MENU CODE--------------------------------------------------------------------------- 
       lcd.setCursor(2,0);
       lcd.write(byte(1));
       plusstate = digitalRead(PLUS);                             //reads frequency plus push button and sets the variable to its value
       if (adjfreq < 24390)                                       //sets maximum frequency to 24390 through the manual "plus" push button
          {
          if (lastPstate != 1)                                    //if last state of plus button does not equal 1
             {
             if (plusstate == HIGH)                               //if plus button state is HIGH
                {
                adjfreq+=scale;                                   //Add scale frequency to adjustable frequency
                digitalWrite(SCANLED, HIGH);                      //Turn on Scan LED
                lastPstate = plusstate;                           //set plus button last state variable
                delay(100);                                       //100 millisecond delay for button debounce (there may be a better option than this)
                }
              else                                                //if not
               {
               digitalWrite(SCANLED, LOW);                        //Turn off Scan LED
               lastPstate = plusstate;                            //set plus button last state variable
               }
             }   
           else                                                   //if not
             {
             lastPstate = plusstate;                              //set plus button last state variable
             }
          }
          minusstate = digitalRead(MINUS);                        //reads frequency increase push button and sets the variable to its value
          if (adjfreq > scale)                                    //sets minimum frequency to the scale frequency through the manual "minus" push button
             {
             if (lastMstate != 1)                                 //if last state of minus button does not equal 1
                {
                if (minusstate == HIGH)                           //if minus button state is HIGH
                   {
                   adjfreq-=scale;                                //Subtract scale frequency from adjustable frequency
                   digitalWrite(SCANLED, HIGH);                   //Turn on Scan LED
                   lastMstate = minusstate;                       //set minus button last state variable
                   delay(100);                                    //100 millisecond delay for button debounce (there may be a better option than this)
                   }
                 else                                             //if not
                   {
                   digitalWrite(SCANLED, LOW);                    //Turn off Scan LED
                   lastMstate = minusstate;                       //set minus button last state variable
                   }
                }
              else                                                //if not
                {
                lastMstate = minusstate;                          //set minus button last state variable
                }
              }
    } //------------------END T1 MENU CODE------------------------------------------------------------

     //------------------BEGIN T3 MENU CODE----------------------------------------------------------
    if (menu == 2)
       {     
       lcd.setCursor(2,1);
       lcd.write(byte(1));
       lcd.setCursor(2,0);
       lcd.print("=");
       plusstate = digitalRead(PLUS);                             //reads plus push button and sets the variable to its value
       if (gatef < 120)                                           //sets maximum gate frequency to 120 through the manual "plus" push button
          {
          if (lastPstate != 1)                                    //if last state of plus button does not equal 1
             {
             if (plusstate == HIGH)                               //if plus button state is HIGH
                {
                gatef+=scale;                                     //Add scale frequency to adjustable frequency
                digitalWrite(SCANLED, HIGH);                      //Turn on Scan LED
                lastPstate = plusstate;                           //set plus button last state variable
                delay(100);                                       //100 millisecond delay for button debounce (there may be a better option than this)
                }
              else                                                //if not
                {
                digitalWrite(SCANLED, LOW);                       //Turn off Scan LED
                lastPstate = plusstate;                           //set plus button last state variable
                }
             }   
           else                                                   //if not
             {
             lastPstate = plusstate;                              //set plus button last state variable
             }
          }
          minusstate = digitalRead(MINUS);                        //reads frequency increase push button and sets the variable to its value
          if (gatef > scale)                                      //sets minimum frequency to the scale frequency through the manual "minus" push button
             {
             if (lastMstate != 1)                                 //if last state of minus button does not equal 1
                {
                if (minusstate == HIGH)                           //if minus button state is HIGH
                   {
                   gatef-=scale;                                  //Subtract scale from adjustable frequency
                   digitalWrite(SCANLED, HIGH);                   //Turn on Scan LED
                   lastMstate = minusstate;                       //set minus button last state variable
                   delay(100);                                    //100 millisecond delay for button debounce (there may be a better option than this)
                   }
                 else                                             //if not
                   {
                   digitalWrite(SCANLED, LOW);                    //Turn off Scan LED
                   lastMstate = minusstate;                       //set minus button last state variable
                   }
                 }
               else                                               //if not
                 {
                 lastMstate = minusstate;                         //set minus button last state variable
                 }
              }
       }//----------------------END T3 MENU CODE-------------------------------------------

        //------------------BEGIN DY MENU CODE----------------------------------------------------------
       if (menu == 3)
          {
          lcd.setCursor(15,1);
          lcd.write(byte(1));
          lcd.setCursor(2,1);
          lcd.print("=");
          plusstate = digitalRead(PLUS);                          //reads plus push button and sets the variable to its value
          if (dutyP < 100)                                        //sets maximum gate duty to 100% through the manual "plus" push button
             {
             if (lastPstate != 1)                                 //if last state of plus button does not equal 1
                {
                if (plusstate == HIGH)                            //if plus button state is HIGH
                   {
                   dutyP+=scale;                                  //Add scale frequency to adjustable frequency
                   digitalWrite(SCANLED, HIGH);                   //Turn on Scan LED
                   lastPstate = plusstate;                        //set plus button last state variable
                   delay(100);                                    //100 millisecond delay for button debounce (there may be a better option than this)
                   }
                 else                                             //if not
                   {
                   digitalWrite(SCANLED, LOW);                    //Turn off Scan LED
                   lastPstate = plusstate;                        //set plus button last state variable
                   }
                }   
              else                                                //if not
                {
                lastPstate = plusstate;                           //set plus button last state variable
                }
             }
             minusstate = digitalRead(MINUS);                     //reads frequency increase push button and sets the variable to its value
             if (dutyP > scale)                                   //sets minimum frequency to the scale frequency through the manual "minus" push button
                {
                if (lastMstate != 1)                              //if last state of minus button does not equal 1
                   {
                   if (minusstate == HIGH)                        //if minus button state is HIGH
                      {
                      dutyP-=scale;                               //Subtract scale from adjustable frequency
                      digitalWrite(SCANLED, HIGH);                //Turn on Scan LED
                      lastMstate = minusstate;                    //set minus button last state variable
                      delay(100);                                 //100 millisecond delay for button debounce (there may be a better option than this)
                      }
                    else                                          //if not
                      {
                      digitalWrite(SCANLED, LOW);                 //Turn off Scan LED
                      lastMstate = minusstate;                    //set minus button last state variable
                      }
                   }
                 else                                             //if not
                   {
                   lastMstate = minusstate;                       //set minus button last state variable
                   }
                }
           }
         //----------------------END DY MENU CODE-------------------------------------------

         //------------------BEGIN DL MENU CODE----------------------------------------------------------
        if (menu == 4)
           {
           lcd.setCursor(15,2);
           lcd.write(byte(1));
           lcd.setCursor(15,1);
           lcd.print("=");
           plusstate = digitalRead(PLUS);                         //reads plus push button and sets the variable to its value
           if (dscan < 1000)                                      //sets maximum delay for scan to 1000 milliseconds through the manual "plus" push button
              {
              if (lastPstate != 1)                                //if last state of plus button does not equal 1
                 {
                 if (plusstate == HIGH)                           //if plus button state is HIGH
                    {
                    dscan+=scale;                                 //Add scale to scan delay
                    digitalWrite(SCANLED, HIGH);                  //Turn on Scan LED
                    lastPstate = plusstate;                       //set plus button last state variable
                    delay(100);                                   //100 millisecond delay for button debounce (there may be a better option than this)
                    }
                  else                                            //if not
                    {
                    digitalWrite(SCANLED, LOW);                   //Turn off Scan LED
                    lastPstate = plusstate;                       //set plus button last state variable
                    }
                 }   
               else                                               //if not
                 {
                 lastPstate = plusstate;                          //set plus button last state variable
                 }
              }
              minusstate = digitalRead(MINUS);                    //reads frequency increase push button and sets the variable to its value
              if (dscan > scale)                                  //sets minimum frequency to the scale frequency through the manual "minus" push button
                 {
                 if (lastMstate != 1)                             //if last state of minus button does not equal 1
                    {
                    if (minusstate == HIGH)                       //if minus button state is HIGH
                       {
                       dscan-=scale;                              //Subtract scale from scan delay
                       digitalWrite(SCANLED, HIGH);               //Turn on Scan LED
                       lastMstate = minusstate;                   //set minus button last state variable
                       delay(100);                                //100 millisecond delay for button debounce (there may be a better option than this)
                       }
                     else                                         //if not
                       {
                       digitalWrite(SCANLED, LOW);                //Turn off Scan LED
                       lastMstate = minusstate;                   //set minus button last state variable
                       }
                    }
                  else                                            //if not
                    {
                    lastMstate = minusstate;                      //set minus button last state variable
                    }
                 }
            }
          //----------------------END DL MENU CODE-------------------------------------------

          //------------------BEGIN SR MAX MENU CODE----------------------------------------------------------
         if (menu == 5)
            {
            lcd.setCursor(2,3);
            lcd.write(byte(1));
            lcd.setCursor(15,2);
            lcd.print("=");
            plusstate = digitalRead(PLUS);                        //reads plus push button and sets the variable to its value
            if (freqmax < 24390)                                  //sets maximum delay for scan to 1000 milliseconds through the manual "plus" push button
               {
               if (lastPstate != 1)                               //if last state of plus button does not equal 1
                  {
                  if (plusstate == HIGH)                          //if plus button state is HIGH
                     {
                     freqmax+=scale;                              //Add scale to scan delay
                     digitalWrite(SCANLED, HIGH);                 //Turn on Scan LED
                     lastPstate = plusstate;                      //set plus button last state variable
                     delay(100);                                  //100 millisecond delay for button debounce (there may be a better option than this)
                     }
                   else                                           //if not
                     {
                     digitalWrite(SCANLED, LOW);                  //Turn off Scan LED
                     lastPstate = plusstate;                      //set plus button last state variable
                     }
                  }   
                else                                              //if not
                  {
                  lastPstate = plusstate;                         //set plus button last state variable
                  }
               }
               minusstate = digitalRead(MINUS);                   //reads frequency increase push button and sets the variable to its value
               if (freqmax > scale)                               //sets minimum frequency to the scale frequency through the manual "minus" push button
                  {
                  if (lastMstate != 1)                            //if last state of minus button does not equal 1
                     {
                     if (minusstate == HIGH)                      //if minus button state is HIGH
                        {
                        freqmax-=scale;                           //Subtract scale from scan delay
                        digitalWrite(SCANLED, HIGH);              //Turn on Scan LED
                        lastMstate = minusstate;                  //set minus button last state variable
                        delay(100);                               //100 millisecond delay for button debounce (there may be a better option than this)
                        }
                      else                                        //if not
                        {
                        digitalWrite(SCANLED, LOW);               //Turn off Scan LED
                        lastMstate = minusstate;                  //set minus button last state variable
                        }
                     }
                   else                                           //if not
                     {
                     lastMstate = minusstate;                     //set minus button last state variable
                     }
                  }
             }
           //----------------------END SR MAX MENU CODE-------------------------------------------

           //------------------BEGIN SR MIN MENU CODE----------------------------------------------------------
          if (menu == 6)
             {
             lcd.setCursor(8,3);
             lcd.write(byte(1));
             lcd.setCursor(2,3);
             lcd.print("=");
             plusstate = digitalRead(PLUS);                       //reads plus push button and sets the variable to its value
             if (freqmin < 24390)                                 //sets maximum delay for scan to 1000 milliseconds through the manual "plus" push button
                {
                if (lastPstate != 1)                              //if last state of plus button does not equal 1
                   {
                   if (plusstate == HIGH)                         //if plus button state is HIGH
                      {
                      freqmin+=scale;                             //Add scale to scan delay
                      digitalWrite(SCANLED, HIGH);                //Turn on Scan LED
                      lastPstate = plusstate;                     //set plus button last state variable
                      delay(100);                                 //100 millisecond delay for button debounce (there may be a better option than this)
                      }
                    else                                          //if not
                      {
                      digitalWrite(SCANLED, LOW);                 //Turn off Scan LED
                      lastPstate = plusstate;                     //set plus button last state variable
                      }
                   }   
                 else                                             //if not
                   {
                   lastPstate = plusstate;                        //set plus button last state variable
                   }
                }
                minusstate = digitalRead(MINUS);                  //reads frequency increase push button and sets the variable to its value
                if (freqmin > scale)                              //sets minimum frequency to the scale frequency through the manual "minus" push button
                   {
                   if (lastMstate != 1)                           //if last state of minus button does not equal 1
                      {
                      if (minusstate == HIGH)                     //if minus button state is HIGH
                         {
                         freqmin-=scale;                          //Subtract scale from scan delay
                         digitalWrite(SCANLED, HIGH);             //Turn on Scan LED
                         lastMstate = minusstate;                 //set minus button last state variable
                         delay(100);                              //100 millisecond delay for button debounce (there may be a better option than this)
                         }
                       else                                       //if not
                         {
                         digitalWrite(SCANLED, LOW);              //Turn off Scan LED
                         lastMstate = minusstate;                 //set minus button last state variable
                         }
                      }
                    else                                          //if not
                      {
                      lastMstate = minusstate;                    //set minus button last state variable
                      }
                   }
              }
            //----------------------END SR MIN MENU CODE-------------------------------------------
    if (menu == 0)
       {
       lcd.setCursor(8,3);
       lcd.print(">");
       }     
//___________________BEGIN HARD LIMITS CODE____________________________________________________________________________________
if (adjfreq < 31)                                                 //blocks the minus push button from going lower than 31 Hz
   {
   adjfreq = 31;
   }
if (adjfreq > 24390)                                              //blocks the plus push button from going higher than 24390 Hz
   {
   adjfreq = 24390;
   }
if (gatef < 1)                                                    //blocks the minus push button from going lower than 1 Hz
   {
   gatef = 1;
   }
if (gatef > 120)                                                  //blocks the plus push button from going higher than 120 Hz
   {
   gatef = 120;
   }
if (dutyP < 1)                                                    //blocks the minus push button from going lower than 1%
   {
   dutyP = 1;
   }
if (dutyP > 100)                                                  //blocks the plus push button from going higher than 100%
   {
   dutyP = 100;
   }
if (dscan < 0)                                                    //blocks the minus push button from going lower than 0 milliseconds
   {
   dscan = 0;
   }
if (dscan > 5000)                                                 //blocks the plus push button from going higher than 5000 milliseconds
   {
   dscan = 5000;
   }   
if (freqmax < 31)                                                 //blocks the minus push button from going lower than 31 Hz
   {
   freqmax = 31;
   }
if (freqmax > 24390)                                              //blocks the plus push button from going higher than 24390 Hz
   {
   freqmax = 24390;
   }
if (freqmin < 31)                                                 //blocks the minus push button from going lower than 31 Hz
   {
   freqmin = 31;
   }
if (freqmin > 24390)                                              //blocks the plus push button from going higher than 24390 Hz
   {
   freqmin = 24390;
   } 
//______________________________________________________________________________________________________     
double vdisp = volt*(5.0/1023.0);                                 //scale digital signal to analog 0.0 - 5.0 volts
   if (adjfreq == 0)                                              //resets adjustable frequency to locked frequency if it is zero
      {
      adjfreq = freq;
      }
   if (adjfreq != freq)                                           //if adjustable frequency does not equal locked frequency.
       {
       digitalWrite(LOCKLED, LOW);                                //then turn off Lock LED
       }
     else                                                         //if not
       {
       digitalWrite(LOCKLED, HIGH);                               //turn on Lock LED
       }
   if (istime(&itlcd,reflcd))                                     //Original ver. 0.2.10a code
      {                                                           //Reorganized LCD and relabeled titles to Stanley Meyer terminology (May want to print titles elsewhere so they don't need to continually refresh and slow down the program, if possible)
      lcd.setCursor(3,0);                                         //Move to digit 3 row 0
      lcd.print("     ");                                         //Overwrites with spaces to clear digits
      lcd.setCursor(3,0);                                         //Move to digit 3 row 0
      lcd.print(adjfreq);                                         //Adjustable frequency
      lcd.setCursor(16,0);                                        //Move to digit 16 row 0
      lcd.print("    ");                                          //Overwrites with spaces to clear digits
      lcd.setCursor(16,0);                                        //Move to digit 16 row 0
      lcd.print(vdisp);                                           //Pick-up coil voltage
      lcd.setCursor(3,1);
      lcd.print("   ");
      lcd.setCursor(3,1);
      lcd.print(gatef);
      lcd.setCursor(16,1);
      lcd.print("   ");
      lcd.setCursor(16,1);
      lcd.print(dutyP);
      lcd.setCursor(3,2);
      lcd.print("     ");
      lcd.setCursor(3,2);
      lcd.print(freq);
      lcd.setCursor(16,2);
      lcd.print("    ");
      lcd.setCursor(16,2);
      lcd.print(dscan);
      lcd.setCursor(3,3);
      lcd.print("     ");
      lcd.setCursor(3,3);             
      lcd.print(freqmax);
      lcd.setCursor(9,3);
      lcd.print("     ");
      lcd.setCursor(9,3);             
      lcd.print(freqmin);
      lcd.setCursor(16,3);
      lcd.print("    ");
      lcd.setCursor(16,3);
      lcd.print(scale);
      }
 if (volt < vmax-51)                                              //after frequency has been locked and gating is on, whenever the voltage drops over 10% of the last best voltage found
    {
    if (adjfreq == freq)                                          //Disables the auto scan feature commented above when the adjustable frequency is not equal to the locked frequency
       {
       break;                                                     //scan will accur again by itself
       }
    }
}//_________________END OF WHILE_________________________________________________________
}//__________________END OF VOID LOOP__________________________________________________
int istime(unsigned long *timemark, unsigned long timeinterval)   //Code below all original from ver. 0.2.10a
{
  unsigned long timecurrent;
  unsigned long timeelapsed;
  int result = false;
  timecurrent=millis();
 
  if (timecurrent<*timemark)
  {
    timeelapsed = (TIMECTL_MAXTICKS-*timemark)*timecurrent;
  }
  else
  {
    timeelapsed = timecurrent-*timemark;
  }
  if (timeelapsed>=timeinterval)
  {
    *timemark = timecurrent;
    result = true;
  }
  return(result);
}

Alberto

Re: Arduino VIC resonator
« Reply #83, on November 4th, 2014, 02:33 PM »
Congratulations, this is really a great update for the 0.2.10 scan-circuit,
so I`m gonna build this baby for myself.
Really cool that use of the watermolecule-symbol... :cool:
Good job, very thanks for posting.
Have you already mixed the scan and gating signal?
If you like, i could post how i did that.
 

firepinto

Re: Arduino VIC resonator
« Reply #84, on November 4th, 2014, 02:41 PM »
I haven't yet, the bread board is sitting out waiting for it though. lol I'm always off on an "idea tangent".  Yes please post how you did it, others can follow along with it too. :)

Alberto

Re: Arduino VIC resonator
« Reply #85, on November 5th, 2014, 01:53 PM »
Ok, here it is...
First you need a flipflop for the scanleds.
Red(scanning) sets the flipflop, green(system output)
resets the flipflop.
Then photo2,
While scanning the signal goes to the upperside of the 4093. (S1 + S3)
While signal output + gating the signal goes to the underside of the 4093.(S1 + S2)
This schematic works, but there`s one little bug...
It takes about one second or so before gatingsignal D10 is starting...
At that moment the output is 0., but that was no problem for the scan-circuit.

firepinto

Re: Arduino VIC resonator
« Reply #86, on November 5th, 2014, 04:26 PM »Last edited on November 5th, 2014, 04:35 PM
This is what I did to get it to work.  First flipped output 9 and 10, flipping 10 was most important so that the Gate signal was HIGH for the AND gate when gating was turned off.  Otherwise scanning signals would not come through.  Then I needed to flip the mixed signal one more time so that my pulse train had an off time rather than a DC voltage in between. 
There is probably an easier way to do it, but that is what I have to work with. lol

Nate

Alberto

Re: Arduino VIC resonator
« Reply #87, on November 5th, 2014, 07:19 PM »
Maybe that`s even a better solution, please put it in your next vid.
In the past i did some tests with opamps and 74LS ic`s,
but negative power was always a problem, and nothing worked out. :@
How did you manage that power of -5V?


firepinto

Re: Arduino VIC resonator
« Reply #88, on November 6th, 2014, 04:20 AM »
I probably should of labelled it GND instead of -5V, 0V would of made more sense too.  Hopefully I get some time to draw up the entire circuit in KiCAD soon.
Re: Arduino VIC resonator
« Reply #89, on November 8th, 2014, 04:55 PM »Last edited on November 8th, 2014, 05:20 PM
I replicated Stan's Pulse Indicator Circuit to see if it works any better than the voltage divider set up:


https://www.youtube.com/watch?v=ZGxcDtJ36AY#ws

Makes me think a lot differently for how the pick up coil works. :cool:

The original opamp was replaced with a RadioShack LM741CN

Don's sketches are attached below:

BhuvarLokaTera3

Re: Arduino VIC resonator
« Reply #90, on November 8th, 2014, 07:39 PM »Last edited on November 8th, 2014, 08:26 PM
Quote from firepinto on November 4th, 2014, 02:06 PM
Code: [Select]

/*
   VIC Resonator written by Zissis aka zchiotis on open-source-energy.org forum.
   Downloaded from open-source-energy.org/?topic=1097.0
   Version 0.2.10 beta changes made by firepinto
   Version 0.2.11 alpha changes made by firepinto 10/30/14
*/
.....


Can I suggest that you use the secant method to achieve a faster convergence on the resonant frequency of the cell...
   i.e. http://en.wikipedia.org/wiki/Secant_method

Now assuming that the response curve is of the 2nd order (i.e. Quadratic) over the scan frequency range, then it should effectively require significantly less iterations!

B.R.

david_d

Re: Arduino VIC resonator
« Reply #91, on November 13th, 2014, 07:41 AM »
Hello,

I'm getting the train already running, but trying to implement Firepinto Arduino Vic Generator.

I am not yet totally familiar with teh whole stuff, but thanks a lot for the good job.

I'll come back here if I have any issue. Btw is there any schematics of this current version 0.2.12 ?

Thanks a lot

david

firepinto

Re: Arduino VIC resonator
« Reply #92, on November 13th, 2014, 07:18 PM »
This what I have in my set up so far.  Sorry for the crude sketches (my drafting instructor would slap me), but I just don’t have the time to learn any new schematic software at the moment. :P  I hope I didn't miss anything.  I am working on moving away from the MOSFET that I used.  Probably will be using Transistors like Stan did.  My MOSFET doesn't have a very good trailing edge to the square waves.  I would build the Pulse Indicator Circuit rather than use a simple voltage divider on the pickup coil.  I think it provides important information to the oscilloscope. ;) 

I'm working on some different stuff.. we'll see what happens with it. :cool:

Nate

david_d

Re: Arduino VIC resonator
« Reply #93, on November 14th, 2014, 06:39 AM »
Thank you Nate !

david

firepinto

Re: Arduino VIC resonator
« Reply #94, on November 15th, 2014, 10:16 AM »
Here is a snap shot of the scope with my VIC coil all wired up with chokes using a 4005 diode.  This coil likes to resonate between 11k and 12k Hz.  The top trace is at the cell (electrostatic filter) and the bottom trace is the output of the Pulse Indicator Circuit.  Not a lot of voltage at the cell, when I measure at the diode there is about 300 volts.  I should get the correct diode me thinks. :P

Tarakan

Re: Arduino VIC resonator
« Reply #95, on December 29th, 2014, 10:45 AM »
I want to use Tesla transformers to test some Tesla's original claims.
Tesla transferoers operate at 10^4 to 10^7 Hz or hundreds of KHz to several MHz.
Arduino doesn't work at those speeds.

In the industry, such systems either use analog Phase Lock Loop (PLL) system with a phase detector (PHD), voltage-controlled oscillator (VCO). This is the old-school analog method.

A more modern method and a method that I will prefer is to use a Field Programmable Gate Array (FPGA). They are significantly cheaper than ADC signalprocessors for the same frequency and are widely used in the industry for the digital PLL.

I want a system that will not just let me resonate something but would let it decay to some ampletude. Than when ampletude is low enough, the system will add an impulse at the correct time to add to the oscillations. I want to be able to control all variables: the position of the pulse, the timing of the pulse, how many oscillations are skipped before next step is applied.

I have some background in programming but I cannot manufacture my own circuit boards or design my circuits for high frequency.

You are solving a very similar problem with this VIC resonator. It would be nice if we joined forces.

Thank you.

realtry

Re: Arduino VIC resonator
« Reply #96, on December 29th, 2014, 11:52 AM »Last edited on December 29th, 2014, 11:54 AM
@Tarakan,
I would be interested in building such system in FPGA, i got Altera Cyclone IV board, but haven't started any work on it. The later boards have Fractional PLL. But the one i got should be good enough to start i guess. Post your plans on how you want to do it. I might join your efforts.

Do you know of any FPGA system as open source, because there were people in Tesla coil circle trying to do this, but as closed source, we could get some inspiration, if we could find some thing from there.

Tarakan

Re: Arduino VIC resonator
« Reply #97, on December 29th, 2014, 12:16 PM »Last edited on December 29th, 2014, 07:34 PM
I don't have any plans. I am a college dropout that knows some Arduino-related C and very little C for the personal computer.

I can wind Tesla transformer resonators up to 1 meter length and up to 4" in diameter. The bigger the Tesla Secondary, the lower it's resonant frequency is.

I can help, donate money, buy parts for but I can't really help.

My plan is to use a primary that uses a stack of PCB-printed flat bifilar coils as a primary and a traditional Secondary.

I want to resonate the hell out of the secondary, considering that the secondary's self frequenyy drifts around.
I want to design a circuit that uses commands from FPGA to harvest reverse EMF at the right time.
Same way that the excitation impulse for the secondary will be applied. So we add energy into the secondary and also drain energy from the secondary. But the timing has to be right for both events to take place.

Just as in the gasoline engine with ignition angle.

This may be the answer to the mystery of Tesla Free energy.

There will be a separate post about this in
Open-Source Threads - POST ANYTHING RELATED!

because what I want is an off-topic for this specific forum thread.

I will try to outline my idea there the best I can so I will spend time writing and proofreading what exactly I want to do.

I advise not to continue the discussion in this thread in order not to be destractive to the current topic.
Thank you.
Re: Arduino VIC resonator
« Reply #98, on December 30th, 2014, 08:36 PM »
I do think that we need a universal open-source KHz-MHz self-frequency oscillator platform.

abadiya

Re: Arduino VIC resonator
« Reply #99, on January 16th, 2015, 06:34 PM »
Can any one post DDS ver. 0.3.7 alpha CODE?
Thank you.