Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions AVNA8main/AVNA1Config.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#define SCREEN_ROTATION 1
#define TOUCH_ROTATION 1

#define TOUCH_ROTATION 3
26 changes: 26 additions & 0 deletions AVNA8main/AVNA8commands.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1601,6 +1601,32 @@ void AnnotateCommand()
}
}

void StartupHelp()
{
Serial.print("\nTypical terminal use:\n\
\t MUST USE 'CARRIAGE RTN', SET BACK TO 'NEWLINE' WHEN DONE\n\n \
\tZ 50\t\timpedance measurement around 50 ohms, else Z 5000 ohms\n \
\tSWEEP\t\tsetup for sweep, else FREQ set a frequency\n\
\tCAL\t\tmust be run after change mode\n\
\tANNOTATE 0\tput in comma separated value for spreadsheet\n\
\tSERPAR 1 0\tseries RX outputted, parallellRX not\n\
\tRUN 1\t\trun 1 or # of times\n\
\n\
\tH or HELP \tmore commands\n\n");

Serial.print("for NANOVANA: either cd ~/Documents/GitHub/nanovna-saver or find the folder\n \
\tthen\n \
\tPython3 nanovna-saver.py\n \
\tor\n\
\tin OS window double click 'nanovna-saver.py' , and in Geany select the gears\n");
}

void HelpCommand()
{
StartupHelp();
SCmd.listCommands();
}

// ============== Commands to support the nanoVNA interface ===========

// calCommand, for "cal", is different than regular serial Cal command for "CAL"
Expand Down
41 changes: 11 additions & 30 deletions AVNA8main/AVNA8lcd.ino
Original file line number Diff line number Diff line change
Expand Up @@ -533,10 +533,10 @@ char* dumpScreenToSD(void) {
filename[5] = i / 100 + '0';
filename[6] = i / 10 + '0';
filename[7] = i % 10 + '0';
if (!SD.exists(filename))
if (!sd.exists(filename))
{
// Only open a new file if it does not exist
bmpFile = SD.open (filename, FILE_WRITE);
bmpFile.open (filename, O_WRONLY | O_CREAT);
break;
}
}
Expand Down Expand Up @@ -682,43 +682,24 @@ void exploreSDCard(void)
{
uint32_t volumesize;
// See if the card is present and can be initialized
if (!SD.begin(chipSelect))
// Initialize the SD card.
if (!sd.begin(SD_CONFIG))
{
Serial.println("uSD Card not present (or failed).");
return;
}
else
{
Serial.println("uSD Card present.");
SDCardAvailable=true;
// we'll use the initialization code from the utility libraries
// since we're just testing if the card is working!
if (!card.init(SPI_HALF_SPEED, chipSelect))
{
Serial.println("uSD card initialization failed.");
return;
}
// Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
if (!volume.init(card))
{
Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
return;
}
else
{
Serial.print("Partition found: FAT");
// print the type and size of the first FAT-type volume
Serial.println(volume.fatType(), DEC);
volumesize = volume.blocksPerCluster(); // clusters are collections of blocks
volumesize *= volume.clusterCount(); // we'll have a lot of clusters
Serial.print("Volume size (Mbytes): ");
Serial.println(volumesize/2048);

Serial.println("Files found on the card (name, date and size in bytes): ");
root.openRoot(volume);
// list all files in the card with date and size
root.ls(LS_R | LS_DATE | LS_SIZE);
Serial.println("");
}
printCardType();
dmpVol();
Serial.println("\nFiles found on the card (name, date and size in bytes): ");
// list all files in the card with date and size
sd.ls("/", LS_R);
Serial.println("");
}
}

Expand Down
107 changes: 86 additions & 21 deletions AVNA8main/AVNA8main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,9 @@
24 - Touch IRQ
*/

#include <stdio.h>
#include <math.h>
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
// #include <SD.h>
#include <SD_t3.h>
#include "SdFatConfig.h"
#include <SdFat.h>
#include <SerialFlash.h>
#include <EEPROM.h>
#include <XPT2046_Touchscreen.h>
Expand Down Expand Up @@ -282,6 +278,9 @@
#define VOLTS 0
#define POWER 1

#define SD_CONFIG SdioConfig(FIFO_SDIO)
#define error(s) sd.errorHalt(&Serial, F(s))

void tNothing(void); // Declarations are required to reference function
void tToInstrumentHome(void); // by pointer, just like C
void tToAVNAHome(void);
Expand Down Expand Up @@ -801,11 +800,11 @@ const int chipSelect = BUILTIN_SDCARD; // for Teensy 3.6
bool SDCardAvailable = false;
bool bmpScreenSDCardRequest = false;
bool hexScreenRequest = false;
File bmpFile;

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;
FsFile bmpFile;
SdFs sd;

