![]() |
|
|||||||
| Proton Plus Compiler v3 Coding problems and general discussion related to the Development Suite |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Licensed User
![]() Join Date: Jan 2010
Posts: 46
![]() |
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
Nigel |
|
|
|
|
|
#2 |
|
Licensed User
![]() Join Date: Apr 2006
Location: Tulsa Oklahoma
Posts: 292
![]() |
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 |
|
|
|
|
|
#3 |
|
Licensed User
![]() Join Date: Jan 2010
Posts: 46
![]() |
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
Nigel Last edited by nigelb; 7th February 2010 at 17:37. |
|
|
|
|
|
#4 |
|
Licensed User
![]() Join Date: Jan 2010
Posts: 46
![]() |
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 |
|
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
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 |