Trust me I’m an engineer

18-aug-2016: Checked the batteries, compass and IMU calibrated, and it runs again. On 24-aug and 25-aug I had two more flights, one on the beach and one on the moor. The flight on 25-aug-2016 had two hard landings because of battery capacity problems, either the low voltage level is too high, either I should charge the batteries differently, namely not at 1C but at a 1/2 or less at done prior to 25-aug-2016.

Rotary encoder on an Arduino

Attach a rotary encoder to an Arduino and make it count when you turn the knob. How does it work?

IMG_3119

The encoder has two lines, an A line on the left, a ground line in the middle, and a B line on the right. A and B output so-called Gray codes when you turn the knob, the Gray codes reveal the sense of rotation, the knob has 24 position in one turn, and with each click line A or B will change like a switch does.

I started to play around with existing Arduino code inspired by an article on circuits at home [link] and I added a few bells and whistles. There are some comments in the code, you will soon learn that there is a state transition table. My  explanation of this table goes in four handwritten sheets after the code.

#define ENC_A 14        // this is analog pin A0
#define ENC_B 15        // analog pin A1 on the arduino Uno
#define ENC_PORT PINC   // ENC_PORT gets all analog pins in one byte
#define TIMEOUT 2       // feel free to experiment around, 2 msec was ok for me
#define DEBUG 0         // 1 gives a bit more output
#define ROTATE 0        // counter from 0 to 255 rotates across boundary or not
#define CLOCKWISE       // undefine if you want a counterclockwise counter

unsigned long int timer = 0;
uint8_t encoder,prevencoder;

void setup() {
  pinMode(ENC_A, INPUT); digitalWrite(ENC_A, HIGH);  // it is A0
  pinMode(ENC_B, INPUT); digitalWrite(ENC_B, HIGH);  // it is A1
  Serial.begin (115200);
  Serial.println("Start");  
}

void loop() {
 static uint8_t counter = 0;      // output of the encoder
 int8_t tmpdata;
 if ((millis() - timer) > TIMEOUT) {
    tmpdata = read_encoder();
    if (DEBUG) {
      if (prevencoder != encoder) BinPrint( encoder );
      prevencoder = encoder;
    }
    if (tmpdata) {
      Serial.println(counter, DEC);
      if (ROTATE) {
        counter += tmpdata;
      } else {
        if ((counter < 255) && (tmpdata == +1)) counter += tmpdata;
        if (  (counter > 0) && (tmpdata == -1)) counter += tmpdata;
      }
    }
    timer = millis();
  }  
}

// returns change in encoder state (-1,0,1) 
int8_t read_encoder()
{
  // put the gray codes in four quadrants and start to count, I checked 
  // this in the following way
  //
  //   01 | 00
  //   -------
  //   11 | 10
  //
  // and the start counting the transitions across the boundaries
  //
  #ifdef CLOCKWISE
    // this is for clockwise turning
    static int8_t enc_states[] = {0,-1,+1,0,+1,0,0,-1,-1,0,0,+1,0,+1,-1,0};   
  #else
     // this is for counterclockwise turning
    static int8_t enc_states[] = {0,+1,-1,0,-1,0,0,+1,+1,0,0,-1,0,-1,+1,0};   
  #endif
  static uint8_t old_AB = 0;                // only does this once actually
  encoder = ENC_PORT;                       // I want to be able to debug
  old_AB <<= 2;                             // remember previous state
  old_AB |= ( encoder & 0x03 );             // form the state byte 
  return ( enc_states[( old_AB & 0x0f )]);  // &0x0f zeros out other bits
}

// shows the state of the encoder ports when we are debugging
void BinPrint( uint8_t copy ) {
  for (int i=0; i<8; i++) {
    if (copy & 0x01) {
      Serial.print("1");
    } else {
      Serial.print("0");
    }
    copy = copy >> 1;
  }
  Serial.println(" ");  
}

Here is the theory:

IMG_3115IMG_3116IMG_3117IMG_3118

Last update: 17-aug-2016

 

PI2NOS