unsigned int mmmm;
//===================================================================================
// To use STL Vector container, we need to trap some errors.
Expand Down Expand Up @@ -834,8 +833,11 @@ void setup()
panelLED(LSTART);
panelLED(LRED);
Serial.begin(9600); // 9600 is not used, it is always 12E6
while(!Serial && millis()<6000){ //wait for lesser of Serial or 6 seconds. Less sometimes misses version stuff
SysCall::yield();
}
delay(1000); //Wait for USB serial

// X.reserve(nn) immediately sets memory for nn X-elements.
Z.reserve(201);
Y.reserve(201);
Expand All @@ -862,9 +864,7 @@ void setup()
saveStateEEPROM(); // Initialize EEPROM, coming from init values for saveState

// SD Card, see what is available
exploreSDCard();
// Check if SD card is present and mark in SDCardAvailable
SDCardAvailable = card.init(SPI_HALF_SPEED, chipSelect);
exploreSDCard(); // Check if SD card is present and mark in SDCardAvailable

tft.begin();
tft.setRotation(SCREEN_ROTATION);
Expand Down Expand Up @@ -899,6 +899,8 @@ void setup()
HWSERIAL4.println((float)CURRENT_VERSION/100.0);
Serial.print("Voltage Check (expect 145 to 175): ");
Serial.println(analogRead(21));
StartupHelp(); //print some helpful hints about using terminal
mytest();

#if 0
// >>>>>>>>>>>>> SOLVED <<<<<<<<<<<<<<<<<<<<<<<<<
Expand Down Expand Up @@ -1006,6 +1008,9 @@ void setup()
SCmd.addCommand("ANNOTATE", AnnotateCommand);
SCmd.addCommand("VERBOSE", VerboseCommand);
SCmd.addCommand("CALSAVE", CalSaveCommand); // Added to save cal in EEPROM. 1 param. ver .70 Jan 2020
SCmd.addCommand("HELP", HelpCommand);
SCmd.addCommand("H", HelpCommand);
SCmd.addCommand("h", HelpCommand);
// A group of commands to allow the AVNA to mimic a nanoVNA to run nanoVNA-saver control program.
// No caps in command names, fortunately for "sweep" etc.
SCmd.addCommand("info", infoCommand);
Expand Down Expand Up @@ -1178,9 +1183,6 @@ void loop()
}
} // End if instrument==AVNA

// Check if SD card is present and mark in SDCardAvailable
SDCardAvailable = card.init(SPI_HALF_SPEED, chipSelect);

// TOUCH SCREEN
istouched = ts.touched();
if (istouched && (millis()-tms) > 250) // Set repeat rate and de-bounce or T_REPEAT
Expand Down Expand Up @@ -1860,7 +1862,7 @@ void setSample(uint16_t nS)
sampleRateExact = (float32_t)setI2SFreq(nS); // It returns a double
//factorFreq is global that corrects any call involving absolute frequency, like waveform generation.
factorFreq = FBASE / sampleRateExact;
#if DIAGNOSTICS
#if true //DIAGNOSTICS
Serial.print(" S Rate="); Serial.print(sampleRateExact); Serial.print( "ff=");
Serial.println(factorFreq);
#endif
Expand Down Expand Up @@ -2059,10 +2061,21 @@ double setI2SFreq(uint16_t iFreq)
} __attribute__((__packed__)) tmclk;
// 44117 is nickname for 44117.64706

