<h1>THE FORUM HAS MOVED,  VISIT US AT OUR NEW SITE www.picbasic.org. Access to this Archive is restricted. Visit the NEW site at www.picbasic.org.  Unless you use the url http://www.picbasic.org you will not gain access to the support forum, wiki and knowledge base. Visit WWW.PICBASIC.ORG  Do not try to log in or register here, use your keyboard and enter the url http://www.picbasic.org directly into your browser. </h1>  

Go Back  

THE FORUM HAS MOVED, VISIT US AT OUR NEW SITE www.picbasic.org. Access to this Archive is restricted. Visit the NEW site at www.picbasic.org. Unless you use the url http://www.picbasic.org you will not gain access to the support forum, wiki and knowledge base. Visit WWW.PICBASIC.ORG Do not try to log in or register here, use your keyboard and enter the url http://www.picbasic.org directly into your browser.

> Proton Development Suite > Proton Plus Compiler v3

Proton Plus Compiler v3 Coding problems and general discussion related to the Development Suite

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
Old 7th February 2010, 17:03   #1
nigelb
Licensed User
 
Join Date: Jan 2010
Posts: 46
nigelb is on a distinguished road
Default Help with ADC code

Hi....could someone please just tell me if the following code is ok....it seems very simple to me and so I don't trust that I'm going about this the right way!

The declares are in the section above the start section, where dims and symbols are etc. The sampling code is obviously in its own section within the main code.

I have set up the adc port and ADCON0/1 registers ok so I'm not worried about them.

sample1/2/3 are byte, adcvalue is a float.

I am assuming (hoping) that the ADIN command takes care of the MSB/LSB malarky and Bob's your uncle....help! lol


Code:
DECLARE ADIN_RES 10     ;Using 10bit ADC
DECLARE ADIN_STIME 50   ;Allow 50us sample time

;Get first sample and store
    sample1 = ADIN 0       ;Place the conversion into variable
    DELAYUS 1

;Get second sample
   sample2 = ADIN 0
    DELAYUS 1
    
;Get third sample
    sample3 = ADIN 0
    DELAYUS 1

;Calculate average
   adcvalue = sample1 + sample2 + sample3
Many thanks in advance

Nigel
nigelb is offline   Reply With Quote
Old 7th February 2010, 17:35   #2
dmTulsa
Licensed User
 
Join Date: Apr 2006
Location: Tulsa Oklahoma
Posts: 292
dmTulsa is on a distinguished road
Default

I think Sample 1/2/3 should be words since your reading in 10 bits. I believe that its right justified by default. I didn't run the sample but it looks ok if you change Sample to a word.

I did a write up about ADC readings http://www.picbasic.org/forum/showthread.php?t=12798 This is a much better way than averaging

Doug
dmTulsa is offline   Reply With Quote
Old 7th February 2010, 17:35   #3
nigelb
Licensed User
 
Join Date: Jan 2010
Posts: 46
nigelb is on a distinguished road
Default Update - code was missing some lines!

Code should read additionally as follows for all 3 samples and final calc

Sorry to be so messy, but the edit option for the firt post has disappeared !

Code:
;Get first sample and store
    GO_DONE = 1              ;Start conversion
    WHILE GO_DONE = 1 : WEND  ;' Poll the GO_DONE flag for completion
    sample1 = ADIN 0       ;Place the conversion into variable
    DELAYUS 1


;Calculate average
   adcvalue = (sample1 + sample2 + sample3) / 3
Thanks again

Nigel

Last edited by nigelb; 7th February 2010 at 17:37.
nigelb is offline   Reply With Quote
Old 7th February 2010, 22:24   #4
nigelb
Licensed User
 
Join Date: Jan 2010
Posts: 46
nigelb is on a distinguished road
Default Panic over

Dear all......it's tough being an idiot

After trying all manner of code variations to get something out of the ADC and onto my 7seg display I finally discovered the problem........

While working on a bit of my program I had switched 'off' the anode transistors in a section of the code then, when writing in the ADC code with a jump to another section to flash the segments at a certain ADC value (for test purposes), I had missed the point that the anodes where not powered up......GOOD GRIEF.....

Powered up the anodes and bingo....result !!

It's always the simple things that get you.....grrrrrr !!

Nigel
nigelb is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On


Similar Threads
Thread Thread Starter Forum Replies Last Post
External Font not working. C_Moore Proton Plus Compiler v3 14 13th December 2008 17:11
Dig problem dolci Proton Plus Compiler v3 8 25th October 2007 13:19
Font Converter FabioPedro The Lounge 7 29th May 2007 19:22
Pprint FabioPedro The Lounge 18 21st April 2007 18:09
Right2Left Alignment On a GLCD SELCUK Proton Plus Compiler v3 2 11th April 2007 07:40


All times are GMT +1. The time now is 09:35.



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright © Crownhill Associates Limited 2002 - 2009