De vraag was waar het getik op de repeater af en toe vandaan komt. Mijn SDR liet vandaag zien dat er af en toe spikes zijn waarbij de zender buiten de 12,5 kHz bandbreedte komt.

pi2nos_spike

Last update: 4-8-2016 13:31

Return loss antenna analyzer #hamradio

Rather than buying an antenna analyzer I have built one myself mostly from spare parts that I had in the mancave. In the end this is what it became:

IMG_3065

The measurement originates from a so-called return loss bridge, if there wouldn’t be any signal returning from the antenna into the transmitter, and, if the bridge was symmetric and if there are no internal losses then the output at B would null out. The signal at A is proportional to what we put in to the Wheatstone bride, and the ratio B/A*1000 is what I decided to call the reflection coefficient.

The oscillator is a si5351 left over from the WSPR beacon kit. It outputs a square wave and is able to generate signals up to 150 MHz. Hans Summers has on his website a library for the si3551, it goes via the I2C interface.  I decided to use it between 3 and 31 MHz in steps of 100 kHz. Voltages at A and B in the bridge are measured by passing the signal through a Schottky diode in series with a 100nF capacitor. The ADC’s of the atmel328p running the Arduino bootloader do the rest of the work. On the Arduino website you can find how to build the interface to the LCD and all of that, I don’t need to explain that here. The first setup was with a standard Arduino Uno to see if it worked at all, in the second revision I put everything on a experimenters PCB.

In the photo the antenna analyzer is running via the red FTDI board on the left of the LCD display. This is only necessary when you upload the code, in the end you can also remove the FTDI adapter and put it in standalone mode, in which case the interaction goes though the LCD display and both buttons. If you leave the FTDI board in then you can also retrieve the return loss spectra shown below.

For my end-fed antenna I found:

reflectionall

When you zoom in on the first resonance you see that the antenna is at resonance at 7.0 MHz, which is fine, the losses increase at the end part of the 40m band, so maybe the antenna is a bit too long, no worries, without a coaxial switch the autotuner is able to match it over the full range.

reflection7MHz

When we zoom in at 20m we get to see that the resonance occurs at the end of the 20m band. The 20m band is where this end-fed antenna works best in my opinion.

reflection14MHz

At 10m the performance of the end-fed antenna is slightly disappointing, actually, it is too long here. Beyond 28.7 MHz I really depends on the autotuner to be able to use it. What I also don’t understand is why the antenna shows a first resonance at 26.9 MHz and a second resonance at 27.9 MHz. Resonances are found by looking for local minima where the the reflection coefficient is less than 390 (thus 39.0%) which is a value based on what I thought was right for this set-up.

reflection28MHz

Below is the experiment on a breadboard.

IMG_3060

I did various experiments with dummy loads and resistors and decided not to try to convert the measured voltages into a SWR values at 50 Ohm. First of all, I did not have any 50 Ohm resistors in the shack, second, I suspect that the voltage measurements are biased and that the bridge is not fully symmetric. Also, the oscillator is outputting a square wave which assumes that the equivalent circuit of the antenna is that of a LCR in series terminating at ground. If we have a sine oscillator then we would not be affected by the returns of the signal at higher harmonics. This could be improved, for instance with the AD9832 DDS which does output a sine wave, that would be the easiest solution. Also, I could compare the reflection coefficient with a calibrated antenna analyzer.

Update 1: handheld case

The handheld version is ready, my solution is, buy polycarbonate and add two plates, this is the easiest temporal solution to carry around experiments.

IMG_3066
You need: 9v battery, switch, charge plug, polycarbonate,  standoffs and some patience

Update 2: Rotary dipoles analyzed

For fieldwork I have the rotary dipoles (see further on in this blog), and here are the reflection spectra measured today with the analyzer.

10m
This one should work fine, probably better than my wire antenna for 10 m
20m
This antenna also works fine, tested it once at the transmitter, the ATU of the FT-991 is able to match it.
40m
Here the resonance dip is so narrow that I doubt whether it will work, maybe you are better off with a wire antenna

Last update: 29-July-2016