if (F_PLL != 180000000)
Serial.println("ERROR: Teensy 3.6 F_PLL should be 180MHz, but is not.");
#if (F_PLL == 180000000)
//Serial.println("ERROR: Teensy 3.6 F_PLL should be 180MHz, but is not.");
const tmclk clkArr[numFreqs] = {{16, 1875}, {32, 1875}, {64, 1875}, {196, 3125}, {16, 255}, {128, 1875}, {219, 1604}, {32, 225}, {219, 802}};
/* Info:
#elif (F_PLL==168000000) //96k messes up signal gen and not much else better
Serial.println("144000000 works better on Teensy 3.5");
const tmclk clkArr[numFreqs] = {{24, 2625}, {16, 875}, {32, 875}, {42, 625}, {8, 119}, {64, 875}, {128, 875}, {16, 105}, {189, 646} };
#elif (F_PLL==144000000) //96k spectrum a little messed up, sig gen 23k BEST OF THE REST
const tmclk clkArr[numFreqs] = {{20, 1875}, {40, 1875}, {80, 1875}, {49, 625}, {4, 51}, {32, 375}, {64, 375}, {8, 45}, {128, 375} };
#elif (F_PLL==120000000) //can't have 96k set in spectrum, even if not using and if using max is 48k, signal gen around 20k
Serial.println("144000000 works better on Teensy 3.5");
const tmclk clkArr[numFreqs] = {{24, 1875}, {48, 1875}, {96, 1875}, {205, 2179}, {8, 85}, {64, 625}, {128, 625 }, {16,75}, {145, 354} };
#elif (F_PLL==192000000)
const tmclk clkArr[numFreqs] = {{1, 125}, {2, 125}, {4, 125},{147, 2500}, {1, 17}, {8, 125}, {16, 125}, {2, 15}, {32, 125} };
#endif
/* Info:
#define I2S0_MCR (*(volatile uint32_t *)0x4002F100) // SAI MCLK Control Register
#define I2S_MCR_DUF ((uint32_t)1<<31) // Divider Update Flag
#define I2S_MCR_MOE ((uint32_t)1<<30) // MCLK Output Enable
Expand All @@ -2083,6 +2096,12 @@ double setI2SFreq(uint16_t iFreq)
return ((double)F_PLL) * ((double)clkArr[iFreq].mult) / (DOUBLE_256 * ((double)clkArr[iFreq].div));
}

void mytest(){
for(int i=0;i<9;i++){
Serial.printf("%d\t%8.2f\n", sampleFreqs[i], setI2SFreq(i)); //setI2SFreq(sampleFreqs[i])
}
}

// valueStringSign()
// Same as valueString() but one char bigger(9) and adds blank or minus sign.
char *valueStringSign(float a, char *unitStr[])
Expand Down Expand Up @@ -2244,3 +2263,49 @@ char *valueString(float a, char *unitString[])
strcpy(str1, " *** "); // It can happen for X at 40 KHz
return str1;
}

void printCardType() {
csd_t m_csd;

sd.card()->readCSD(&m_csd);

Serial.printf("Card type: ");
switch (sd.card()->type()) {
case SD_CARD_TYPE_SD1:
Serial.printf("SD1\n");
break;
case SD_CARD_TYPE_SD2:
Serial.printf("SD2\n");
break;
case SD_CARD_TYPE_SDHC:
if (sdCardCapacity(&m_csd) < 70000000) {
Serial.printf("SDHC\n");
} else {
Serial.printf("SDXC\n");
}
break;
default:
Serial.printf("Unknown\n");
break;
}
}

void dmpVol() {
uint32_t clusterCount = sd.clusterCount();
if (sd.fatType() <= 32) {
Serial.printf("Volume is FAT%d, ", int(sd.fatType()));
} else {
Serial.printf("\nVolume is exFAT, ");
}
//Serial.printf("sectorsPerCluster: ") << sd.sectorsPerCluster() << endl;
//Serial.printf("clusterCount: ") << sd.clusterCount() << endl;
//Serial.printf("freeClusterCount: ") << freeClusterCount << endl;
//Serial.printf("fatStartSector: ") << sd.fatStartSector() << endl;
//Serial.printf("dataStartSector: ") << sd.dataStartSector() << endl;
Serial.printf("size (Mbytes): %u\n", clusterCount/2048);
/*if (sd.dataStartSector() % m_eraseSize) {
Serial.printf("Data area is not aligned on flash erase boundary!\n");
Serial.printf("Download and use formatter from www.sdcard.org!\n");
}
//*/
}
11 changes: 11 additions & 0 deletions AVNA8main/src/SerialCommandR2/SerialCommandR2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ char *SerialCommand::next()
return nextToken;
}

//list the commands
void SerialCommand::listCommands() //mdr20200211 from my mods in old file on mdr20181123
{
uint16_t i;

for (i=0; i<numCommand; i++){
Serial.println(CommandList[i].command);
}

}

// This checks the Serial stream for characters, and assembles them into a buffer.
// When the terminator character (default '\r') is seen, it starts parsing the
// buffer for a prefix command, and calls handlers setup by addCommand() member
Expand Down
3 changes: 2 additions & 1 deletion AVNA8main/src/SerialCommandR2/SerialCommandR2.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ class SerialCommand
void setResponse(uint16_t); // Response, if desired. default:NO_RESPONSE
void addCommand(const char *, void(*)()); // Add commands to processing dictionary
void addDefaultHandler(void (*function)()); // A handler to call when no valid command received.

void listCommands(); //Print out the available commands

private:
char inChar; // A character read from the serial stream
char buffer[SERIALCOMMANDBUFFER]; // Buffer of stored characters while waiting for terminator character
Expand Down