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
 
Tools
Old 26th January 2009, 06:14 PM   #1
Default Usart + Adc

Ive gotten the ADC to work to control the blink rate of a LED, but now I want to try and read the ADC value via USART on my Junebug. Ive gotten it to "talk" with the computer, but It gives me Funky stuff (numbers/letters/symbols) instead of the values I want. Im using a PIC18F1320 and using the pots on the junebug as my voltage source for the ADC.

Code:
Device = 18F1320
Clock = 4 // 4MHz clock
Config OSC = INTIO2, WDT = OFF, LVP = OFF

Include "IntOsc4.bas"
Include "ADC.bas"
Include "USART.bas"
Include "convert.bas"

    
Function Get_ADC_Sample() As Float   // Function to grab the ADC sample

    result = ADC.Read(1)     //grab a voltage from channel 1 and convert it
    result = (result +1)*500
    result = result / 1024
End Function

SetBaudrate (br9600)

   
While True                         // Create an infinite loop
USART.Write ("DC Volts = ",Get_ADC_Sample ,13,10)
DelayMS (500)
        
Wend
Note "IntOsc4.bas" is the basic file for the internal osc running at 4Mhz
__________________
I believe that you're wrong.
Insinuating that they hold the bomb.
---
Overclocked is offline  
Old 26th January 2009, 06:44 PM   #2
Default

Did you try the AD logger program in JPUG#2?
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/
blueroomelectronics is offline  
Old 28th January 2009, 05:04 PM   #3
Default

Quote:
Originally Posted by blueroomelectronics View Post
Did you try the AD logger program in JPUG#2?
Yes, but why not use adc.bas rather than setting up the AD converter "manually"?
__________________
I believe that you're wrong.
Insinuating that they hold the bomb.
---
Overclocked is offline  
Old 28th January 2009, 05:19 PM   #4
Default

Quote:
Originally Posted by Overclocked View Post
Yes, but why not use adc.bas rather than setting up the AD converter "manually"?
Because you might learn what you're doing?.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is online now  
Old 28th January 2009, 05:22 PM   #5
Default

I've edited Gramo's ADC code to get it working with the Junebug.
Spency's digital-diy 18F PIC micro Tutorial - ADC

PS I think the problem with your program has to do with float vs integer math. I've found myself having all sorts of weird results until I make sure all my variables are of the same type.
Code:
Device = 18F1320
Clock = 4
Config OSC = INTIO2, WDT = OFF, LVP = OFF

Include "USART.bas"
Include "ADC.bas"
Include "convert.bas"

Dim ADVal As Word
// Read the AD port and scale for 0.00 - 5.00 volts...
Function ADInAsVolt() As Word
    result = (ADC.Read(1) + 1) * 500 / 1024
End Function
// Start Of Program...
OSCCON = $62    ' 4MHz internal clock
SetBaudrate (br9600)

// main program loop...
While true
    ADVal = ADInAsVolt
    USART.Write("DC Volts = ", DecToStr(ADVal / 100), ".", DecToStr(ADVal, 2), " ",13,10)
    DelayMS(500)
Wend
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/

Last edited by blueroomelectronics; 28th January 2009 at 05:24 PM.
blueroomelectronics is offline  
Old 28th January 2009, 06:35 PM   #6
Default

Quote:
Originally Posted by blueroomelectronics View Post
I've edited Gramo's ADC code to get it working with the Junebug.
Spency's digital-diy 18F PIC micro Tutorial - ADC

PS I think the problem with your program has to do with float vs integer math. I've found myself having all sorts of weird results until I make sure all my variables are of the same type.
Awesome, that works. Thanks =D
__________________
I believe that you're wrong.
Insinuating that they hold the bomb.
---
Overclocked is offline  
Reply

Tags
adc, usart

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
usart with pic neelam29 Micro Controllers 19 18th July 2009 09:39 AM
Pic16f877a-usart tio_rafael Micro Controllers 5 16th June 2007 06:47 PM
PIC USART: Help Please mortuzahasan Micro Controllers 2 11th February 2007 07:28 PM
HELP!!! nothing going through my USART!!! Guyver Micro Controllers 8 6th May 2004 09:11 AM
Usart to Usart? Eclipsed General Electronics Chat 7 23rd October 2003 05:07 PM



All times are GMT. The time now is 09:50 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker