Full Version : Minimum Mass Wireless Terminal Interface (AVR ASM)
avr >>COMMUNICATIONS & WEB PROJECTS >>Minimum Mass Wireless Terminal Interface (AVR ASM)


AVR_Admin- 04-28-2006
Minimum Mass Wireless Coupler Terminal Interface
by Dick Cappel

This is a Minimum Mass Wireless Coupler that connects a terminal, or PC running terminal software, to other Minimum Masss Wireless devices by means of a 1200 baud data channel at 181.818 kHz.

The basic Minimum Mass Wireless Coupler technology is described and links to other projects on this site that use the Minimum Mass Wireless Coupler are located on the web page, Minimum Mass Wireless Coupler: http://cappels.org/dproj/minmassrfbase/minmassrfbu.html

The loop antenna goes around the perimiter of the circuit board.
The componenets inside the loop seem to have little effect on performance.

The purpose of the terminal interface is to allow my computer to communicate with Minimum Mass Wireless Coupler equipped devices using a terminal emulator program. Consequently, the Base Unit is basically an RS-232 interface and Minimum Mass Wireless Coupler. The Base Unit is the larger enclosure in Photo 1. The RS-232 interface to the computer is 9600 baud, 1 stop bit, no parity, plenty fast to keep up with the 1200 baud maximum data rate from the Coupler.

The antenna is made of 12 turns of #30 enameled wire threaded through metal guide loops arranged around the perimeter of the board (See the photograph.) This antenna's area is about 160% that of the prototype 5.5 cm loop so it has a little more range for both transmitting and receiving.

The 2N2907 and 2N2222 circuit is the RS-232 interface. The sensitivity
adjustment is made with R1, R2, and R3.

To further increase the transmitter's range, I used 220 ohm bias resistors (See the schematic, Figure 4). This sets the maximum peak current from the microcontroller’s output pin at about 23 milliamps, safely below the maximum current specified on the microcontroller’s data sheet. Since the antenna is resonant, the peak antenna current is greater than the microcontroller's drive current, about 70 milliamps peak-to-peak in this cae.

The Base Unit uses a trick to increase the receiver's sensitivity. I added an adjustment to compensate for some of the comparator's offset. The smaller the offset voltage, the smaller the signal needed from the antenna to trip the comparator. Adjusting R1 causes the voltage drop across R3 of up to ± 60 millivolts, and this effectively compensates for offset voltages across the comparator input up to the maximum shown on the controller’s data sheet.

Increasing the sensitivity can be a good thing, but too much can be a problem. When the offset is adjusted to near zero, noise from the microcontroller itself causes the receiver to repeatedly detect false signals. I've also noted that when I put the base unit too close to a backlight power supply in my notebook computer it picks up interference. Not only does the RS-232 output send out garbage, but the noise interferes with the desired signals from being properly decoded. The solution is to back off on the sensitivity adjustment. to the point that the receiver is stable.

The firmware for the terninal interface is very compact. All it does is to check for an incoming character from the UART if one is present, send it out the Minimum Mass Wireless Coupler, and check the Miniumu Mass Wireless Coupler for an incoming character, and if one is present, send it out the UART.


If an escape character is received from the terminal, the following character is trapped and executed as a command. If the character following the escape character is a second escape character, it is sent out over the Minimum Mass Wireless Coupler. If the character following the escape character is an ASCII "e", local echo is toggled on and off, and a notation is typed to the terminal screen. The "e" command is the only command that this interpreter responds to.

The Base Unit operates continuously for days or weeks at a time from an AC power adaptor and does not have an accessible power switch. Since resetting it manually would be inconvenient, the on-chip watchdog timer is used to catch hang-ups in the firmware. The main routine in the firmware alternately checks the RS-232 interface to see if there is anything to send out via the Minimum Mass Wireless Coupler, then checks the Minimum Mass Wireless Coupler to see if there is incoming data to receive and send out the RS-232 interface. After these checks are completed, the watchdog is reset. If, for any reason, the controller does not return from one of the two communications tasks, the watchdog would reset the controller.

Link to Site: http://cappels.org/dproj/minmassrfbase/minmassrfbu.html

CODE

;File name: vlfterm2313.asm Initial code for VLF terminal program

;4 MHz AT90S2313

;Copyright 2004 Richard Cappels, projects@cappels.org


.include "2313def.inc" ;Include file in same directory as this file..


; UART BAUD RATE CALCULATIONS
.equ     clock   = 4000000;Clock frequency
.equ     baudrate  = 9600         ;Choose a baudrate
.equ     baudconstant  = (clock/(16*baudrate))-1

.equ RFSigPort = PORTB ;Port output signal is to appear on.
.equ RFSigDDR = DDRB ;Data Direction Register for signal output
.equ RFSigPin = 0 ;Pin output signal is to appear on.

