Learning about ADC

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

Post Reply
econnections
Posts: 35
Joined: Fri Dec 26, 2008 4:02 pm
Contact:

Learning about ADC

Post by econnections »

I have v2 Assembly for PICMicro and v2 development board. I would like to learn to use an ADC to monitor a thermister and send the data to the LCD.

There are no tutorials for this in v2 so can I upgrade to Assembly for PICMicro v4 and at what cost?

Can I use the 16F88 with the v2 development board?

Alternatively, are there any ADC assembly code examples on the site I can use with the 16F88 and stick with v2 software, although I would need the P16F88.inc file from somewhere?

I would also like to learn about serial communication.

What are my best options?

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Learning about ADC

Post by Benj »

Hello

Contact sales@matrixmultimedia.com for questions on upgrades and prices.

Yes you can use the 16F88 with the V2 dev board. ADC routines are fairly trivial if you look at the device datasheet then in the ADC section should be a step by step guide of how to program the code. You should also be able to find hundreds of examples by trawling google.

Same for serial communication. When I was learning PICs I printed off sections of the datasheet and read through them until I understood what was going on and what was required.

econnections
Posts: 35
Joined: Fri Dec 26, 2008 4:02 pm
Contact:

Re: Learning about ADC

Post by econnections »

Hi Ben,

I have been in touch with sales and will upgrade to Assembly for PICMicro v4 tommorrow when I have the license details.

I have tried reading the datasheets on ADC but they only particially helped. There's nothing quite like getting your teeth into a good training tutorial where you have a working example that you can play with. The upgrade will also supply the P16F88.inc file that I need.

Would I be right in thinking that PICs with limited port pins provide the digital output from the ADC as a serial feed on a designated pin which would be of no use to me if wanting to present this to the LCD, and other PICs present the data on an 8-bit port which I could then use?

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Learning about ADC

Post by Benj »

Hello

True its always nice to have a working tutorial to get up to speed with how the devices are meant to work.

ADCs on the PICs work to convert an incoming voltage on a single I/O pin into a number. The voltage is measured between the PIC chips VDD and VSS lines so normally this will be 0 - 5V. The ADCs are 10 bit but you can read them in 8 bit mode to give the following.

8-bit - 0 - 5V = 0 - 255
10-bit - 0 - 5V = 0 - 1023

Once you have done a ADC sample you can use your variable for anything you want eg transmitting via serial or sending to a LCD etc.

econnections
Posts: 35
Joined: Fri Dec 26, 2008 4:02 pm
Contact:

Re: Learning about ADC

Post by econnections »

So, at great cost I have upgraded to Assembly for PICMicro v4 professional and the v3 development board along with Flowcode and some other goodies.

I tested the board and software set-up by loading tutorial 29 and checking that a message was sent to the LCD - it was.

I loaded up tutorial 43 so I could get straight on and learn about setting-up and using the ADC. With the 16F88 installed I noticed one line of the LCD half filled with zero's but nothing else happened. The clock switch was set for XT and all the jumpers on J14 was set to digital. I tried rotating the pots but nothing happened. Not sure if RV3 is used in this project but something needs to apply a variable voltage.

Next I changed the PIC for the 16F877A and selected it in the software then downloaded. The LCD had a few less zero's showing but nothing else appears to happen and the tutorial doesn't tell me what to expect and if any jumpers need to be set.

It's now 03:35, I'm tired, I'm disappointed; I'm giving up, the excitement has all gone and I need my bed. Please help - I would love to be able to build my temperature sensor this weekend if only I can make the ADC tutorial work :twisted:
Last edited by econnections on Fri Feb 27, 2009 11:42 am, edited 1 time in total.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Learning about ADC

Post by Benj »

Hello

Think about what you just posted.
all the jumpers on J14 was set to digital
the Pot RV3 is connected to pin RA1 which uses ADC channel AN1. Therefore Jumper 1 of J14 must be moved to the analogue setting.

econnections
Posts: 35
Joined: Fri Dec 26, 2008 4:02 pm
Contact:

Re: Learning about ADC

Post by econnections »

Hi Ben,

The problem is the tutorial doesn't mention that I will be using RV3 to control the voltage or to set J14.1 to analogue and it should do so if that's required. Anyway I have made the changes and nothing appears to happen. I only see the following on the RHS of the LCD: 0000 _00000.

I also note from the code that both ch0 and ch1 are set and these connect to RA0 and RA1 respectively. Does that mean the ADC will also be sensing on RB1 and the LCD will be displaying two sets of data? There is no mention of changing J14 for this so I am very confused.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Learning about ADC

Post by Benj »

Hello

Sorry about not ringing back before you were back in work. I ended up getting called into a development meeting.

At the top of the tutorial is the following.
"This program is not intended to be run on the development board or for simulation on the Vlab."

This explains why the program does not run as is. Im not sure why this was included in the course. I will see if I can get any further with this.

I have incuded an example assembler program that will work on a 16F877A running with a 19.6608MHz crystal. If you need me to explain the code then let me know. It was generated from Flowcode so the assembler is not very readable. Sorry about this.
Attachments
Analogue.asm
(28.06 KiB) Downloaded 433 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Learning about ADC

Post by Benj »

Hello

Right here is the edited and fixed assembler file. Ill also post it up in the FAQ section.

There was a couple of problems with the file.

1) numeric values such as 15 were not being assigned correctly I changed these to D'15' or H'0F'

2) a few register addresses were incorrect so I have updated the address list and these values are now all ok.

I have added comments where you can edit the file to work with a 16F877A. Shouldn't have any problems in doing this. I have also removed the configuration words and instead of using these I am letting PPP do the work. So by clicking on the PIC spanner icon you should be able to autodetect your target device and assign the oscillator to XTAL operation. Once you have done this you can click the compile and send button to transfer your program.

Let me know if you have any problems with this.
Attachments
A43a.zip
(3.16 KiB) Downloaded 479 times

econnections
Posts: 35
Joined: Fri Dec 26, 2008 4:02 pm
Contact:

Re: Learning about ADC

Post by econnections »

Hi Ben,

That seems to work. Thank you for sorting the problem quickly.

I attached an LM35 digital thyrister to one of the channels and observed a reading of the LCD of around 240. The LM25 produces and output of 0.22volts at 22 degree C and changes by 10mV/C. Is it possible to change the reference voltage to the ADC so I get a value around 500 and how would I do this?

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Learning about ADC

Post by Benj »

Hello

Some chips have +VREF and -VREF inputs that can be switched on. Look at the pin diagram of the PICmicro you are using to see if it has this functionliaty. If the chip does have this feature then you can find the settings by looking at the ADC registers in the device datasheet.

Post Reply