;AUTOTUNER CIRCUIT TEST 03 PROGRAM ;Created by Andrew Cornwall of Nova Scotia, Canada. ;The program is copyrighted, 2019, under the terms of the ;GNU General Public License version 3 as published by the ;Free Software Foundation. See the GNU General Public License ;for more details: https://www.gnu.org/licenses/ . ; ;This program is free software: you may use it, and under the ;terms of GNU 3 you may redistribute and/or modify it. ; ;This program is distributed in the hope that it will be useful, ;but WITHOUT ANY WARRANTY - without even the implied warranty of ;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ; ;PLATFORM: ;This program was written for the PICAXE 18M2+ microcontroller, using ;the PICAXE Editor 6. ; ;The program is for use with the small magnetic loop antenna autotuner ;circuit created by Andrew Cornwall. The circuit is documented ;at www.acornwall.ca . ; ;NOTES: ;The program assumes that a free-turning (360 degree) variable ;capacitor is attached to an automatic tuner stepper motor with 0.9 ;or 1.8 degrees full steps. setfreq m4; Note: in terminal program set BAUD rate to 4800. SERTXD (CR,LF,"VE1COR Autotuner Circuit Test Program 03. Function test and A4988 stepper motor current set utility",CR,LF) symbol AVG_VOLTS=W0 ;AVG_VOLTS is the measure of Sample Antenna radiated ;signal symbol NUMBER_STEPS=W2 symbol J=W0 symbol SIGNAL=W1 symbol COUNTER=B20 symbol SWEEP=B1 symbol LED_RED=B.0 symbol LED_YELLOW=B.1 symbol LED_BLUE=B.2 symbol BUZZER=B.3 symbol DIR=B.4 symbol STEPX=B.5 symbol MS1=C.7 symbol MS2=C.6 symbol MS3=B.7 symbol SLEEPX=B.6 symbol ADC=C.1 symbol RELAY=C.0 ;Initial conditions LOW LED_RED ;Off LOW LED_BLUE ;Off LOW LED_YELLOW ;Off LOW BUZZER ;Off LOW STEPX ;Off LOW MS2 ;LOW MS2 and LOW MS1 for Full Step LOW MS1 ;LOW LOW MS3 ; default MS3 is low LOW SLEEPX ;NO power to the stepper motor when LOW LOW DIR ;Direction at the Easy Driver needs to be something to start, ;which way does not matter LOW RELAY; Relay Open NUMBER_STEPS=400 ;one FULL STEP turn sertxd(CR,LF,"* TESTING BUZZER AND LEDS",CR,LF,"LED Blue, Yellow, then Red") pause 1000 gosub BLINK_BUZZER gosub BLINK_BUZZER gosub BLINK_BLUE gosub BLINK_BLUE gosub BLINK_YELLOW gosub BLINK_YELLOW gosub BLINK_RED gosub BLINK_RED pause 1000 sertxd(CR,LF,"* FOR ABOUT 10 SECONDS STEPPER MOTOR POWER IS ON BUT NO STEPS") sertxd(CR,LF," . time to measure circuit current draw and adjust stepper motor current",CR,LF) HIGH SLEEPX pause 10000 LOW SLEEPX sertxd(CR,LF,"* TESTING RF PATHWAY INCL. RELAY, AND ANALOGUE TO DIGITAL CONVERSION") sertxd(CR,LF,"- Apply various low currents to the sampling antenna input") sertxd(CR,LF," . for about the next 20 seconds the Relay is CLOSED",CR,LF) HIGH RELAY HIGH LED_YELLOW DO_AGAIN_ONE: COUNTER=COUNTER+1 gosub READ_ADC if SIGNAL<5 then LOW LED_RED LOW LED_BLUE endif if SIGNAL>500 then LOW LED_BLUE HIGH LED_RED endif if SIGNAL<500 and SIGNAL>=5 then LOW LED_RED HIGH LED_BLUE endif pause 300 if COUNTER<50 then goto DO_AGAIN_ONE LOW LED_RED LOW LED_BLUE gosub BLINK_BUZZER COUNTER=0 sertxd(CR,LF," . for about the next 20 seconds the Relay is OPEN",CR,LF) LOW RELAY LOW LED_YELLOW DO_AGAIN_TWO: COUNTER=COUNTER+1 gosub READ_ADC if SIGNAL<5 then LOW LED_RED LOW LED_BLUE endif if SIGNAL>=500 then LOW LED_BLUE HIGH LED_RED endif if SIGNAL<500 and SIGNAL>=5 then LOW LED_RED HIGH LED_BLUE endif pause 300 if COUNTER<50 then goto DO_AGAIN_TWO LOW LED_RED LOW LED_BLUE gosub BLINK_BUZZER COUNTER=0 sertxd(CR,LF,"* TESTING STEPPER MOTOR CONTROL") sertxd(CR,LF," . motor is ON but waiting 3 seconds to start",CR,LF) HIGH SLEEPX ;Turn on stepper motor power pause 3000 ;Wait 2 seconds to get started SWEEP=0 sertxd(CR,LF,"- Turning at FULL_STEP") sertxd(CR,LF," . ONE Complete Turn for 0.9 Deg. Stepper Motor") sertxd(CR,LF," . TWO Complete Turns for 1.8 Deg. Stepper Motor") LOW MS1 LOW MS2 gosub BLINK_BUZZER LOW LED_RED ;On HIGH LED_BLUE ;Off LOW LED_YELLOW ;Off gosub TURN_MOTOR toggle DIR pause 10 sertxd(CR,LF,"-Turning at HALF_STEP") sertxd(CR,LF," . In Opposite Direction") HIGH MS1 LOW MS2 gosub BLINK_BUZZER LOW LED_RED ;Off LOW LED_BLUE ;Off HIGH LED_YELLOW ;On gosub TURN_MOTOR toggle DIR pause 10 sertxd(CR,LF,"-Turning at QUARTER_STEP") sertxd(CR,LF," . In Opposite Direction") LOW MS1 HIGH MS2 gosub BLINK_BUZZER HIGH LED_RED ;Off LOW LED_BLUE ;On LOW LED_YELLOW ;Off gosub TURN_MOTOR toggle DIR pause 10 sertxd(CR,LF,"-Turning at EIGHTH_STEP") sertxd(CR,LF," . In Opposite Direction") HIGH MS1 HIGH MS2 gosub BLINK_BUZZER LOW LED_RED ;Off HIGH LED_BLUE ;On HIGH LED_YELLOW ;On gosub TURN_MOTOR toggle DIR pause 10 sertxd(CR,LF,"-Turning at SIXTEENTH_STEP") sertxd(CR,LF," . In Opposite Direction") HIGH MS1 HIGH MS2 HIGH MS3 gosub BLINK_BUZZER HIGH LED_RED ;On HIGH LED_BLUE ;On HIGH LED_YELLOW ;On gosub TURN_MOTOR sertxd(CR,LF,"* TESTING ROUTINE DONE") gosub BLINK_BUZZER gosub BLINK_BUZZER LOW RELAY LOW SLEEPX LOW LED_RED ;Off LOW LED_BLUE ;Off LOW LED_YELLOW ;Off DONEX: gosub BLINK_RED gosub BLINK_YELLOW gosub BLINK_BLUE goto DONEX ;SUBROUTINES ARE BELOW BLINK_BUZZER: HIGH BUZZER pause 400 LOW BUZZER pause 400 return BLINK_BLUE: HIGH LED_BLUE pause 400 LOW LED_BLUE pause 400 return BLINK_RED: HIGH LED_RED pause 400 LOW LED_RED pause 400 return BLINK_YELLOW: HIGH LED_YELLOW pause 400 LOW LED_YELLOW pause 400 return READ_ADC: readadc10 ADC,SIGNAL if SIGNAL>5 then sertxd(CR,LF,"SIGNAL IS ",#SIGNAL) endif return TURN_MOTOR: For j=1 to NUMBER_STEPS ;Move stepper mnotor one interval pause 10 HIGH STEPX pause 10 ;was 20 LOW STEPX pause 10 next j pause 2000 return