.equ LEDOutPort = PORTB ;Indicator LED
.equ LEDOutDDR = DDRB
.equ LEDOutPin = 3

.equ CompPlusPort = PORTB ;Comparitor noninverting input (input 0)
.equ CompPlusDDR = DDRB
.equ CompPlusPin = 0

.equ BridgePowerPort = PORTB ;Power for bridging resistors
.equ BridgePowerDDR = DDRB
.equ BridgePowerPin = 2


; used  = r0 ;Used for loading indirect from memory.
.def RFChar  = r16 ;RF character I/O buffer
.def flagreg  = r17 ;Flags for firmware control
; used  = ZL  
; used  = ZL


;Assignment of flagreg bits
;0 if set, indicates that local echo is on.
;1
;2
;3
;4
;5
;6
;7

;definition of I/O
;B0 + comparitor input - Antenna Signal
;B1 - comparitor input - Antenna reference
;B2 Bridge power  
;B3 LED (high to turn LED on) .
;B4 Receive/Xmit application (for test purposes)
;B5 (not assigned - configure as INPUT with weak pullup)
;B6 (not assigned - configure as INPUT with weak pullup)
;B7 (not assigned - configure as INPUT with weak pullup)


;D0 Reserved FOR UART RECEIVE - input has weak pullup
;D1 Reserved FOR UART TRANSMIT - output.
;D2 (not assigned - configure as INPUT with weak pullup)
;D3 (not assigned - configure as INPUT with weak pullup)
;D4 (not assigned - configure as INPUT with weak pullup)
;D5 (not assigned - configure as INPUT with weak pullup)
;D6 (not assigned - configure as INPUT with weak pullup)
;D7 (not assigned - configure as INPUT with weak pullup)



.cseg

.ORG $0000   ;Initializaton code
 rjmp start
.ORG $0006
 rjmp timer0service;Timer/counter compare interrupt for RF xmit/rcv.
.ORG $000A
 rjmp comparitorservice;Service comparitor interupt for RF receive.

.include "vlfcw2313.inc" ;RF communications include file, in same directory as this file.

start:
 
ldi RFChar,RAMEND ;Initialize Stack Pointer (AT90S2313 has an 8 bit stack pointer).
out spl,RFChar
 
ldi     RFChar,baudconstant    
out     ubrr,RFChar ;Load baud rate into UART register.
 
   ;Set PORTD.
ldi RFChar,0b00000010  
out DDRD,RFChar
ldi RFChar,0b10111111
out PORTD,RFChar

   ;Set PORTB.
ldi RFChar,0b00000000  
out DDRB,RFChar
ldi RFChar,0b11110100
out PORTB,RFChar  


sbi ucr,rxen ;Enable UART receive.
sbi     ucr,txen  ;Enmable USRT transmit.

clr flagreg  ;Clear firmware flags.

wdr   ;Reset the watchdog timer
ldi RFChar,0b00001111
out wdtcr,RFChar ;Enable the watchdog.

sbi BridgePowerDDR,BridgePowerPin;Turn on bridge power
sbi LEDOutDDR,LEDOutPin;Make LED pin an output pin.
sei   ;ENABLE THE INTERRUPTS.

rcall SayHello ;Send greeting to terminal.



Terminal:   ;This routine is for a terminal connection.
sbis usr,rxc  ;Check for data in UART receiver.
rjmp    norsdata ;If no data in UART, skip down.
in RFChar,udr ;Read data from UART.
sbrc flagreg,0 ;Don't echo char if local echo is off
rcall EchoIt  ;Echo the character to terminal
cpi RFChar,$1B ;Is this an escape character?
breq escapechar ;If escape character, branch to treat as special.
SB1: rcall SendRFByte ;Send data via RF.
rcall PostXmitDelay ;Wait for circuit to recover from xmit.
norsdata:  
rcall ReceiveRFByte ;Check for data from RF port
wdr   ;Reset the watchdog timer.
brcc noemit  ;If no data, don't emit the char, but skip down.
rcall EmitUart
noemit:
rjmp Terminal


EchoIt:    ;Echo character to terminal. If return, also send linefeed.
cpi RFChar,$0D
breq SendCRLF
rcall EmitUart ;Send char via UART.
ret

SendCRLF:
rjmp CRLF  ;CRLF executes an "ret" instruction when complete (why exercize the stack pointer?).

escapechar:
rcall SendESCMessage
W4DATA: wdr   ;Keep watchdog from timing out.
sbis usr,rxc  ;Wait for data in UART receiver.
rjmp    W4DATA  
in RFChar,udr ;Read data from UART.
rcall EmitUart ;Echo the character
rcall CRLF  ;Drop down one line.
cpi RFChar,$1B ;If escape key this time, send via RF link.
breq SB100  
andi RFChar,$5F ;Make upper-case character
cpi RFChar,'E' ;If an "E", then toggle local echo enable bit.
breq ToggleEcho
rjmp norsdata ;If not special to this program, drop it.

