|
| 1 | +/* |
| 2 | +* CWSendTest4Rate.ino Test the |
| 3 | +* F32 library CW Modulator at four sample rates. |
| 4 | +* Bob Larkin 29 August 2025 |
| 5 | +* Public Domain |
| 6 | +*/ |
| 7 | + |
| 8 | +// This is a test of the CW Modulator |
| 9 | +// Runs at 12, 24, 48 and 96 ksps. Sends a test string out |
| 10 | +// to both Left and Right channels. |
| 11 | + |
| 12 | +#include "OpenAudio_ArduinoLibrary.h" |
| 13 | +#include "AudioStream_F32.h" |
| 14 | +#include <Audio.h> |
| 15 | +// Next include has set_audioClock( ) |
| 16 | +#include <utility/imxrt_hw.h> |
| 17 | + |
| 18 | +radioCWModulator_F32 CWMod1; //xy=414,332 |
| 19 | +AudioOutputI2S_F32 audioOutI2S1; //xy=595,327 |
| 20 | +AudioConnection_F32 patchCord1(CWMod1, 0, audioOutI2S1, 0); |
| 21 | +AudioConnection_F32 patchCord2(CWMod1, 0, audioOutI2S1, 1); |
| 22 | +AudioControlSGTL5000 sgtl5000_1; //xy=509,390 |
| 23 | + |
| 24 | +char test12Str[] = "test 12 "; |
| 25 | +char test24Str[] = "test 24 "; |
| 26 | +char test48Str[] = "test 48 "; |
| 27 | +char test96Str[] = "test 96 "; |
| 28 | + |
| 29 | +void setup(void) |
| 30 | + { |
| 31 | + Serial.begin(9600); |
| 32 | + delay(1000); |
| 33 | + AudioMemory_F32(20); |
| 34 | + Serial.println("Test CW Transmit"); |
| 35 | + |
| 36 | + setI2SFreq(12000); // Sets I2S clocks |
| 37 | + |
| 38 | + CWMod1.setSampleRate_Hz(12000.0f); // Sets CW functions, only |
| 39 | + CWMod1.setCWSpeedWPM(13); |
| 40 | + CWMod1.setFrequency(700.0f); |
| 41 | + CWMod1.amplitude(0.3f); // <== IMPORTANT Set before using headphones |
| 42 | + CWMod1.sendStringCW(test12Str); |
| 43 | + CWMod1.enableTransmit(true); |
| 44 | + Serial.println("Going to 12 ksps Sample Rate"); |
| 45 | + while(CWMod1.getBufferSpace() < 512) delay(1); // Send at 12 ksps |
| 46 | + |
| 47 | + setI2SFreq(24000); |
| 48 | + CWMod1.setSampleRate_Hz(24000.0f); |
| 49 | + CWMod1.sendStringCW(test24Str); |
| 50 | + Serial.println("Going to 24 ksps Sample Rate"); |
| 51 | + while(CWMod1.getBufferSpace() < 512) delay(1); // Send at 24 ksps |
| 52 | + |
| 53 | + setI2SFreq(48000); |
| 54 | + CWMod1.setSampleRate_Hz(48000.0f); |
| 55 | + CWMod1.sendStringCW(test48Str); |
| 56 | + Serial.println("Going to 48 ksps Sample Rate"); |
| 57 | + while(CWMod1.getBufferSpace() < 512) delay(1); // Send at 48 ksps |
| 58 | + |
| 59 | + setI2SFreq(96000); |
| 60 | + CWMod1.setSampleRate_Hz(96000.0f); |
| 61 | + CWMod1.sendStringCW(test96Str); |
| 62 | + Serial.println("Going to 96 ksps Sample Rate"); |
| 63 | + while(CWMod1.getBufferSpace() < 512) delay(1); // Send at 96 ksps |
| 64 | + delay(5); |
| 65 | + |
| 66 | + Serial.println("End of Transmission"); |
| 67 | + } |
| 68 | + |
| 69 | +void loop(void) |
| 70 | + { |
| 71 | + delay(1); |
| 72 | + } |
| 73 | + |
| 74 | +// Frank B's routine for setting I2S clocks. *** FOR T4.x ONLY *** |
| 75 | +void setI2SFreq(int freq1) // Thank ypu, Frank B. |
| 76 | + { |
| 77 | + // PLL between 27*24 = 648MHz und 54*24=1296MHz |
| 78 | + int n1 = 4; //SAI prescaler 4 => (n1*n2) = multiple of 4 |
| 79 | + int n2 = 1 + (24000000 * 27) / (freq1 * 256 * n1); |
| 80 | + double C = ((double)freq1 * 256 * n1 * n2) / 24000000; |
| 81 | + int c0 = C; |
| 82 | + int c2 = 10000; |
| 83 | + int c1 = C * c2 - (c0 * c2); |
| 84 | + set_audioClock(c0, c1, c2, true); |
| 85 | + CCM_CS1CDR = (CCM_CS1CDR & ~(CCM_CS1CDR_SAI1_CLK_PRED_MASK | CCM_CS1CDR_SAI1_CLK_PODF_MASK)) |
| 86 | + | CCM_CS1CDR_SAI1_CLK_PRED(n1-1) // &0x07 |
| 87 | + | CCM_CS1CDR_SAI1_CLK_PODF(n2-1); // &0x3f |
| 88 | + } |
0 commit comments