![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
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
__________________ I believe that you're wrong. Insinuating that they hold the bomb. --- | |
| |
| | #2 |
|
Did you try the AD logger program in JPUG#2?
| |
| |
| | #3 |
| 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. --- | |
| |
| | #4 |
| Because you might learn what you're doing?.
| |
| |
| | #5 |
|
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
Last edited by blueroomelectronics; 28th January 2009 at 05:24 PM. | |
| |
| | #6 | |
| Quote:
__________________ I believe that you're wrong. Insinuating that they hold the bomb. --- | ||
| |
|
| 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 |