' Robby004.bas ' ' HeVaWi ' Build: ' 001, 2004-07-13, original release ' ' Program measures Robby accu voltage about 4 times per second ' and sends value to serial connection ' and: switches on ' - led1 if power is above 5V ' - led1 and led2 if power is above 6V ' - led1 to led3 if power is above 7V ' - led1 to led4 if power is above 8V ' - makes all leds blink together if voltage is above 9V ' ' I do not like the original #SUBSYS_PWR_ON function because: ' 1. it does more than switching power ' 2. it initialises processor ports connected to power-control-chip inputs ' 3. it does it in a (for me) unlogical way ' 4. it does not shut down ACS power making front IR-diodes send when in COM mode ' ' Therefor I prefer a dedicated #INIT_SUBSYS_PWR_CONTROL before switching on any power. ' '-------------------------- '------ I/O PORTS --------- '-------------------------- '- INTERFACE LCD/EXTPORT -- define sdio port[1] define sclio port[3] define strobe port[4] '-- INTERFACE COM/NAV ----- 'define DATALINE port[1] 'define CLOCKLINE port[2] '-------------------------- '------ SENSORS --------- '-------------------------- define SYS_CURRENT ad[1] 'define CHRG_CURRENT ad[2] define SYS_VOLTS ad[3] 'define MIC ad[4] 'define TOUCH ad[5] 'define LIGHT_R ad[6] 'define LIGHT_L ad[7] 'define FOR_USER ad[8] 'my define '--------------------------- '------ DRIVE ------------- '--------------------------- 'define SPEED_L da[1] 'define SPEED_R da[2] 'define REV_L port[6] 'define REV_R port[5] 'define FWD_L port[6] 'REV_L renamed to FWD_L to correspond with real situation 'define FWD_R port[5] 'REV_H renamed to FWD_H to correspond with real situation '-------------------------- '---- SYSTEM MEMORY ------- '-------------------------- '--- INTERFACE BUFFER ---- 'define LBYTE byte[1] 'define HBYTE byte[2] 'define SUBCMD byte[3] '---- OPERATION DATA ------ define EXTPORT byte[4] define COM_NAV_PWR_F bit[25] 'my defines define ACS_PWR_LO_F bit[26] 'my defines define ACS_PWR_HI_F bit[27] 'my defines define SNS_PWR_F bit[28] 'my defines define LED1_F bit[29] define LED2_F bit[30] define LED3_F bit[31] define LED4_F bit[32] 'define SYSTEM_STATUS byte[5] 'define ACSL_F bit[33] 'define ACSR_F bit[34] 'define IR_F bit[35] '--- SYSTEMROUTINEN ----------- 'define PLM_SLOW &H01C4 define SYSTEM &H01C9 'define COMNAV &H0154 '- ERWEITERTE SYSTEM ROUTINEN - 'define REVR &H0101 'ANTRIEB RECHTS RÜCKWÄRTS 'define REVL &H0106 'ANTRIEB LINKS RÜCKWÄRTS 'define FWDR &H010B 'ANTRIEG RECHTS VORWÄRTS 'define FWDL &H0110 'ANTRIEB LINKS VORWÄRTS 'define ROTR &H0115 'RECHTS DREHEN 'define ROTL &H0119 'LINKS DREHEN 'define REV &H011D 'RÜCKWÄRTS 'define FWD &H0121 'VORWÄRTS 'define COMNAV_STATUS &H0125 'UPDATED ALLE FLAGS IM STATUS-REGISTER 'define ACS_LO &H01E1 'ACS POWER LO 'define ACS_HI &H01E9 ' 'define ACS_MAX &H01F1 ' 'define SEND_TLM &H014A 'SENDET TELEMETRIE (CH=HBYTE,DATEN=LBYTE) 'define SEND_SPEEDR &H0134 'SENDET TLM KANAL 8,PLM RECHTS 'define SEND_SPEEDL &H013A 'SENDET TLM KANAL 7,PLM LINKS 'define SEND_SYSSTAT &H0144 'SENDET TLM KANAL 0,SYSTEM STATUS '================================================================================ ' USER DEFINES '================================================================================ define wMsrAccVlt word[3] 'measured accu voltage '================================================================================ ' MAIN PROGRAM START '================================================================================ #lMaiLop 'mark program as started (send message to terminal, only visible if connected) print print print "Started" print 'beep, to indicate program start beep 500,4,0 'initialise subsystem power control gosub INIT_SUBSYS_PWR_CONTROL 'prepair sense power-on only (generates 2.5V precision reference voltage) SNS_PWR_F=on 'activate sense power SYS SYSTEM 'switch off all leds gosub LEDSOFF '#---now-main-processor-voltage-reference-on-pin8-is-2.5V-by-Zener-chip--- 'When switching on sense-power, a zener-chip applies 2.5V reference to the microcontroller 'So 8-bit AD-converter, 8-bits = 0-255, meaning 2.5V / 255 bits = 9.80mV per bit. 'Voltage is measure over 1K resistor in series with 3K resistor. So multiple measured value by 4 'Full scale AD-Converter reading (&HFF) represents 4 times 2.5V = 10V 'So one (1) bit represents 255 * 9,80 = 39,2V '---measure-accu-voltage--- #lMsrAccVlt 'SYS_VOLTS ranges from 0-255 'Printed values range from -32K to +32K '392 * 255 = appr. 100.000. This is too high for integer and will return a negative value! 'So use 39 * measvalue plus 0.2 * measvalue (do: 2 * measvalue, then divide by 10)... '...and add this remainder to the original calculation 'now measure the accu voltage value wMsrAccVlt=(SYS_VOLTS * 39)+((SYS_VOLTS *2)/10) 'software test for overvoltage detection 'wMsrAccVlt=9001 'show accu voltage value on terminal (only visible if connected) print "Accu voltage=";wMsrAccVlt;" mV" 'switch off all leds gosub LEDSOFF 'if voltage above 5V, 6V, 7V or 8V then switch corresponding leds on if wMsrAccVlt > 5000 then gosub LED4ON 'led1 on if wMsrAccVlt > 6000 then gosub LED3ON 'led1 and led2 on if wMsrAccVlt > 7000 then gosub LED2ON 'led1 to led3 on if wMsrAccVlt > 8000 then gosub LED1ON 'led1 to led4 on 'if no overvoltage detected, jump to 'Voltage Test End' if wMsrAccVlt <= 9000 then goto lVltTstEnd '#---now-an-overvoltage-is-detected,-make-all-leds-blink--- 'keep all leds on for 20*20=400ms pause 20 'switch all leds off gosub LEDSOFF 'send warning message to terminal (only visible if connected) print "Warning: Overvoltage!" 'keep all leds off for 10*20=200ms (next 'pause 10' will keep on/off time equal) pause 10 '---voltage-test-end--- #lVltTstEnd 'keep all leds... (OFF, in case of overvoltage, or ON in other cases) for 10*20=200ms pause 10 'repeat measurerent goto lMsrAccVlt '================================================================================ ' MAIN PROGRAM END '================================================================================ END '================================================================================ ' INIT SUBSYS POWER CONTROL (AND ALL POWERS OFF) '================================================================================ #INIT_SUBSYS_PWR_CONTROL 'define serial-data signal as output-low sdio=off 'define serial-clock signal as output-low sclio=off 'define strobe signal as output-low strobe=off 'set EXTPORT communication/navigation power off (by setting bit to ON!) COM_NAV_PWR_F=off 'set EXTPORT refernce-voltage-microphone-power off SNS_PWR_F=off 'set ACS power to NONE by setting LO and HI to ON(!) ACS_PWR_LO_F=on ACS_PWR_HI_F=on 'send contents of EXTPORT (memory 4) to shiftregister IC I11 sys SYSTEM 'return return '================================================================================ ' Leds switch on/off '================================================================================ #LED1ON LED1_F=on : sys SYSTEM : return #LED1OFF LED1_F=off : sys SYSTEM : return #LED2ON LED2_F=on : sys SYSTEM : return #LED2OFF LED2_F=off : sys SYSTEM : return #LED3ON LED3_F=on : sys SYSTEM : return #LED3OFF LED3_F=off : sys SYSTEM : return #LED4ON LED4_F=on : sys SYSTEM : return #LED4OFF LED4_F=off : sys SYSTEM : return '================================================================================ ' All Leds off '================================================================================ #LEDSOFF '#ledsoff1: make all led bits (bits 4-7) from EXTPORT go low/off and leave bits 0 to 3 unchanged EXTPORT=EXTPORT and &H0F 'send EXTPORT byte to led/pwr control chip sys SYSTEM 'return return '================================================================================ ' All Leds on '================================================================================ #LEDSON 'make all led bits (bits 4-7) from EXTPORT go hihh/on and leave bits 0 to 3 unchanged EXTPORT=EXTPORT or &HF0 'send EXTPORT byte to led/pwr control chip sys SYSTEM 'return return