1. ## ADC in 12F683; puzzled

I have started my second project, which is a temperature regulator.
My first project used one ADC channel, but I only used it as 8 bit ADC.
This time I thought that I needed 10 bits and specified that in the set up...

To test the first mock up, I set up a trip point of 512, which should be 2,5V.
-But it's not. By trying different numbers, I came to the conclusion that the ADC gives 13300 per Volt!??
What's up here? I'm totally lost!

2. Did you find this post helpful? |
Hi, Mike

How do you want us to give you any idea ???

Alain

3. Did you find this post helpful? |
Originally Posted by Acetronics

Alain
Right, of cource...

Code:
```
ANSEL = %00000011 'GP0 = AN0, GP1 = AN1

DEFINE ADC_BITS 10 'Set number of bits in result
DEFINE ADC_CLOCK 3 'Set clock source
DEFINE ADC_SAMPLEUS 50 'Set sampling time in us

time1 VAR WORD 'First time in seconds
time2 VAR WORD 'Second time in seconds
time3 VAR WORD 'Third time in seconds
involt1 VAR word 'Value for ADC0 (temp)
ut4 var bit 'Status for LED 4
ut5 var bit 'Status for LED 5
trip1 var word
trip1 = 13300 'Default value
trip2 var word
trip2 = 13300 'Default value

TRISIO = %11001011 'Defining PORT
GPIO = %00111000 'Turn off all LEDs
time1 = 0 'Zero time 1
time2 = 0 'Zero time 2
time3 = 0 'Zero time 3
ut4 = 1 'LED 4 = off (inversed)
ut5 = 1 'LED 5 = off (inversed)

loop1:
pause 100 'Wait 100 ms
IF involt1 >= trip1 THEN
GPIO.4 = 0 'Turn on LED4
else
GPIO.4 = 1 'Turn off LED4
endif
IF involt2 >= trip2 THEN
GPIO.5 = 0 'Turn on LED5
else
GPIO.5 = 1 'Turn off LED5
endif
goto loop1 'Go back to loop1
END```
trip1 = 13300 gives exactly 1V trip level. I don't mind having this kind of resolution, but it doesn't seem realistic.
Last edited by Acetronics2; - 21st September 2010 at 13:20.

4. Did you find this post helpful? |
Just guessing with your code, It looks like your result is left justified (or right) but in any event, you appear to be reading the the 2 LSB as bit 6,7 of your answer. since the 10 bit result is a word, you seem to have result high as valid 8 bits. but your result low is ddxxxxxx. So your LSB is really = dec128 and not 1!

How do i guess this? if you right shift your 13300 6 times, you get ~207. Assuming you are testing 0-5V you expect 1024/5=204 per volt. Pretty close.

If you need help understanding or fixing this, post code!

Sorry, we posted together
Last edited by cncmachineguy; - 21st September 2010 at 13:24. Reason: code posted while I was postng

5. Did you find this post helpful? |
Originally Posted by mikebike
Right, of cource...

trip1 = 13300 gives exactly 1V trip level. I don't mind having this kind of resolution, but it doesn't seem realistic.
Missing :

- Deactivate comparators

Alain

6. Did you find this post helpful? |
Originally Posted by Acetronics
Missing :

- Deactivate comparators
Is this specific for 10 bit ADC, or should it be there for 8 bit conversion as well?
And how? -CMON0 something?

Originally Posted by Acetronics
Missing :
Alain
Hm, the example programs that I have (for 16F877A) do not have such an instruction, does that PIC not need it?

ADCON0.7 = 1 seems to have have cured the problem, thanks guys.

7. Did you find this post helpful? |
Originally Posted by mikebike
Is this specific for 10 bit ADC, or should it be there for 8 bit conversion as well?
And how? -CMON0 something?
have a look to datasheet ... Comparator section !!!

Hm, the example programs that I have (for 16F877A) do not have such an instruction, does that PIC not need it?
some pins share the comparator and ADC functions ... you HAVE to verify which function is deactivated and which is to activate. ( one at a time ... )

Depends on the chip used - and the ports used ...

ADCON0.7 = 1 seems to have have cured the problem, thanks guys.
Full config done = NO suprise ...

sometimes, the pic defaults @ reset are the ones you want ... sometimes not. so you have to verify everything with the pic Datasheet !!!

8. Did you find this post helpful? |
Originally Posted by Acetronics
have a look to datasheet ... Comparator section !!!
Done that, but didn't understand it (new to this stuff).

Code:
`CMCON0 = %00000000`
seems to be accepted by PBP and the chip (still) works.

9. Did you find this post helpful? |
Originally Posted by Acetronics
sometimes, the pic defaults @ reset are the ones you want ... sometimes not. so you have to verify everything with the pic Datasheet !!!
Yes, I have had some interesting output signals on outputs that were not specified in the program!

10. Did you find this post helpful? |
Originally Posted by mikebike
Done that, but didn't understand it (new to this stuff).

Code:
`CMCON0 = %00000000`
seems to be accepted by PBP and the chip (still) works.
Boooooooooooooo .... the chip is really gentle with you ...

look a bit closer at the drawings and the corresponding config @ \$8 p 53 ...

Alain

11. Did you find this post helpful? |
I said that I don't understand this kind of data sheet...

Well, I think it says that .....000 only turnes the comp output off, but ....111 turnes the comp off as well. It doesn't matter much for this project, but my first project is battery operated and saving some current is welcome.

I guess it's nice to have a comparator integrated, but right now I would need an OP-amp instead!

12. Did you find this post helpful? |
Originally Posted by mikebike
I said that I don't understand this kind of data sheet...
!
I do promise you lots of fun ...

Swedish hot nights ... I believed it was a bit different

Alain

13. Did you find this post helpful? |
Not sure if you're sorted, but as someone who recently struggled with this very type of same thing, here are the 12F683 commands towards helping you out ...

If using 10 bit AtoD, then right justify is required**.....

.....whereas with 8 bit AtoD, left justify is required....

and finally this one....

CMCON0 = 0 (turns the pesky 12f683 comparator off - of course if you need the PIC's comparator, then it's not pesky at all & this command should not be used!)

Good luck!

** and no matter how many times I read the datasheet with respect to left/right justifying, I end feeling like an amoeba being wafted around the bottom of a refuse tip pond.
Last edited by HankMcSpank; - 23rd September 2010 at 16:35.

14. Did you find this post helpful? |
mikebike, Here is something I thru together last year for quick motor control pwn controller. Try it... The A/D works just fine.. You can get rid of the 64 samples...

Dave Purola,
N8NTA