AtomSoft
Well-Known Member
Hello all im trying to get this A/D Conversion down pack im using swordfish just because it saves time and coding... The issue is when i press a button i get multiple values sometimes even with a delay.
Code:
{
*****************************************************************************
* Name : UNTITLED.BAS *
* Author : Jason *
* Notice : Copyright (c) 2008 AtomSoft *
* : All Rights Reserved *
* Date : 5/7/2008 *
* Version : 1.0 *
* Notes : *
* : *
*****************************************************************************
}
Device = 18F448
Clock = 20
Config OSC = HS
Include "usart.bas"
Include "convert.bas"
Include "ADC.bas"
Dim LED As PORTA.0
Dim AdTmp as word
function Get_ADC_Sample() as word // Function to grab the ADC sample
result = ADC.Read(0) // Grab an ADC sample from channel 0
result = result * 2 // Scale the answer up by a factor of 3
end function
Sub Print(pStr As String)
USART.Write(pStr, 13, 10)
End Sub
SetBaudrate(br19200)
Input(PORTA.0)
High(LED)
DelayMS(500)
While True
adtmp = Get_ADC_Sample
DelayMS(10)
if adtmp <= 2046 then
Print("")
Print("RA0")
Print("---------------------- ")
print(DecToStr(Get_ADC_Sample))
Print("---------------------- ")
end if
Wend