Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 7th May 2008, 04:04 PM   (permalink)
Experienced Member
 
AtomSoft is just really niceAtomSoft is just really niceAtomSoft is just really niceAtomSoft is just really nice
Send a message via MSN to AtomSoft Send a message via Skype™ to AtomSoft
Default A/D Debounce

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
AtomSoft is online now   Reply With Quote
Old 8th May 2008, 03:18 AM   (permalink)
Experienced Member
 
Blog Entries: 1
Sceadwian is just really niceSceadwian is just really niceSceadwian is just really nice
Send a message via AIM to Sceadwian Send a message via Yahoo to Sceadwian
Default

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.
__________________
Curiosity killed the cat; That's why they have nine lives.

Sceadwian is online now   Reply With Quote
Old 8th May 2008, 03:23 AM   (permalink)
Experienced Member
Pommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to behold
Default

What do you have connected to RA0?

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

Mike.

Last edited by Pommie; 8th May 2008 at 03:25 AM.
Pommie is offline   Reply With Quote
Old 8th May 2008, 03:32 AM   (permalink)
Experienced Member
 
Blog Entries: 4
blueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to behold
Send a message via Skype™ to blueroomelectronics
Default

I think Swordfish has an oversample command for the AD. I'll have to look it up.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is offline   Reply With Quote
Old 8th May 2008, 11:17 AM   (permalink)
Experienced Member
 
AtomSoft is just really niceAtomSoft is just really niceAtomSoft is just really niceAtomSoft is just really nice
Send a message via MSN to AtomSoft Send a message via Skype™ to AtomSoft
Default

Quote:
Originally Posted by Pommie
What do you have connected to RA0?

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

Mike.

Just really noticed that thanks will see it replacing it with AdTmp will help...
AtomSoft is online now   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
555 timer as A/D converter raviram87 Electronic Projects Design/Ideas/Reviews 4 7th April 2008 04:00 PM
Button Debounce Coding help Suraj143 Micro Controllers 25 4th August 2007 09:48 AM
Please help me in writing code abdosat2000 Micro Controllers 9 5th June 2007 01:40 PM
Any simple debounce code? NewGeek Micro Controllers 6 1st September 2004 03:00 PM
Switch debounce circuit-please help!! elec123 Electronic Projects Design/Ideas/Reviews 3 27th March 2004 02:30 AM



All times are GMT. The time now is 05:55 AM.


Electronic Circuits  |  Radio Controlled
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.