REM *************************************** REM *************************************** REM * VLF Receiver based on PICAXE-28X2 * REM * - Jurjen Kranenborg, Jan. 2025 (V2) * REM * V1: Baseline, receiver works well. * REM * V2: Addition of separate (manual) * REM * control of antenna tuning via * REM * the DAC and relais. By the push * REM * of a button the device alter- * REM * nates between receiving mode * REM * and antenna tuning mode using * REM * the same knob/dial. * REM *************************************** REM *************************************** REM: Define program configuration: REM: Tests or full-program functionality REM =================================== '#DEFINE FourFreqs_m16 '#DEFINE RelaisCheck '#DEFINE SerialDisplayMessaging '#DEFINE ReadFreqDial '#DEFINE TestDACoutput #DEFINE FullProgram REM Hardware settings: REM ================== #picaxe 28x2 REM Emulate accuracy of em64 through m16 + osc. calibration (using a frequency meter) REM as the N4800 baud mode for Serial Display communication is not suppported for em64. PAUSE 250 SETFREQ m16 PAUSE 100 CALIBFREQ 20 'Calibrate the on-chip oscillator for maximum PWM frequency accuracy PAUSE 100 DACSETUP %10100000 ; external DAC, supply voltage as reference #no_data #no_table REM !Specific HW settings (please adapt for your picaxe HW config)! REM --------------------------------------------------------------- PULLUP %01110011 OUTPUT A.0, A.1, A.2, A.3, A.4 OUTPUT C.0, C.1, C.2, C.3 INPUT B.0, B.1, B.4, B.5, B.6 OUTPUT B.2, B.3, B.7 SYMBOL SwitchB0 = PinB.0 'Only needed for test setup to be able to quickly pre-select four different frequencies SYMBOL SwitchB1 = PinB.1 'idem SYMBOL ButtonSwitch = PinB.6 'Interrupt-driven button to switch between "Receiving" and "Antenna Tuning" modes" SYMBOL LED = A.1 'On-board LED, also used to indicate which band is active (for band-switching) SYMBOL PWM_Autodyne = C.2 'Baseline frequency signal supplied (via RC-filter) to SA612A RF Mixer SYMBOL TuningDAC = A.2 'DC voltage to control the varactor/varicap diode for tuning the antenna coil SYMBOL RelaisControl = B.7 'Band-switching relais SYMBOL SerialDisplay = B.3 'Serial Display (AXE133/133Y) interface. SYMBOL FrequencyDial = 13 '= ADC13 = B.5. Frequency dial connection (potmeter)- also used for antenna tuning SYMBOL NULL = $00 SYMBOL Relais_OFF = $00 SYMBOL Relais_ON = $01 SYMBOL Receiving = $02 SYMBOL AntennaTuning = $03 REM Interrupt setting for ButtpnSwitch (active LOW): PAUSE 100 SETINT %00000000, %01000000, B 'Pin B.6, active LOW, has internal pullup) REM Software definitions (registers): REM --------------------------------- SYMBOL ADC_FreqDial = b0 SYMBOL OperationMode = b1 SYMBOL Period8 = b2 SYMBOL Period8_old = b3 SYMBOL Duty10 = w2 SYMBOL DACcalcW = w3 SYMBOL DACcalcB = b6 SYMBOL Stepsize = b8 SYMBOL Frequency = w5 SYMBOL Frequency_kHz = w6 SYMBOL Frequency_tenth = w7 SYMBOL Period8_temp = b16 SYMBOL DACCalcB_old = b17 SYMBOL RelaisStatus = b18 REM Execution start (for all configurations) REM ======================================== REM Startup HIGH LED PAUSE 4000 LOW LED REM Further execution depends on comfiguration settings (tests programs of full receiver config): '---------------------------------------------------- #IFDEF RelaisCheck REM Check the Relais (toggling) REM ========================== DO TOGGLE LED TOGGLE RelaisControl PAUSE 3000 LOOP #ENDIF '---------------------------------------------------- #IFDEF FourFreqs_m16 REM Choice of 4 fixed frequecies depending on switch settings at B.0 and B.1 REM Note that internal pullups have been switched on, so default state is HIGH for these pins REM ============================= IF SwitchB0 = 1 THEN IF SwitchB1 = 1 THEN REM: SAQ freq (17.2 kHz) + 2 kHz tone/beatnote REM Freq: 19.2 kHz HIGH RelaisControl, LED DACLEVEL 0 pwmout PWM_Autodyne, 207, 415 ELSE REM GQD freq (19.6 kHz) + 2 kHz tone/beatnote REM Freq: 21.6 kHz HIGH RelaisControl, LED DACLEVEL 0 pwmout PWM_Autodyne, 184, 369 ENDIF ELSE IF SwitchB1 = 1 THEN REM: DHO38 freq (23.4 kHz) + 2kHz tone/beatnote REM Freq: 25.4 kHz HIGH RelaisControl, LED DACLEVEL 0 pwmout PWM_Autodyne, 156, 313 ELSE REM DCF freq (77.5 kHz) + 2 kHz tone/beatnote REM Freq: 79.5 kHz LOW RelaisControl, LED DACLEVEL 31 pwmout PWM_Autodyne, 50, 101 ENDIF ENDIF DO REM Just generate the pwm signal endlessly REM and test the DAC output(for load measurement) LOOP #ENDIF '---------------------------------------------------- #IFDEF SerialDisplayMessaging REM Test the communication of the 28X2 with the Serial Display) REM =========================================================== DO REM First clear the display and set cursor to upper left position (first line SEROUT SerialDisplay, N4800_16,(254,1) PAUSE 15 ; PAUSE 15 = 3 chars x 2.5ms = 7.5ms @ 16MHz ... (so change to PAUSE 30 for testing at 32MHz) SEROUT SerialDisplay, N4800_16,(254,128) PAUSE 15 REM Now display is ready to show some messages: SEROUT SerialDisplay, N4800_16, ("Hello1") PAUSE 2000 SEROUT SerialDisplay, N4800_16,(254, 192) PAUSE 15 SEROUT SerialDisplay, N4800_16, ("Hello2") PAUSE 2000 SEROUT SerialDisplay, N4800_16,(254,1) PAUSE 15 SEROUT SerialDisplay, N4800_16, ("Hello World! ") ; 16 chars (including spaces) Pause 2000 SEROUT SerialDisplay, N4800_16,(254, 192) PAUSE 15 SEROUT SerialDisplay, N4800_16,(253, 15) ; Show pre-programmed message nr 15 PAUSE 2000 LOOP #ENDIF #REM The most common Display control commands are: 254,1 Clear Display (must be followed by a ?pause 30? command) 254,8 Hide Display 254,12 Restore Display 254,14 Turn on Cursor 254,16 Move Cursor Left 254,20 Move Cursor Right 254,128 Move to line 1, position 1 254, y Move to line 1, position x (where y = 128 + x) 254,192 Move to line 2, position 1 254, y Move to line 2, position x (where y = 192 + x) #ENDREM '---------------------------------------------------- #IFDEF ReadFreqDial REM Test the Frequency Dial input REM ============================= DO READADC FrequencyDial, ADC_FreqDial sertxd("Freq_ADC: ",#ADC_FreqDial,13,10) PAUSE 1000 LOOP #ENDIF '---------------------------------------------------- #IFDEF TestDACoutput REM Test the DAC output, controlled by the ADC input (Freq. dial) REM ============================= DO READADC FrequencyDial, ADC_FreqDial sertxd("Freq_ADC: ",#ADC_FreqDial,13,10) ADC_FreqDial = ADC_FreqDial / 8 DACLEVEL ADC_FreqDial PAUSE 1000 LOOP #ENDIF '---------------------------------------------------- #IFDEF FullProgram REM VLF Receiver User Interface REM =========================== REM Initialize LCD screen and define baseline setting (i.e. frequency close to DCF77 signal) REM --------------------------- REM Provide start message for a few secs: CALL WelcomeMessage_LCD REM Assume frequency dial is in the middle position such that no frequency change happens at the start, REM then start close to DCF77 / Mainflingen Time Base transmitter (as this signal is always available) LET Period8_old = 53 LET Period8 = Period8_old LET Duty10 = Period8_old * 2 + 1 pwmout PWM_Autodyne, Period8_old, Duty10 'Start listening to the DCF77 Mainflingen station CALL TuneAntennaCoil ' ... fine-tune the antenna coil for it as well using the varactor and relais, LET DACCalcB_old = DACCalcB ' ... and have an initial DAC value in var. DACCalcB as a consequnce REM Start in Receiving mode: LET OperationMode = Receiving REM Now the Radio can be tuned forever ...: REM --------------------------- DO REM Read Frequency dial and decide if its setting has changed READADC FrequencyDial, ADC_FreqDial SETINT OFF 'Disable interrupts, as either operation mode step needs to be properly completed. IF OperationMode = Receiving THEN REM Operate as a classical receiver, with the dial used for frequency selection. CALL ConvertADCtoPeriod ' --> Check new dial position and update the PWM signal period (only if needed) in Period8 IF Period8 <> Period8_old THEN REM Frequency needs to change, only then change PWM LET Duty10 = Period8 * 2 + 1 pwmout PWM_Autodyne, Period8, Duty10 ' Change frequency accordingly CALL TuneAntennaCoil ' ... and fine-tune the antenna coil for it as well using the varactor and bandswitch-relais CALL ConvertPeriodToFreq_LCD ' ... and report the new frequency Period8_old = Period8 ENDIF ELSE REM OperationMode = AntennaTuning, So tune the antenna coil at current fixed frequency, usimg the dial. CALL ConvertADCtoCapacitance ' --> Check new dial position and update the combined DAC + Relais settings IF DACCalcB <> DACCalcB_old THEN CALL ReportTuningStatus_LCD 'Show updated DAC and Relais setting on LCD --> DAC:xx, Relais:x LET DACCalcB_old = DACCalcB ENDIF ENDIF REM Re-enable interrupts SETINT %00000000, %01000000, B 'Pin B.6, active LOW, has internal pullup) PAUSE 2000 '1s at 16mHz LOOP #ENDIF Interrupt: #REM On a button press, Switch between the following modes: - Receiving: normal operation mode, dial is used for frequency setting - Antenna tuning: Keep the current frequency, dial is used to change the coil capacitance linearly via both DAC and Relais settings Operation mode is kept in the variable OperationMode that is comstatly checked in the main program loop #ENDREM IF OperationMode = Receiving THEN REM Switch to antenna tuning mode OperationMode = AntennaTuning CALL ReportTuningStatus_LCD 'Show DAC and Relais setting on LCD --> DAC:xx, Relais:x ELSE REM Switch back to Receiving Mode OperationMode = Receiving CALL TuneAntennaCoil ' Fine-tune the antenna coil again (automatically calculated) CALL ConvertPeriodToFreq_LCD ' ... and show frequency status ENDIF PAUSE 500 'Debounce switch SETINT %00000000, %01000000, B 'Re-enable interrupts RETURN ' Subroutines for both testing and full programs ' =============================================== ConvertADCtoPeriod: REM: Update the receiver's frequency (+ or -) depending om frequency dial position (mid = neutral = no change) #REM Check changed dial position (ADC_FreqDial) and update Period8 (based on Period8_old) if needed based on the following range: Frequency dial division (for period8 changes) based on ADC values: Note that a frenquency increase implies a Period8 decrease ... Upper frequency limit is at Period8 = 49 (lowest value) Lower frequency limit is at Period8 = 255 (highest value) ADC value: Period8 update: --------- -------------- 0-14: +8 15-41: +4 42-67: +2 68-96: +1 97-133: 0 (no period8/frequency change needed) 134-158: -1 159-184: -2 185-222: -4 223-255: -8 #ENDREM REM First: interpret the freq dial: SELECT CASE ADC_FreqDial CASE 0 TO 14 IF Period8 < 248 THEN LET Period8 = Period8_old + 8 LET Stepsize = 248 ELSE LET Period8 = 255 LET Stepsize = 255 - Period8 ENDIF CASE 15 TO 41 IF Period8 < 252 THEN LET Period8 = Period8_old + 4 LET Stepsize = 252 ELSE LET Period8 = 255 LET Stepsize = 255 - Period8 ENDIF CASE 42 TO 67 IF Period8 < 254 THEN LET Period8 = Period8_old + 2 LET Stepsize = 254 ELSE LET Period8 = 255 LET Stepsize = 255 - Period8 ENDIF CASE 68 TO 96 IF Period8 < 255 THEN LET Period8 = Period8_old + 1 LET Stepsize = 255 ELSE LET Period8 = 255 LET Stepsize = 255 - Period8 ENDIF CASE 97 TO 133 LET Period8 = Period8_old 'Frequency (and thus Period8) unchanged = Period8_old CASE 134 TO 158 IF Period8 > 49 THEN LET Period8 = Period8_old - 1 LET Stepsize = 1 ELSE LET Period8 = 49 LET Stepsize = Period8 - 49 ENDIF CASE 159 TO 184 IF Period8 > 50 THEN LET Period8 = Period8_old - 2 LET Stepsize = 2 ELSE LET Period8 = 49 LET Stepsize = Period8 - 49 ENDIF CASE 185 TO 222 IF Period8 > 52 THEN LET Period8 = Period8_old - 4 LET Stepsize = 4 ELSE LET Period8 = 49 LET Stepsize = Period8 - 49 ENDIF CASE 223 TO 255 IF Period8 > 56 THEN LET Period8 = Period8_old - 8 LET Stepsize = 8 ELSE LET Period8 = 49 LET Stepsize = Period8 - 49 ENDIF ENDSELECT RETURN ConvertADCtoCapacitance: REM: Alter the antenna tune capacity (+ or -) depending on frequency dial position (mid = neutral = no change) #REM Check changed dial position (ADC_FreqDial) and update both the varactor DAC level (ACCalcB) and the bandswitch relais (RelaisStatus): Frequency dial division (for capacity changes) based on ADC values: Note that a frenquency increase implies a Period8 decrease ... Upper capacitance limit is at DACCalcB = 0 and RelaisStaust = ON (at lowest freq) Lower capacitance limit is at DACCalcB = 31 and RelaisStatus = OFF (at highest freq) ADC value: DAClevel update: --------- -------------- 0-14: -8 15-41: -4 42-67: -2 68-96: -1 97-133: 0 (no DAClevel/capacitance change needed) 134-158: +1 159-184: +2 185-222: +4 223-255: +8 #ENDREM REM First: interpret the freq dial: SELECT CASE ADC_FreqDial CASE 0 TO 14 IF DACCalcB >= 8 THEN LET DACCalcB = DACCalcB - 8 ELSE IF RelaisStatus = Relais_OFF THEN REM Lower border of Lower Capacity Band, switch to upper part of Higher Cap. Band LET DACCalcB = DACCalcB + 32 - 8 LET RelaisStatus = Relais_ON ELSE REM Lower border of Higher Capacity Band, REM Higher in capacity we cannot go, so this is the DAC bottom level as well LET DACCalcB = 0 ENDIF ENDIF CASE 15 TO 41 IF DACCalcB >= 4 THEN LET DACCalcB = DACCalcB - 4 ELSE IF RelaisStatus = Relais_OFF THEN REM Lower border of Lower Capacity Band, switch to upper part of Higher Cap. Band LET DACCalcB = DACCalcB + 32 - 4 LET RelaisStatus = Relais_ON ELSE REM Lower border of Higher Capacity Band, REM Higher in capacity we cannot go, so this is the DAC bottom level as well LET DACCalcB = 0 ENDIF ENDIF CASE 42 TO 67 IF DACCalcB >= 2 THEN LET DACCalcB = DACCalcB - 2 ELSE IF RelaisStatus = Relais_OFF THEN REM Lower border of Lower Capacity Band, switch to upper part of Higher Cap. Band LET DACCalcB = DACCalcB + 32 - 2 LET RelaisStatus = Relais_ON ELSE REM Lower border of Higher Capacity Band, REM Higher in capacity we cannot go, so this is the DAC bottom level as well LET DACCalcB = 0 ENDIF ENDIF CASE 68 TO 96 IF DACCalcB >= 1 THEN LET DACCalcB = DACCalcB - 1 ELSE IF RelaisStatus = Relais_OFF THEN REM Lower border of Lower Capacity Band, switch to upper part of Higher Cap. Band LET DACCalcB = 31 LET RelaisStatus = Relais_ON ELSE REM Lower border of Higher Capacity Band, REM Higher in capacity we cannot go, so this is the DAC bottom level as well LET DACCalcB = 0 ENDIF ENDIF CASE 97 TO 133 PAUSE 10 'Coil tuning cacitance (and thus DAC and Relais settings) unchanged ... CASE 134 TO 158 IF DACCalcB <= 30 THEN LET DACCalcB = DACCalcB + 1 ELSE IF RelaisStatus = Relais_ON THEN REM Higher border of High Capacity Band, switch to lower part of Lower Cap. Band LET DACCalcB = DACCalcB - 32 + 1 LET RelaisStatus = Relais_OFF ELSE REM Higher border of Lower Capacity Band, REM lower in capacity we cannot go, so this is the DAC top level as well LET DACCalcB = 31 ENDIF ENDIF CASE 159 TO 184 IF DACCalcB <= 29 THEN LET DACCalcB = DACCalcB + 2 ELSE IF RelaisStatus = Relais_ON THEN REM Higher border of High Capacity Band, switch to lower part of Lower Cap. Band LET DACCalcB = DACCalcB - 32 + 2 LET RelaisStatus = Relais_OFF ELSE REM Higher border of Lower Capacity Band, REM lower in capacity we cannot go, so this is the DAC top level as well LET DACCalcB = 31 ENDIF ENDIF CASE 185 TO 222 IF DACCalcB <= 27 THEN LET DACCalcB = DACCalcB + 4 ELSE IF RelaisStatus = Relais_ON THEN REM Higher border of High Capacity Band, switch to lower part of Lower Cap. Band LET DACCalcB = DACCalcB - 32 + 4 LET RelaisStatus = Relais_OFF ELSE REM Higher border of Lower Capacity Band, REM lower in capacity we cannot go, so this is the DAC top level as well LET DACCalcB = 31 ENDIF ENDIF CASE 223 TO 255 IF DACCalcB <= 23 THEN LET DACCalcB = DACCalcB + 8 ELSE IF RelaisStatus = Relais_ON THEN REM Higher border of High Capacity Band, switch to lower part of Lower Cap. Band LET DACCalcB = DACCalcB - 32 + 8 LET RelaisStatus = Relais_OFF ELSE REM Higher border of Lower Capacity Band, REM lower in capacity we cannot go, so this is the DAC top level as well LET DACCalcB = 31 ENDIF ENDIF ENDSELECT REM Now the new DAC level should be effective as well: DACLEVEL DACCalcB IF RelaisStatus = Relais_ON THEN HIGH RelaisControl, LED ELSE LOW RelaisControl, LED ENDIF RETURN ReportTuningStatus_LCD: SEROUT SerialDisplay, N4800_16,(254, 192) PAUSE 70 SEROUT SerialDisplay, N4800_16, ("Relais:", #RelaisStatus, " DAC:", #DACCalcB, " ") PAUSE 70 RETURN WelcomeMessage_LCD: REM First clear the display and set cursor to upper left position (first line SEROUT SerialDisplay, N4800_16,(254,1) PAUSE 15 ; PAUSE 15 = 3 chars x 2.5ms = 7.5ms @ 16MHz ... (so change to PAUSE 30 for testing at 32MHz) SEROUT SerialDisplay, N4800_16,(254,128) PAUSE 15 REM Present Welcome message: SEROUT SerialDisplay, N4800_16, ("VLF Receiver ") PAUSE 2000 SEROUT SerialDisplay, N4800_16,(254, 192) PAUSE 15 SEROUT SerialDisplay, N4800_16, ("(16kHz - 80kHz) ") REM Wait a while: PAUSE 6000 '(3 sec. at 16mHz for a X2) REM; Clear display again and then start ordinary operation SEROUT SerialDisplay, N4800_16,(254,1) PAUSE 15 ; PAUSE 15 = 3 chars x 2.5ms = 7.5ms @ 16MHz ... (so change to PAUSE 30 for testing at 32MHz) SEROUT SerialDisplay, N4800_16,(254,128) PAUSE 15 RETURN ConvertPeriodToFreq_LCD: REM Display the receiver frequency, based on current PWM settings REM For some well-known stations, the name shows up as well when getting close ... REM ============================================================================== #REM Period8 (picaxe) to freq calc: ------------------------------ According to manual: * the PWM period = (period8 + 1) x 4 x resonator speed (resonator speed for 4MHz = 1/4000000) * PWM frequency = 1 / (the PWM period) In our case at m16 (= 16MHz): Freq = 16.000.000 / 4 / (period8 +1) = 4.000.000 / (period8 + 1)) ... in Hz = 40.000 / (period8 + 1) ... in 100 Hz blocks This can be calculated fully in unsigned 16-bit arithmetic #ENDREM LET Frequency = Period8 + 1 LET Frequency = 40676 / Frequency 'Frequency in 100Hz steps --> 775 = 77.5 kHz) 'Note: Constant is hand-calibrated from baseline 40000 value through direct PWM frequency measurement LET Frequency_kHz = Frequency / 10 LET Frequency_tenth = Frequency // 10 SEROUT SerialDisplay, N4800_16,(254, 128) PAUSE 70 SEROUT SerialDisplay, N4800_16, ("Freq: ", #Frequency_kHz,".", #Frequency_tenth," kHz") PAUSE 70 SELECT CASE Frequency CASE 161 TO 166 SEROUT SerialDisplay, N4800_16,(254, 192) PAUSE 70 SEROUT SerialDisplay, N4800_16, ("(JXN Gildeskal) ") PAUSE 70 CASE 167 TO 177 SEROUT SerialDisplay, N4800_16,(254, 192) PAUSE 70 SEROUT SerialDisplay, N4800_16, ("(SAQ Grimeton) ") PAUSE 70 CASE 186 TO 206 SEROUT SerialDisplay, N4800_16,(254, 192) PAUSE 70 SEROUT SerialDisplay, N4800_16, ("(GQD Anthorn) ") PAUSE 70 CASE 214 TO 254 SEROUT SerialDisplay, N4800_16,(254, 192) PAUSE 70 SEROUT SerialDisplay, N4800_16, ("(DHO38 Rhauder.)") PAUSE 70 CASE 360 TO 390 SEROUT SerialDisplay, N4800_16,(254, 192) PAUSE 70 SEROUT SerialDisplay, N4800_16, ("(ISL US/Icelnd.)") PAUSE 70 CASE 415 TO 435 SEROUT SerialDisplay, N4800_16,(254, 192) PAUSE 70 SEROUT SerialDisplay, N4800_16, ("(SAS2 Varberg) ") PAUSE 70 CASE 440 TO 480 SEROUT SerialDisplay, N4800_16,(254, 192) PAUSE 70 SEROUT SerialDisplay, N4800_16, ("(NSY US/Niscemi)") PAUSE 70 CASE 570 TO 629 SEROUT SerialDisplay, N4800_16,(254, 192) PAUSE 70 SEROUT SerialDisplay, N4800_16, ("(MSF Anthorn) ") PAUSE 70 CASE 630 TO 650 SEROUT SerialDisplay, N4800_16,(254, 192) PAUSE 70 SEROUT SerialDisplay, N4800_16, ("(FTA63 St.Assis)") PAUSE 70 CASE 651 TO 665 SEROUT SerialDisplay, N4800_16,(254, 192) PAUSE 70 SEROUT SerialDisplay, N4800_16, ("(FUE Kerlouan) ") PAUSE 70 CASE 760 TO 810 SEROUT SerialDisplay, N4800_16,(254, 192) PAUSE 70 SEROUT SerialDisplay, N4800_16, ("(DCF77 Mainfl.) ") PAUSE 70 ELSE SEROUT SerialDisplay, N4800_16,(254, 192) PAUSE 70 SEROUT SerialDisplay, N4800_16, (" ") PAUSE 70 END SELECT SEROUT SerialDisplay, N4800_16,(254,128) PAUSE 70 RETURN TuneAntennaCoil: #REM Tune the antenna through the combination of: - Varactor DAC voltage (low for high pF value and v.v.) - Relais switch for bandswitch #ENDREM SYMBOL RelaisSwitch_Period8 = 120 'Boundary for switching; On for Period8 > RelaisSwitch_Period8 REM define the varactor voltage first (for each of the two bands) IF Period8 >= RelaisSwitch_Period8 THEN REM This is the LOWER frequency band REM -------------------------------- REM Scale the DAC voltage in the 0 - 31 range linearly inverse with respect to the Period8 interval (255 - 120) = [135] REM ... so Period8 = 255 corresponds with DAC = 0, Period = 120 with DAC = 31 REM Use proper integer math: 135 x 10 = 1350 & 1350 : 43 = 31.4 --> DAClevel = 10*(255-Period8)/43 LET DACcalcW = 255 - Period8 LET DACcalcW = DACcalcW * 10 LET DACCalcW = DACcalcW / 43 DACLEVEL DACcalcB 'Lower byte of DACcalcW REM 'Relais should be switched ON in this lower-frequency band HIGH RelaisControl, LED LET RelaisStatus = Relais_ON ELSE REM This is the HIGHER frequency band REM -------------------------------- REM Scale the DAC voltage in the 0 - 31 range linearly inverse with respect to the Period8 interval (119 - 49)= [70] REM ... so Period8 = 119 corresponds with DAC = 0, Period = 49 with DAC = 31 REM Use proper integer math: 70 x 10 = 700 & 700 : 22 = 32 --> DACLEVEL = 10*(119-Period8)/22 & then floor to 31 LET DACcalcW = 119 - Period8 LET DACcalcW = DACcalcW * 10 LET DACCalcW = DACcalcW / 22 IF DACcalcW > 31 THEN 'Floor this value to 31 (= max range of DAC) DACcalcW = 31 ENDIF DACLEVEL DACcalcB 'Lower byte of DACcalcW REM Relais should be switched OFF in this higher-frequency band LOW RelaisControl, LED LET RelaisStatus = Relais_OFF ENDIF RETURN '---------------------------------------------------- #REM Useful relations: ================= 1) REM Range control: 16 kHz - 80 kHz: ----------------------------------- 80.0 kHz = pwmout PWM_pin, 49, 99 78.4 kHz = pwmout PWM_pin, 50, 101 76.9 kHz = pwmout PWM_pin, 51, 103 (DCF77) 62.4 kHz = pwmout PWM_pin, 63, 127 62.0 kHz = pwmout PWM_pin, 64, 129 33.1 kHz = pwmout PWM_pin, 120, 241 <-- medium frequency range 26.5 kHz = pwmout PWM_pin, 150, 301 17.2 kHz = pwmout PWM_pin, 232, 465 (Grimeton/SAQ) 16.0 kHZ = pwmout PWM_pin, 249, 499 15.6 kHz = pwmout PWM_pin, 255, 511 2) Antenna Coil Inductance determination using colpitts oscillator --------------------------------------------------------------- 4 LW coils on ferrite rod: Net series capacitance: Measured Freq: Inductance L calculated: 2800 pF = 2800e-12 F 13.17 kHz = 13170 Hz 52.1 mH (4x) 23500 pf = 23500e-12 F 4.57 kHz = 4570 Hz 51.6 mH (4x) 0.05 uF = 50000e-12 F 3.13 kHz = 3130 Hz 51.7 mH (4x) 5 LW Coils on ferrite rod: Net series capacitance: Measured Freq: Inductance L calculated: 2800 pF = 2800e-12 F 11.50 kHz = 11500 Hz 68.4 mH (5x) 23500 pf = 23500e-12 F 3.91 kHz = 3905 Hz 70.7 mH (5x) 0.05 uF = 50000e-12 F 2.66 kHz = 2664 Hz 71.3 mH (5x) #ENDREM