Author | Rob Jansen, Copyright © 2018..2018, all rights reserved. |
Adapted-by | Rob Jansen, small bug fix in transmiter. |
Compiler | 2.4q6 |
This is the transmit only version of Virtual_Wire, see the file virtual_wire.jal for all changes compared to the original Virtual_Wire library and more information.
http://www.airspayce.com/mikem/arduino/VirtualWire.pdf
-
No dependency found
const byte VW_HEADER_LEN = 8
var byte vw_tx_bit = 0
const byte VW_RAMP_ADJUST = 9
const byte VW_RX_RAMP_LEN = 160
const byte VW_SPEED_1000 = 250
const byte VW_SPEED_2000 = 125
const byte VW_RAMP_INC_RETARD = (VW_RAMP_INC - VW_RAMP_ADJUST)
const byte VW_RAMP_INC_ADVANCE = (VW_RAMP_INC + VW_RAMP_ADJUST)
var bit vw_tx_enabled = false
const byte VW_RX_SAMPLES_PER_BIT = 8
const byte VW_MAX_PAYLOAD = VW_MAX_MESSAGE_LEN - 3
var byte vw_tx_rx_buf[VW_MAX_MESSAGE_LEN * 2]
const byte symbols_c[] =
const byte vw_tx_header_buf[VW_HEADER_LEN]
var byte vw_tx_index = 0
var byte vw_tx_len = 0
var bit vw_tx_header = false
var word data_2
var byte vw_tx_sample = 0
const byte VW_RAMP_INC = (VW_RX_RAMP_LEN/VW_RX_SAMPLES_PER_BIT)
const byte VW_RAMP_TRANSITION = VW_RX_RAMP_LEN/2
const byte VW_HEADER_LEN = 8
Outgoing message bits grouped as 6-bit words 36 alternating 1/0 bits, followed by 12 bits of start symbol Followed immediately by the 4-6 bit encoded byte count, message buffer and 2 byte FCS Each byte from the byte count on is translated into 2x6-bit words Caution, each symbol is transmitted LSBit first, but each byte is transmitted high nybble first
var byte vw_tx_bit = 0
Bit number of next bot to send
const byte VW_RAMP_ADJUST = 9
Internal ramp adjustment parameter
const byte VW_RX_RAMP_LEN = 160
The size of the receiver ramp. Ramp wraps modulo this number
const byte VW_SPEED_1000 = 250
Selection of bitrates.
const byte VW_SPEED_2000 = 125
2000 bits/second
const byte VW_RAMP_INC_RETARD = (VW_RAMP_INC - VW_RAMP_ADJUST)
Internal ramp adjustment parameter
const byte VW_RAMP_INC_ADVANCE = (VW_RAMP_INC + VW_RAMP_ADJUST)
Internal ramp adjustment parameter
var bit vw_tx_enabled = false
Indicates if the transmitter is active.
const byte VW_RX_SAMPLES_PER_BIT = 8
Number of samples per bit.
const byte VW_MAX_PAYLOAD = VW_MAX_MESSAGE_LEN - 3
The maximum payload length, count (1) and FCS (2) must be subtracted.
var byte vw_tx_rx_buf[VW_MAX_MESSAGE_LEN * 2]
Transmit and receive buffer. The symbol buffer for transmission is combined with the data buffer for reception.
const byte symbols_c[] =
4 bit to 6 bit symbol converter table for coding Used to convert the high and low nibbles of the transmitted data into 6 bit symbols for transmission. Each 6-bit symbol has 3 1s and 3 0s with at most 3 consecutive identical bits
const byte vw_tx_header_buf[VW_HEADER_LEN]
Transmit header to synchronize the receiver.
var byte vw_tx_index = 0
Index of he next symbot to send. Ranges from 0 to VW_Tx_Len
var byte vw_tx_len = 0
Number of symbols in VW_Tx_Buf to be sent
var bit vw_tx_header = false
Indicates that the header must be transmitted first.
var word data_2
No documentation found
var byte vw_tx_sample = 0
Sample number for the transmitter. Runs 0 to 7 during one bit interval.
const byte VW_RAMP_INC = (VW_RX_RAMP_LEN/VW_RX_SAMPLES_PER_BIT)
Ramp adjustment parameters Standard is if a transition occurs before VW_RAMP_TRANSITION (80) in the ramp, the ramp is retarded by adding VW_RAMP_INC_RETARD (11) else by adding VW_RAMP_INC_ADVANCE (29) If there is no transition it is adjusted by VW_RAMP_INC (20) Internal ramp adjustment parameter
const byte VW_RAMP_TRANSITION = VW_RX_RAMP_LEN/2
Internal ramp adjustment parameter
timer2_interrupt()
This is the interrupt service routine called when timer1 overflows Its job is to output the next bit from the transmitter (every 8 calls) and to call the PLL code if the receiver is enabled
vw_setup(byte in bitrate)
This procedure initialized the timer 0 that is used for creating the pulse time interrupt. This has to be VW_RX_SAMPLES_PER_BIT times the bit time.
vw_tx_stop()
Stop the transmitter, call when all bits are sent
vw_wait_tx()
Wait for the transmitter to become available Busy-wait loop until the ISR says the message has been sent
_vw_timer_setup(byte in bitrate)
Intialize Timer 2 to generate the RF bit time.
vw_send(byte in buf[], byte in len) return bit
Wait until transmitter is available and encode and queue the message into vw_tx_buf The message is raw bytes, with no packet structure imposed It is transmitted preceded a byte count and followed by 2 FCS bytes
vw_tx_active() return bit
Return true if the transmitter is active
_vw_calc_crc(word in crc, byte in data) return word
Calculate new crc over given data. Formula is: Xexp16 + Xexp12 + Xexp5 + 1
16f1825 | 16f1825_virtual_wire_transmitter.jal |