Announcement

Collapse
No announcement yet.

Arduino Nano PI Main Discussion

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 6666
    replied
    Marty see email re nano

    Leave a comment:


  • MartyJ1963
    replied
    Hiya George. Thanks for the info. I don't know what the problem is but now matter what driver I try it doesn't seem to work. The port shows up in Arduino IDE but when I try to program the Nano it fails. The Nano has the FT232r chip and I have nstalled the FR232r usb uart drivers. When I go into Tools for the settings I put :- Board>Arduino Nano. Processor>ATmega328P. Port>Com3. Programmer>ArduinoISP. It gives an error and doesn't program the code. If I change Processor to ATmega328P (Old Bootloader) it programs the Nano but doesn't work on my ANPI Detector pcb. When it's plugged into the ANPI I get +5v on TP4 but only -2.56v on TP3. I get the 50us wave etc on TP2. Baffled? I'm using windows 7 64 bit. Thanks, Marty.

    Leave a comment:


  • Qiaozhi
    replied
    Originally posted by MartyJ1963 View Post
    Hi Alec, Hope you're well! I already tried the drivers from FTDchip. No success. The first 2 Nano's I ordered had the ch340g chip installed on board. When I installed the Nano to the ANPI i could get +5V but not -5V. Then everything went wrong after that. The Nano died! I swapped out the LT1054 about 20 times then tried about the same amount of 7660's,,nothing. George offered to test the Nano for me and the NE5534's in case they're fake but I'm yet to get to town to post them to him. Really bad weather here at the moment. I'm just trying to install the drivers on another pc at the moment for the Nano's. Regards, Marty.
    It's probably something really simple, if only you could find the cause of the problem. I've not had any issues programming the ELEGOO NANO 3.0 boards that I have here using either Windows 10 or Linux Mint.

    Here are my settings:

    Windows 10 with Arduino IDE V1.8.13
    Tools > Board: > Arduino Nano
    Tools > Processor: > Atmega328P
    Tools > Port: > COM8

    Linux Mint 18.1 Cinnamon 3.2.7 with Arduino IDE V1.8.13
    Tools > Board: > Arduino Nano
    Tools > Processor: > Atmega328P
    Tools > Port: > /dev/tty/USB0

    In Windows 10 there were two USB ports shown in the list, so I just tried them in order to find out which one was connected to the Nano. The easiest way to test this is to select Tools > Get Board Info. Only one of the selections will return any data.

    Marty - Our friendly postie will take any letters or parcels when he comes to the door. You can buy postage online on the Post Office site, print off a label and attach it to a jiffy bag. If your postie is the same, it would save you a trip into town.

    Leave a comment:


  • MartyJ1963
    replied
    Hi Alec, Hope you're well! I already tried the drivers from FTDchip. No success. The first 2 Nano's I ordered had the ch340g chip installed on board. When I installed the Nano to the ANPI i could get +5V but not -5V. Then everything went wrong after that. The Nano died! I swapped out the LT1054 about 20 times then tried about the same amount of 7660's,,nothing. George offered to test the Nano for me and the NE5534's in case they're fake but I'm yet to get to town to post them to him. Really bad weather here at the moment. I'm just trying to install the drivers on another pc at the moment for the Nano's. Regards, Marty.

    Leave a comment:


  • surfdetector
    replied
    Originally posted by MartyJ1963 View Post
    I couldn't zero the 5534 or get the -5v on the both ANPI's I built.
    Hi Marty,

    Leave a comment:


  • MartyJ1963
    replied
    @Gallico58, Thanks for the reply. I have tried everything with no success. The drivers I installed, multiple times, do not seem to work as the red light on the Nano continues to glow. I am at a loss what to try next. Thanks anyway for your help. Regards, Marty.

    Leave a comment:


  • gallico58
    replied
    Hi Marty, I had the same problems as you, sometimes with nano did not see the com port in windows xp, I made several attempts then I don't know how I managed it.
    if you can try linux.
    on the web I found this explanation but I have not tried

    "If you own an Arduino Nano 3.0 you may have connection problems, this manifests itself with problems so that the module is recognized by the PC once connected for example for loading a program.
    The problem is due to the fact that Gravitech designers in the first models of the module (now the problem should be solved) have not left free, this is not connected to ground, the PIN 26 (test) of the U2 Type FT232RL integration which serves as an interface between the USB port and the ATMega 368 processor.
    As reported on the device's datasheet, this pin must, for normal operations, be connected to GND. If you own an Arduino Nano 3.0 you may have connection problems, this manifests itself with problems so that the module is recognized by the PC once connected for example for loading a program.
    The problem is due to the fact that Gravitech designers in the first models of the module (now the problem should be solved) have not left free, this is not connected to ground, the PIN 26 (test) of the U2 Type FT232RL integration which serves as an interface between the USB port and the ATMega 368 processor.
    As reported on the device's datasheet, this pin must, for normal operations, be connected to GND."

    Leave a comment:


  • MartyJ1963
    replied
    Hi everyone. I'm having a real difficult time with my new Arduino Nano V.3 boards. The first 2 Nano's I ordered had the ch340g chip on board and I couldn't zero the 5534 or get the -5v on the both ANPI's I built. I received my 2 x Nano boards today that have the FT232R UART Chip on board and cannot get my pc to recognise them or install drivers for them. I have downloaded original drivers from FTI etc and other sites and still can't get the pc to recognise it or install it correctly. It's driving me absolutely daft! as I've been at this now for weeks! Can anyone offer any suggestions or alternative drivers or procedures etc please? Thanks, Marty.

    Leave a comment:


  • Qiaozhi
    replied
    Amazon have announced that paperback printing will begin launching in Australia on May 19, 2021.

    No longer will our Australian friends have to order books via the USA, or at inflated prices from third-party book sellers.

    Leave a comment:


  • gallico58
    replied
    Hi George, however it may be a subjective problem, it may be that my construction on a breadboard is not so perfect, I would leave everything as an original from a book that works well, maybe opening a dedicated post on modifications would be more appropriate, what do you think?
    however the audio and oscilloscope pulses in a certain position of the potentiometer you describe were really my problem, perhaps I had not explained myself well.
    but when I replaced the code with that of Teleno they practically disappeared ........ Mystery!

    Leave a comment:


  • Qiaozhi
    replied
    I first tested the original code in the ANPI, and there was a small amount of jitter on the main sample delay, probably less than 100ns.
    Then I tested Teleno's code and the sample delay was rock solid.

    However, there was no discernible difference in performance between the two versions as far as the audio response was concerned. I suspect this is because any small jitter is being integrated out in the following stages.

    There was one side-effect of adding hysteresis to the sample delay pot measurement though. I discovered that it was possible to adjust the pot to a position where it caused a repeating beep in the audio output, and the sample delay (on the scope) jumped around between two settings.

    The adjustment of the sample delay was also much smoother in the original version.

    Maybe a running average would be a better solution if you're concerned about the jitter.

    Leave a comment:


  • Qiaozhi
    replied
    Thanks Teleno and gallico58.

    I'll load the modified code tonight and compare the difference.
    Personally I'm really pleased with the way the Arduino Nano PI has turned out. It's a great platform for learning about the Arduino, and provides a lot of flexibility for further experiments.

    Leave a comment:


  • Teleno
    replied
    Originally posted by gallico58 View Post
    Thanks Teleno, it works well, more stable.
    ide was giving me error I had to insert, I hope in the right place the line "word Potread = 0;" this link for a video:

    https://drive.google.com/file/d/1cUw...ew?usp=sharing
    Good to hear.

    I made the error of inserting "word potValue" where I should have written "word potRead".

    Corrected program:
    Code:
    // Arduino Pulse Induction Metal Detector
    
    // Pin assignments
    byte txPin = 8;          // Assign pin 8 to TX output
    byte mainSamplePin = 9;  // Assign pin 9 to main sample pulse
    byte efeSamplePin = 10;  // Assign pin 10 to EFE sample pulse
    byte audioPin = 11;      // Assign pin 11 to audio chopper
    byte boostPin = 12;      // Assign pin 12 to boost switch
    byte delayPin = A0;      // Assign delay pot to A0
    
    
    // Program constants
    const float normalPower = 50E-6;       // Normal TX-on time (50us)
    const float boostPower = 100E-6;       // Boost TX-on time (100us)
    const float clockCycle = 62.5E-9;      // Time for one clock cycle (1/16MHz)
    const unsigned long maxCount = 65535;  // Value of 2^16 - 1
    const byte readDelayLimit = 100;       // Wait 100 TX periods (100ms) before reading delay pot
    const byte mosfetOn = HIGH;            // Mosfet turns on when transmitter input high
    const byte mosfetOff = LOW;            // Mosfet turns off when transmitter input low
    const byte syncDemodOn = LOW;          // Sample gate turns on when input high
    const byte syncDemodOff = HIGH;        // Sample gate turns off when input low
    
    
    // Detector timings
    float txOn = normalPower;        // TX-on time using normal power mode
    float defMainDelay = 10E-6;      // Default main sample delay (10us)
    float mainDelay = defMainDelay;  // Main sample pulse delay
    float mainSample = 50E-6;        // Main sample pulse width (50us)
    float efeDelay = 240E-6;         // EFE sample pulse delay (240us)
    float efeSample = mainSample;    // EFE sample pulse width (same as main sample)
    float txPeriod = 1E-3;           // TX period (1ms)
    
    
    // Timing offsets
    float txOnOffset = 3E-6;         // TX-on pulse offset (3us)
    float mainDelayOffset = 4.2E-6;  // Main delay pulse offset (4.2us)
    float mainSampleOffset = 3E-6;   // Main sample pulse offset (3us)
    float efeDelayOffset = 12E-6;    // EFE delay pulse offset (12us)
    float efeSampleOffset = 4E-6;    // EFE sample pulse offset (4us)
    float txPeriodOffset = 30E-6;    // TX period offset (30us)
    
    
    // Program variables
    float temp1, temp2, temp3, temp4, temp5, temp6;  // Intermediate calculation variables
    word txOnCount;                                  // TX pulse
    word mainDelayCount;                             // Main sample delay
    word mainSampleCount;                            // Main sample pulse
    word efeDelayCount;                              // EFE sample delay
    word efeSampleCount;                             // EFE sample pulse
    word txPeriodCount;                              // TX period
    word potRead;                                    // Voltage at the delay pot
    word delayVal = 0;                               // Delay pot value
    boolean readDelayPot = false;                    // Delay pot read (true or false)
    byte intState = 0;                               // Interrupt state machine
    byte readDelayCounter = 0;                       // Read delay pot counter
    
    
    void setup() {
      pinMode(txPin, OUTPUT);           // Set TX pin to output mode
      pinMode(mainSamplePin, OUTPUT);   // Set main sample pin to output mode
      pinMode(efeSamplePin, OUTPUT);    // Set EFE sample pin to output mode
      pinMode(boostPin, INPUT_PULLUP);  // Set Boost switch pin to input mode with pullup resistor
      calcTimerValues();                // Calculate all timer values
      noInterrupts();                   // Disable interrupts
      TCCR1A = 0;                       // Initialize Timer1 registers
      TCCR1B = 0;
      TIMSK0 = 0;                       // Clear Timer0 mask register to eliminate jitter
      TCNT1 = txOnCount;                // Load Timer1 with TX-on count
      TCCR1B |= (1 << CS10);            // No prescaling for Timer1
      TIMSK1 |= (1 << TOIE1);           // Enable Timer1 overflow interrupt
      interrupts();                     // Enable interrupts
      analogWrite(audioPin, 127);       // Set audioPin with 50% duty cycle PWM
    }
    
    
    void calcTimerValues() {
      if (digitalRead(boostPin) == HIGH) {                   // Get boost switch position
        txOn = normalPower;                                  // Set TX-on to 50us if HIGH
      } else {
        txOn = boostPower;                                   // Set TX-on to 100us if LOW
      }
      temp1 = (txOn - txOnOffset) / clockCycle;
      txOnCount = maxCount - int(temp1);                     // TX-on count for Timer1
      temp2 = (mainDelay - mainDelayOffset) / clockCycle;
      mainDelayCount = maxCount - int(temp2);                // Main sample delay count for Timer1
      temp3 = (mainSample - mainSampleOffset) / clockCycle;
      mainSampleCount = maxCount - int(temp3);               // Main sample pulse count for Timer1
      temp4 = (efeDelay - efeDelayOffset) / clockCycle;
      temp4 -= temp3 + temp2;
      efeDelayCount = maxCount - int(temp4);                 // EFE sample delay count for Timer1
      temp5 = (efeSample - efeSampleOffset) / clockCycle;
      efeSampleCount = maxCount - int(temp5);                // EFE sample pulse count for Timer 1
      temp6 = (txPeriod - txPeriodOffset) / clockCycle;
      temp6 -= temp1 + temp2 + temp3 + temp4 + temp5;
      txPeriodCount = maxCount - int(temp6);                 // TX period count for Timer1
    }
    
    
    ISR(TIMER1_OVF_vect) {
      switch (intState) {
        case 0:
          TCNT1 = txOnCount;                           // Load Timer1 with TX-ON count
          digitalWrite(txPin, mosfetOn);               // Turn on Mosfet
          intState = 1;
          break;
        case 1:
          TCNT1 = mainDelayCount;                      // Load Timer1 with main sample delay count
          digitalWrite(txPin, mosfetOff);              // Turn off Mosfet
          intState = 2;
          break;
        case 2:
          TCNT1 = mainSampleCount;                     // Load Timer1 with main sample pulse count
          digitalWrite(mainSamplePin, syncDemodOn);    // Turn on main sample gate
          intState = 3;
          break;
        case 3:
          TCNT1 = efeDelayCount;                       // Load Timer1 with EFE sample delay count
          digitalWrite(mainSamplePin, syncDemodOff);   // Turn off main sample gate
          if (readDelayPot == false) {                 // Check if read delay pot flag is false
            readDelayCounter++;                        // Increment read delay counter
            if (readDelayCounter >= readDelayLimit) {  // Check if read delay counter has reached limit
              readDelayPot = true;                     // Enable read of delay pot
              readDelayCounter = 0;                    // Clear read delay counter
            }
          }
          intState = 4;
          break;
        case 4:
          TCNT1 = efeSampleCount;                      // Load Timer1 with EFE sample pulse count
          digitalWrite(efeSamplePin, syncDemodOn);     // Turn on EFE sample gate
          intState = 5;
          break;
        case 5:
          TCNT1 = txPeriodCount;                       // Load Timer1 with TX period count
          digitalWrite(efeSamplePin, syncDemodOff);    // Turn off EFE sample gate
          intState = 0;
          break;
        default:
          intState = 0;
          break;
      }
    }
    
    
    void loop() {
      if (readDelayPot == true) {
        potRead = analogRead(delayPin);                        // Read the delay pot
        /* update delayVal with hysteresis to avoid ADC and pot jitter */                       
        if (potRead > (delayVal + 16)) delayVal = potRead - 16;
        else if (potRead < (delayVal  - 16)) delayVal = potRead + 16;
        mainDelay = defMainDelay + delayVal * clockCycle;      // Offset main sample delay
        calcTimerValues();                                     // Calculate new timer values
        readDelayPot = false;                                  // Set read delay pot flag to false
      }
    }

    Leave a comment:


  • gallico58
    replied
    Thanks Teleno, it works well, more stable.
    ide was giving me error I had to insert, I hope in the right place the line "word Potread = 0;" this link for a video:



    // Arduino Pulse Induction Metal Detector


    // Pin assignments
    byte txPin = 8; // Assign pin 8 to TX output
    byte mainSamplePin = 9; // Assign pin 9 to main sample pulse
    byte efeSamplePin = 10; // Assign pin 10 to EFE sample pulse
    byte audioPin = 11; // Assign pin 11 to audio chopper
    byte boostPin = 12; // Assign pin 12 to boost switch
    byte delayPin = A0; // Assign delay pot to A0




    // Program constants
    const float normalPower = 50E-6; // Normal TX-on time (50us)
    const float boostPower = 100E-6; // Boost TX-on time (100us)
    const float clockCycle = 62.5E-9; // Time for one clock cycle (1/16MHz)
    const unsigned long maxCount = 65535; // Value of 2^16 - 1
    const byte readDelayLimit = 100; // Wait 100 TX periods (100ms) before reading delay pot
    const byte mosfetOn = HIGH; // Mosfet turns on when transmitter input high
    const byte mosfetOff = LOW; // Mosfet turns off when transmitter input low
    const byte syncDemodOn = LOW; // Sample gate turns on when input high
    const byte syncDemodOff = HIGH; // Sample gate turns off when input low




    // Detector timings
    float txOn = normalPower; // TX-on time using normal power mode
    float defMainDelay = 10E-6; // Default main sample delay (10us)
    float mainDelay = defMainDelay; // Main sample pulse delay
    float mainSample = 50E-6; // Main sample pulse width (50us)
    float efeDelay = 240E-6; // EFE sample pulse delay (240us)
    float efeSample = mainSample; // EFE sample pulse width (same as main sample)
    float txPeriod = 1E-3; // TX period (1ms)




    // Timing offsets
    float txOnOffset = 3E-6; // TX-on pulse offset (3us)
    float mainDelayOffset = 4.2E-6; // Main delay pulse offset (4.2us)
    float mainSampleOffset = 3E-6; // Main sample pulse offset (3us)
    float efeDelayOffset = 12E-6; // EFE delay pulse offset (12us)
    float efeSampleOffset = 4E-6; // EFE sample pulse offset (4us)
    float txPeriodOffset = 30E-6; // TX period offset (30us)




    // Program variables
    float temp1, temp2, temp3, temp4, temp5, temp6; // Intermediate calculation variables
    word txOnCount; // TX pulse
    word mainDelayCount; // Main sample delay
    word mainSampleCount; // Main sample pulse
    word efeDelayCount; // EFE sample delay
    word efeSampleCount; // EFE sample pulse
    word txPeriodCount; // TX period
    word potRead = 0;
    word potValue; // Voltage at the delay pot
    word delayVal = 0; // Delay pot value
    boolean readDelayPot = false; // Delay pot read (true or false)
    byte intState = 0; // Interrupt state machine
    byte readDelayCounter = 0; // Read delay pot counter




    void setup() {
    pinMode(txPin, OUTPUT); // Set TX pin to output mode
    pinMode(mainSamplePin, OUTPUT); // Set main sample pin to output mode
    pinMode(efeSamplePin, OUTPUT); // Set EFE sample pin to output mode
    pinMode(boostPin, INPUT_PULLUP); // Set Boost switch pin to input mode with pullup resistor
    calcTimerValues(); // Calculate all timer values
    noInterrupts(); // Disable interrupts
    TCCR1A = 0; // Initialize Timer1 registers
    TCCR1B = 0;
    TIMSK0 = 0; // Clear Timer0 mask register to eliminate jitter
    TCNT1 = txOnCount; // Load Timer1 with TX-on count
    TCCR1B |= (1 << CS10); // No prescaling for Timer1
    TIMSK1 |= (1 << TOIE1); // Enable Timer1 overflow interrupt
    interrupts(); // Enable interrupts
    analogWrite(audioPin, 127); // Set audioPin with 50% duty cycle PWM
    }




    void calcTimerValues() {
    if (digitalRead(boostPin) == HIGH) { // Get boost switch position
    txOn = normalPower; // Set TX-on to 50us if HIGH
    } else {
    txOn = boostPower; // Set TX-on to 100us if LOW
    }
    temp1 = (txOn - txOnOffset) / clockCycle;
    txOnCount = maxCount - int(temp1); // TX-on count for Timer1
    temp2 = (mainDelay - mainDelayOffset) / clockCycle;
    mainDelayCount = maxCount - int(temp2); // Main sample delay count for Timer1
    temp3 = (mainSample - mainSampleOffset) / clockCycle;
    mainSampleCount = maxCount - int(temp3); // Main sample pulse count for Timer1
    temp4 = (efeDelay - efeDelayOffset) / clockCycle;
    temp4 -= temp3 + temp2;
    efeDelayCount = maxCount - int(temp4); // EFE sample delay count for Timer1
    temp5 = (efeSample - efeSampleOffset) / clockCycle;
    efeSampleCount = maxCount - int(temp5); // EFE sample pulse count for Timer 1
    temp6 = (txPeriod - txPeriodOffset) / clockCycle;
    temp6 -= temp1 + temp2 + temp3 + temp4 + temp5;
    txPeriodCount = maxCount - int(temp6); // TX period count for Timer1
    }




    ISR(TIMER1_OVF_vect) {
    switch (intState) {
    case 0:
    TCNT1 = txOnCount; // Load Timer1 with TX-ON count
    digitalWrite(txPin, mosfetOn); // Turn on Mosfet
    intState = 1;
    break;
    case 1:
    TCNT1 = mainDelayCount; // Load Timer1 with main sample delay count
    digitalWrite(txPin, mosfetOff); // Turn off Mosfet
    intState = 2;
    break;
    case 2:
    TCNT1 = mainSampleCount; // Load Timer1 with main sample pulse count
    digitalWrite(mainSamplePin, syncDemodOn); // Turn on main sample gate
    intState = 3;
    break;
    case 3:
    TCNT1 = efeDelayCount; // Load Timer1 with EFE sample delay count
    digitalWrite(mainSamplePin, syncDemodOff); // Turn off main sample gate
    if (readDelayPot == false) { // Check if read delay pot flag is false
    readDelayCounter++; // Increment read delay counter
    if (readDelayCounter >= readDelayLimit) { // Check if read delay counter has reached limit
    readDelayPot = true; // Enable read of delay pot
    readDelayCounter = 0; // Clear read delay counter
    }
    }
    intState = 4;
    break;
    case 4:
    TCNT1 = efeSampleCount; // Load Timer1 with EFE sample pulse count
    digitalWrite(efeSamplePin, syncDemodOn); // Turn on EFE sample gate
    intState = 5;
    break;
    case 5:
    TCNT1 = txPeriodCount; // Load Timer1 with TX period count
    digitalWrite(efeSamplePin, syncDemodOff); // Turn off EFE sample gate
    intState = 0;
    break;
    default:
    intState = 0;
    break;
    }
    }




    void loop() {
    if (readDelayPot == true) {
    potRead = analogRead(delayPin); // Read the delay pot
    if (potRead > (delayVal + 16)) delayVal = potRead - 16;
    else if (potRead < (delayVal - 16)) delayVal = potRead + 16;
    mainDelay = defMainDelay + delayVal * clockCycle; // Offset main sample delay
    calcTimerValues(); // Calculate new timer values
    readDelayPot = false; // Set read delay pot flag to false
    }
    }

    Leave a comment:


  • Teleno
    replied
    Originally posted by Qiaozhi View Post
    Teleno is most likely correct that the Delay pot is the cause, although I'm a bit surprised that any audio jitter would be that noticeable for a change as small as 62.5ns.
    The maximum accuracy of the ADC is 3.5 bits (page 265, table 28.9 of the Atmega328P datasheet). Thus the ADC value can vary by 1.1% from one measurement to the next for the same pot position.
    2^3.5 is 11.3, so a jitter of 11.3 x 62.5ns = 706 ns can be expected from this alone.
    Then the potentiometer's own jitter on top of it, a well known phenomenon: Potentiometer jitter
    The interrupt jitter is about 1 cycle because most of the instructions take 1 or 2 cycles, very rarely 3 or more, and their execution is completed before serving the interrupt.
    Originally posted by gallico58 View Post
    Thanks Teleno and Qiaozhi, I will try to change the code, I am quite good with the soldering iron but I am denied in software programming.
    sorry also my bad english, i use the translator!
    Try the hysteresis code first. The new .ino file would be like this:

    Code:
    // Arduino Pulse Induction Metal Detector
    
    // Pin assignments
    byte txPin = 8;          // Assign pin 8 to TX output
    byte mainSamplePin = 9;  // Assign pin 9 to main sample pulse
    byte efeSamplePin = 10;  // Assign pin 10 to EFE sample pulse
    byte audioPin = 11;      // Assign pin 11 to audio chopper
    byte boostPin = 12;      // Assign pin 12 to boost switch
    byte delayPin = A0;      // Assign delay pot to A0
    
    
    // Program constants
    const float normalPower = 50E-6;       // Normal TX-on time (50us)
    const float boostPower = 100E-6;       // Boost TX-on time (100us)
    const float clockCycle = 62.5E-9;      // Time for one clock cycle (1/16MHz)
    const unsigned long maxCount = 65535;  // Value of 2^16 - 1
    const byte readDelayLimit = 100;       // Wait 100 TX periods (100ms) before reading delay pot
    const byte mosfetOn = HIGH;            // Mosfet turns on when transmitter input high
    const byte mosfetOff = LOW;            // Mosfet turns off when transmitter input low
    const byte syncDemodOn = LOW;          // Sample gate turns on when input high
    const byte syncDemodOff = HIGH;        // Sample gate turns off when input low
    
    
    // Detector timings
    float txOn = normalPower;        // TX-on time using normal power mode
    float defMainDelay = 10E-6;      // Default main sample delay (10us)
    float mainDelay = defMainDelay;  // Main sample pulse delay
    float mainSample = 50E-6;        // Main sample pulse width (50us)
    float efeDelay = 240E-6;         // EFE sample pulse delay (240us)
    float efeSample = mainSample;    // EFE sample pulse width (same as main sample)
    float txPeriod = 1E-3;           // TX period (1ms)
    
    
    // Timing offsets
    float txOnOffset = 3E-6;         // TX-on pulse offset (3us)
    float mainDelayOffset = 4.2E-6;  // Main delay pulse offset (4.2us)
    float mainSampleOffset = 3E-6;   // Main sample pulse offset (3us)
    float efeDelayOffset = 12E-6;    // EFE delay pulse offset (12us)
    float efeSampleOffset = 4E-6;    // EFE sample pulse offset (4us)
    float txPeriodOffset = 30E-6;    // TX period offset (30us)
    
    
    // Program variables
    float temp1, temp2, temp3, temp4, temp5, temp6;  // Intermediate calculation variables
    word txOnCount;                                  // TX pulse
    word mainDelayCount;                             // Main sample delay
    word mainSampleCount;                            // Main sample pulse
    word efeDelayCount;                              // EFE sample delay
    word efeSampleCount;                             // EFE sample pulse
    word txPeriodCount;                              // TX period
    word potValue;                                   // Voltage at the delay pot
    word delayVal = 0;                               // Delay pot value
    boolean readDelayPot = false;                    // Delay pot read (true or false)
    byte intState = 0;                               // Interrupt state machine
    byte readDelayCounter = 0;                       // Read delay pot counter
    
    
    void setup() {
      pinMode(txPin, OUTPUT);           // Set TX pin to output mode
      pinMode(mainSamplePin, OUTPUT);   // Set main sample pin to output mode
      pinMode(efeSamplePin, OUTPUT);    // Set EFE sample pin to output mode
      pinMode(boostPin, INPUT_PULLUP);  // Set Boost switch pin to input mode with pullup resistor
      calcTimerValues();                // Calculate all timer values
      noInterrupts();                   // Disable interrupts
      TCCR1A = 0;                       // Initialize Timer1 registers
      TCCR1B = 0;
      TIMSK0 = 0;                       // Clear Timer0 mask register to eliminate jitter
      TCNT1 = txOnCount;                // Load Timer1 with TX-on count
      TCCR1B |= (1 << CS10);            // No prescaling for Timer1
      TIMSK1 |= (1 << TOIE1);           // Enable Timer1 overflow interrupt
      interrupts();                     // Enable interrupts
      analogWrite(audioPin, 127);       // Set audioPin with 50% duty cycle PWM
    }
    
    
    void calcTimerValues() {
      if (digitalRead(boostPin) == HIGH) {                   // Get boost switch position
        txOn = normalPower;                                  // Set TX-on to 50us if HIGH
      } else {
        txOn = boostPower;                                   // Set TX-on to 100us if LOW
      }
      temp1 = (txOn - txOnOffset) / clockCycle;
      txOnCount = maxCount - int(temp1);                     // TX-on count for Timer1
      temp2 = (mainDelay - mainDelayOffset) / clockCycle;
      mainDelayCount = maxCount - int(temp2);                // Main sample delay count for Timer1
      temp3 = (mainSample - mainSampleOffset) / clockCycle;
      mainSampleCount = maxCount - int(temp3);               // Main sample pulse count for Timer1
      temp4 = (efeDelay - efeDelayOffset) / clockCycle;
      temp4 -= temp3 + temp2;
      efeDelayCount = maxCount - int(temp4);                 // EFE sample delay count for Timer1
      temp5 = (efeSample - efeSampleOffset) / clockCycle;
      efeSampleCount = maxCount - int(temp5);                // EFE sample pulse count for Timer 1
      temp6 = (txPeriod - txPeriodOffset) / clockCycle;
      temp6 -= temp1 + temp2 + temp3 + temp4 + temp5;
      txPeriodCount = maxCount - int(temp6);                 // TX period count for Timer1
    }
    
    
    ISR(TIMER1_OVF_vect) {
      switch (intState) {
        case 0:
          TCNT1 = txOnCount;                           // Load Timer1 with TX-ON count
          digitalWrite(txPin, mosfetOn);               // Turn on Mosfet
          intState = 1;
          break;
        case 1:
          TCNT1 = mainDelayCount;                      // Load Timer1 with main sample delay count
          digitalWrite(txPin, mosfetOff);              // Turn off Mosfet
          intState = 2;
          break;
        case 2:
          TCNT1 = mainSampleCount;                     // Load Timer1 with main sample pulse count
          digitalWrite(mainSamplePin, syncDemodOn);    // Turn on main sample gate
          intState = 3;
          break;
        case 3:
          TCNT1 = efeDelayCount;                       // Load Timer1 with EFE sample delay count
          digitalWrite(mainSamplePin, syncDemodOff);   // Turn off main sample gate
          if (readDelayPot == false) {                 // Check if read delay pot flag is false
            readDelayCounter++;                        // Increment read delay counter
            if (readDelayCounter >= readDelayLimit) {  // Check if read delay counter has reached limit
              readDelayPot = true;                     // Enable read of delay pot
              readDelayCounter = 0;                    // Clear read delay counter
            }
          }
          intState = 4;
          break;
        case 4:
          TCNT1 = efeSampleCount;                      // Load Timer1 with EFE sample pulse count
          digitalWrite(efeSamplePin, syncDemodOn);     // Turn on EFE sample gate
          intState = 5;
          break;
        case 5:
          TCNT1 = txPeriodCount;                       // Load Timer1 with TX period count
          digitalWrite(efeSamplePin, syncDemodOff);    // Turn off EFE sample gate
          intState = 0;
          break;
        default:
          intState = 0;
          break;
      }
    }
    
    
    void loop() {
      if (readDelayPot == true) {
        potRead = analogRead(delayPin);                   // Read the delay pot
        if (potRead > (delayVal + 16)) delayVal = potRead - 16;
        else if (potRead < (delayVal  - 16)) delayVal = potRead + 16;
        mainDelay = defMainDelay + delayVal * clockCycle;  // Offset main sample delay
        calcTimerValues();                                 // Calculate new timer values
        readDelayPot = false;                              // Set read delay pot flag to false
      }
    }

    Leave a comment:

Working...
X