Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

A/D Debounce

Status
Not open for further replies.

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
 
You don't need to debounce the AD, you need to debounce the switch. Google will give you about 50,000 hits searching for microcontroller switch debounce. I don't know if it's in any of the sticky posts on the forums here, but check Google and wikipedia FIRST.
 
What do you have connected to RA0?

BTW, do you realise that you are reading the ADC twice per loop.

Mike.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top