#1 2016-12-23 15:23:22

whemming
Member
Registered: 2016-12-04
Posts: 28

My Fork of LibAPRS

All,

I created a new fork of LibAPRS for the Mega2560 and allow you to use any DAC pin.  Also added pin definitions for all other pins.  Using this mechod the pins do not need to be in order.  But you do need a port with 5 pins available.

You could for example use PA0-7

Port A has 7 pins defined in an 8 bit Binary each as a separate bit

pin7  pin6  pin5  pin4  pin3 pin2 pin1 pin0
  0      0     0      0     0     0     0    0

To select pins we use the _BV macro to select the bit we need.

_BV(0) = 00000001
_BV(1) = 00000010
_BV(2) = 00000100
_BV(3) = 00001000
_BV(4) = 00010000
_BV(5) = 00100000
_BV(6) = 01000000
_BV(7) = 10000000

#define DAC_PORT PORTA
#define DAC_DDR  DDRA
#define DAC_PINS (_BV(0)| _BV(2) | _BV(4) | _BV(6)) //in binary equals 01010101
#define PPT_PIN 1 equals 00000001


https://github.com/williamhemmingsen/LibAPRS


------------------------------------------------

To change DAC pins I added the following to device.h

#define DAC_PINS (_BV(4)| _BV(5) | _BV(6) | _BV(7))
#define PPT_PIN 3

Than change the following in ASFK.h

#define AFSK_DAC_INIT()        do { DAC_DDR |= (DAC_PINS | _BV(PPT_PIN)); } while (0)

Finally in ASFK.cpp

DAC_PORT = (AFSK_dac_isr(AFSK_modem) & DAC_PINS) | _BV(PPT_PIN);

Regards,

William

Offline

#2 2016-12-23 16:15:08

whemming
Member
Registered: 2016-12-04
Posts: 28

Re: My Fork of LibAPRS

Offline

#3 2016-12-31 14:06:27

whemming
Member
Registered: 2016-12-04
Posts: 28

Re: My Fork of LibAPRS

The changes to the DAC pins appeared to work at first, but after further examination with an oscope, the sine wave way wrong.  The library is doing a bitwise compare to the DAC pins in order to switch the pins.  The sine wave uses values from 128-255 (binary 10000000 - 111111111).  When using DAC pins 4-7, we get a port registrar of 11110000.

The following line in ASFK.cpp, is used to clear/set the DAC bits based on position/phase of the sine wave.

DAC_PORT = (AFSK_dac_isr(AFSK_modem) & 0xF0) | _BV(3);

So lets say we are at the 128 position of the sine wave, we get

DAC_PORT = (10000000) & 11110000) | _BV(00000100);

The output of this command

10000000 & 11110000 = 10000000 (turn on bit7, PIN 7) |  turn on 00001000 (Bit 3 PTT Port).

So lets see what happens when we change the pins

10000000 & 01010101 = 00000000 (turn on nothing) |  turn on 00001000 (Bit 3 PTT Port).

So you can see by using any pins other than 4-7 you totally disrupt the sine wave.  To fix this I did the following:

    if (hw_afsk_dac_isr) {
       //Sine wave is designed around bits 7,6,5,4
       //Here we move bits around to macth chosen ports in
       //Device.h
       uint8_t sinwave = AFSK_dac_isr(AFSK_modem);\\Read value of sinewave into variable
       uint8_t tempsin = 0;
       if (sinwave & 0b10000000){
        tempsin += DAC_PIND; \\If bit 7 of sinewave is set, set tempsin bit assigned to DAC_PIND
        }
       if (sinwave & 0b01000000){
        tempsin += DAC_PINC;\\If bit 6 of sinewave is set, set tempsin bit assigned to DAC_PINC
        }
       if (sinwave & 0b00100000){
        tempsin += DAC_PINB;\\If bit 5 of sinewave is set, set tempsin bit assigned to DAC_PINB
        }
       if (sinwave & 0b00010000){
        tempsin += DAC_PINA;\\If bit 4 of sinewave is set, set tempsin bit assigned to DAC_PINA
        }

    DAC_PORT = tempsin & DAC_PINS | _BV(PPT_PIN);

     } else {
         DAC_PORT = 128;

The above code allows you to use any pins of a port, in any order for DAC.  They still need to belong to the same port.  PTT must also belong to same port.  So you need 5 out of 7 free pins on a port.  The reason I did this to facilitate easier routing on some boards where the pins are not in order i.e. 2,4,6,8.  The mega for example digital pins 22-53 are staggered this way.

Hope this helps somebody!

William

Offline

Board footer

Powered by FluxBB