Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

ADC problems on pic16F690

Status
Not open for further replies.

DavidLindh

New Member
Hello everyone,
I'm new to pic programing and I followed this tutorial but it's not working the way I expected.

Im using the PICkit2 programer and experimental card.


Question 1:
If I turn the pot to
0% i get 0,
on 50% I get 255,
on 51% I get 0,
on 75% I get 255,
on 76 I get 0 and
on 100% I get 255.

How do I get 0 at 0% and 255 at 100%?

Question 2:
How do I use 2 pots? One connected to RA0 and the other to RA1.

Thank you for the help
/David
 
The ADC has 10 bits of resolution, so the result doesn't fit into a single 8 bit register. The most significant bits of the result are in ADRESH. I think you'll find that you get 255 at 25% and 0 at 26% as well.

If you clear the ADFM bit, 8 bits of the result go into ADRESH, with only the two least significant bits in ADRESL. You can then just use ADRESH.

To use two pots, connect to RA0 and RA1. You can only read one at a time, each reading takes much less than 1ms.
 
Thank you for your answer.
I manage to solve the first question. I had right justified result activated so at first I only collected the two last bit.


My guess how to solve the second question is by

selecting AN0 output with the CHS0 to 3 bits in the ADCON0 register.
Read the results and save it to a variable.
Select AN1.
Read the result and save it to another variable.


I selected AN0 by setting all to 0 but how do I select AN1?
 
Ok, solved it. Was thinking on CHS1 as the second input and set ADCON0 to 0b00001000 when I should have set it to 0b00000100.


Now there is only one problem left but that have nothing to do with ADC.
Thank you again and here is some pictures of my project.
 

Attachments

  • moodlamp 2.jpg
    moodlamp 2.jpg
    665.8 KB · Views: 215
  • moodlamp 4.jpg
    moodlamp 4.jpg
    734.2 KB · Views: 181
  • moodlamp 3.jpg
    moodlamp 3.jpg
    547.7 KB · Views: 164
  • moodlamp 1.jpg
    moodlamp 1.jpg
    525 KB · Views: 190
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top