SB100: rcall crlf
rjmp SB1  ;Send by RF link then continue to service terminal.

ToggleEcho:
sbrc flagreg,0 ;Test local echo enable flag bit.
rjmp echoset
ori flagreg,1 ;Set local echo flag.
rcall EchoOnMsg ;Announce that local echo is on.
rjmp TEDone  ;Jump to toggle echo done.
echoset:
andi flagreg,0b11111110;Clear local echo flag
rcall EchoOffMsg ;Announce that local echo is off.
TEDone:
rjmp Terminal ;Go back to servicing the terminal/RF link/

EchoOnMsg:
ldi     ZH,high(2*EOM) ;Load high part of byte address into ZH.
ldi     ZL,low(2*EOM) ;Load low part of byte address into ZL.
rcall  sendstring ;Send greeting.
ret

EOM:    ;Text if Local Echo ON message.
.db     "Local Echo ON."
.db     $0A,$0D
.db     00,00



EchoOffMsg:
ldi     ZH,high(2*EOFFM);Load high part of byte address into ZH.
ldi     ZL,low(2*EOFFM) ;Load low part of byte address into ZL.
rcall  sendstring ;Send greeting.
ret
EOFFM:    ;ext if Local Echo OFF message.
.db     "Local Echo OFF. "
.db     $0A,$0D
.db     00,00


EmitUart:   ;Send RFChar via UART, preserves content of RFChar
sbis    usr,udre ;Wait for data to arrive.
rjmp    EmitUart    
out     udr,RFChar ;Send byte.
ret  


SendESCMessage:   ;Send message indicating that a first escape character was received.
ldi     ZH,high(2*ESCMsg);Load high part of byte address into ZH.
ldi     ZL,low(2*ESCMsg);Load low part of byte address into ZL.
rcall  sendstring ;Send greeting.
ret

ESCMsg:    ;Text of greeting.
.db     "ESC-"
.db     00,00


SayHello:   ;Power on/reset greeting routine.
ldi     ZH,high(2*Greeting);Load high part of byte address into ZH.
ldi     ZL,low(2*Greeting);Load low part of byte address into ZL.
rcall  sendstring ;Send greeting.
ret


sendstring:            ;Flash string send routine. Call with location of string in Z.
lpm                     ;Load byte from program memory into r0.
tst r0  ;Check if we've reached the end of the message
breq finisheds ;If so, return
mov RFChar,r0
rcall EmitUart ;Send the character via UART.
adiw ZL,1  ;Increment Z registers
rjmp sendstring ;Keep going until a $00 is reached.
finisheds:
ret


Greeting:   ;Text of power on/reset greeting.
.db     $0A,$0D
.db "VLF Terminal interface program vlfterm040715A "
.db     $0A,$0D
.db "www.projects.cappels.org"
.db     $0A,$0D
.db "Local echo is off, to toggle, type escape-e."
.db     $0A,$0D
.db     $0A,$0D
.db     00,00

crlf:    ;Send a carriage return and linefeed.
push RFChar
ldi RFChar,$0A
rcall EmitUart
ldi RFChar,$0D
rcall EmitUart
pop RFChar
ret


.exit   ;No assembly below this line.


AVR_Admin- 04-28-2006
Tiny Tuned Loop Antennas for the Minimum Mass Wireless Coupler

The basic Minimum Mass Wireless Coupler technology is described and links to other projects on this site that use the Minimum Mass Wireless Coupler are located on the web page, Minimum Mass Wireless Coupler.

Loop Antennas are considered to be "small" when their diameter drops below about 1/10 of the wavelength they are intended to be used at. In this case, I use the term "Tiny" because the antenna's diameter is about 1/30,000 the wavelength, and at 5.5 cm in diameter, they are quite small in human terms. Coils are one of the few components experimenters can easily do a good job of making for themselves, and the coil, with or without the core, is the major component in a resonant loop antenna.

The resonant loop antenna is fundamentally a parallel resonant LC circuit tuned to the carrier frequency. A coil, or in some cases coils, of wire form the antenna, which is usually mostly inductive, and a parallel capacitance is used to make the antenna resonant at the desired frequency. Time varying magnetic fields from the signal source that cross the coils of wire induce current in the loop, which results in a voltage across the output. The closer the incoming signal is to the loop's resonant frequency, the higher the output voltage.

Link to Site: http://cappels.org/dproj/minmassrfloop/loopantring.html

Forumer™ is Voted #1 Free Forum Hosting provider
Build your own community today with the largest message board hosting company.