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.

Dual Input ADC Program using PIC16F88

Status
Not open for further replies.

Steve311

Member
Hello All; I am in need of some help. I have a program which has two analog inputs (X= AN3 and Y= AN4). The program should determine if 2V < X < 3V and 4V < Y < 5V. If both conditions are met, The output at pin RB0 should be held HIGH. If one of the two conditions are NOT met, then the output at pin RB0 should toggle between HIGH/LOW.

I think my problem is arising when the ADC goes to read the second input because when I run the program with just the X input, the program and PIC both work fine.

Attached is my .asm file if anyone would be so kind to take a quick look. Thank Again.
Steve
 

Attachments

  • A_D Conversion Code ver2.asm
    12.6 KB · Views: 203
Can I ask you something is this all your wanting to do
Version 1: Simple ADC program to read one analog input at AN4 and send its
; coresponding 8 bit output to PORTB respectively (RB0 - RB7).

If so that's a lot of code to do just that all you need to do is move adc result

adc_result then move to PORTB

Code:
     swapf     ADRESH,w       ; Copy the display to the LEDs
     movwf     PORTB
     goto      MainLoop

You could use part that mike added to my code to get nice values with out jitter

Take sample A run it threw the test output that then .
Take sample B run it threw the test output that go back to main.
 
Last edited:
Hi Burt; Thanks for your response. Sorry, the revision history on that version of the .asm was not updated properly. My fault, here is what I am trying to do with the program:

1) Read analog input 1 (X) from AN4, store the value
2) Read analog input 2 (Y) from AN3, store the value
3) Perform conditional statements to determine if 2V < X < 3V and 4V < Y < 4.5V
-If both conditions are true; Output a logic1 to pin RB0
-If EITHER one of the above conditions are met, then toggle the output at RBO (High to Low)...for enough time to measure with a DMM.

I know the code may be messy right now. I am not at home and unfortunately do not have a cleaner copy to attach at the moment. I will post it asap.

I think my issue is coming from reading the second analog input (Y).

Thanks Again for your interest!
-Steve L
 
Hi Again Burt; I realize now that I did post a new version of my code for the same issue. It is under the following Thread Title:


ADC Data manipulation with PIC16F88 -- HELP!

There is a ver3.asm attached. Any help is greatly appreciated.

Steve
 
I look at it but ericgibbs is the Oshonsoft simulator man I never liked Oshonsoft

I did look at it it still looks like a lot of code to just do what you want. I haven't used asm in a year been working with Jalv2
and Swordfish basic for the 18f chips

Any way it looked like it should work so I dug out a 16f88 and going to try to see what happens in real life let you know
to night
 
Great Burt thanks alot. Yeah; I notice Eric Gibbs with the Oshnsoft simulator....it looks pretty gory. I wish MPLAB sim had a stimulus/debug for using an ADC. Too bad it doesnt.

I know my code isn't "top notch" by any means...I am actually an RF guy and had slight experience with Assembly language/PICs back in college. Normally when I do side projects involving PICS...its all basic digital input/outputs with not much brains. So my programming skill is still at a minimum. I just love PICs and I love what they can do, so as I get spend more time with this, hopefully I can clean up my code some.

But Thanks again, and I look forward to hearing what your results are! I'll talk to you later.

-Steve
 
If you have a debugger like the pickit2 you can debug the 16f88 with it in real time. Read page 149 of the data sheet
 
Burt; I just wanted to give you a heads up...don't spend too much more time on looking into my code for the time being. I had mentioned to you I didnt think I was reading the second analog input and I figured out why. I had the GO_DONE bit set, then a loop to allow the internal capacitor to charge for the next conversion. Looks like the issue came down to setting a delay loop BEFORE i set the go_done bit.

But anyway, thanks again for your help so far and I will defintely be in touch if i have more issues!

Regards,
Steve
 
I figured it would be something like that because your code looked ok. Glad you found that.
 
Status
Not open for further replies.

Latest threads

Back
Top