![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | Thread Tools | Display Modes |
| | (permalink) |
| Experienced 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 |
| | |
| | (permalink) |
| Experienced Member | 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. |
| | |
| | (permalink) |
| Experienced Member | 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. |
| | |
| | (permalink) |
| Experienced Member | I think Swordfish has an oversample command for the AD. I'll have to look it up. |
| | |
| | (permalink) | |
| Experienced Member | Quote:
Just really noticed that thanks will see it replacing it with AdTmp will help... | |
| | |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| | ||||
| 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 |