Hello,
I'm trying to make a digital SWR meter to use for an automatic tuner for my stack.
My problem is the result of swr that is obtained by the sum of the forward voltage and reverse voltage (of a bridge reflectometric) divided by (their difference).
Help me please.
I'm trying to make a digital SWR meter to use for an automatic tuner for my stack.
My problem is the result of swr that is obtained by the sum of the forward voltage and reverse voltage (of a bridge reflectometric) divided by (their difference).
Help me please.
Code:
program adc_lcd
' *
' * Project name:
' Adc_On_Lcd
' * Copyright:
' (c) mikroElektronika, 2008
' * Revision History:
' 20080225:
' - initial release.
' * Description:
' This code demonstrates how to use library function ADC_read, and library
' procedures and functions for LCD display (4 bit interface)
' * Test configuration:
' MCU: PIC16F877A
' Dev.Board: selfmade
' Oscillator: HS, 4.000 MHz
' Ext. Modules: None
' SW: mikroBasic v7.1
' * NOTES:
' - Make sure you put the jumper on RA2 at A/D Converter Input (board specific)
' - Switch on LCD on SW9 (Lcd backlight)
' - Notice the change of ADC value on Lcd while you turn P1 (board specific)
' *
dim ch as byte
adc_rd as word
adc_rd1 as word
Text as char[17]
tlong as longint
ros as word
tlong1 as longint
main:
PORTD = 0 ' clear PORTD
TRISD = 0 ' designate PORTD as output (LCD is connected to PORTD)
INTCON = 0 ' disable all interrupts
Lcd_Init(PORTD) ' Lcd_Init_
Lcd_Cmd( LCD_CURSOR_OFF) ' send command to LCD (cursor off)
Lcd_Cmd(LCD_CLEAR) ' send command to LCD (clear LCD)
'Text = "mikroElektronika" ' assign text to string a
'Lcd_Out(1,1, Text) ' print string a on LCD, 1st row, 1st column
OPTION_REG = $80
ADCON1 = $82 ' configure VDD as Vref, and analog channels
TRISA = $FF ' designate porta as input
Delay_ms(2000)
Text = "Voltage: " ' assign text to string a
'Lcd_Out(2, 1, Text) ' print string a on LCD, 2nd row, 1st column
Lcd_Out(1, 16, "Vdir/Vrif")
Lcd_Out(2, 1, "R.O.S. = ")
while TRUE
adc_rd = ADC_read(0) ' get ADC value from 1st channel
tlong = adc_rd*5000
adc_rd = tlong >> 10
ch = adc_rd div 1000 ' prepare value for diplay
Lcd_Chr(1, 3, 48+ch) ' write ASCII at 1st row, 9th column
Lcd_Chr(1, 4, ".")
ch = (adc_rd div 100) mod 10
Lcd_Chr(1, 5, 48+ch)
ch = (adc_rd div 10) mod 10
Lcd_Chr(1, 6, 48+ch)
ch = adc_rd mod 10
Lcd_Chr(1, 7, 48+ch)
delay_ms(1)
adc_rd1 = ADC_read(1) ' get ADC value from 2nd channel
tlong = adc_rd1*5000
adc_rd1 = tlong >> 10
ch = adc_rd1 div 1000 ' prepare value for diplay
Lcd_Chr(1, 9, 48+ch) ' write ASCII at 2nd row, 9th column
Lcd_Chr(1, 10, ".")
ch = (adc_rd1 div 100) mod 10
Lcd_Chr(1, 11, 48+ch)
ch = (adc_rd1 div 10) mod 10
Lcd_Chr(1, 12, 48+ch)
ch = adc_rd1 mod 10
Lcd_Chr(1, 13, 48+ch)
delay_ms(1)
ros=(adc_rd+adc_rd1) / (adc_rd-adc_rd1)
'tlong1 = ros
'ros = tlong1 >> 10
ch = ros div 1000 ' prepare value for diplay
Lcd_Chr(2, 12, 48+ch) ' write ASCII at 2nd row, 9th column
Lcd_Chr(2, 13, ".")
ch = (ros div 100) mod 10
Lcd_Chr(2, 14, 48+ch)
ch = (ros div 10) mod 10
Lcd_Chr(2, 15, 48+ch)
ch = ros mod 10
Lcd_Chr(2, 16, 48+ch)
delay_ms(1)
wend
end.