More Analog Questions from a Newbie....

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
Ron
Posts: 225
Joined: Wed Apr 11, 2007 6:15 pm
Has thanked: 2 times

More Analog Questions from a Newbie....

Post by Ron »

Hi,

I have written a little program and am having a HUGE issue!

16F886, 20MHz

The first thing I do is a while 1 loop.

Then I turn on RB7, LED.

I read Digital input RC0, test for RC0 = 1, if YES then Sample RA0, ReadAsInt RA0, loop back and check RC0 again.

My entire RB port goes to tri-state and RB0 is no longer when the switch is ON? RB7 goes OFF, I need it to stay on.

I have read the data sheet and can find no connection between PortC and PortB. I did find something called ANSEL and ANSELH that sounds like it could be the issue.

Can anyone help explain why PortB is going to Tri-state.

If I control an output on PortB below the analog sample and ReadAsInt then the port appears to stay a digital output port.

Please, someone explain what is going on.

I am trying to determine if it is an issue with me, a bootloader I am testing, flowcode, or something I am totally unaware of.

16F886 datasheet - section 3.4.1 says

"The ANSELH regiter (register 3-4) is used to configure the input mode of an I/O pin to analog. Setting the appropriate ANSELH bit high will cause all digital reads on the pin to be read as a '0' and allow analog functions on the pin to operate correctly.

The state of the ABSELH bits has no effect on the digital output function. A pin with TRIS clear and ANSELH set will still operate as a digital output, but the input mode will be analog. This can cause unexpected behavior when executing read-modify-write instructions on the affected port.

Is there anyone that can look at this simple program and tell me if I am doing something wrong, if it is flowcode, or more likely, the bootloader that I am testing.


UPDATE -

I think I am on the correct track about this special function regsister ANSELH. If I place the sample and read as int commands above the while = 1 loop to read the values only one time and then loop on my little flash the led program it all works properly.

If you Experts agree with my Newbie analysis of the situation my question would be, how do I prevent the bits from being changed from 1's (which is digital outputs, to 0's which means Inputs for PortB? I want to be able to read Analog on 5 PortA pins and 1 PortB pin, and have the rest of Port B stay Digital output till death do us part.

I have tested the problem code on an 18F2620 and it works perfectly, no ANSELH register that I can find.



Thanks

Ron

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:

Post by Benj »

Hello Ron

Are you using the latest version of Flowcode. I will email you with the latest FCD file. That should solve your problem.

Post Reply