Problem with TRIS?

Moderator: Benj

Post Reply
PicHead
Posts: 4
Joined: Thu Jul 26, 2012 1:41 pm
Has thanked: 4 times
Contact:

Problem with TRIS?

Post by PicHead »

Hi,
Total rookie with Flowcode, but 1st of all want to congratulate and thank all of Flowcode team for this excellent, easy to learn, PIC code development/programming app .....and of course allowing everyone the opportunity of downloading and testing with the restricted free version before committing to purchase the full version.

As stated before, "complete rookie here", so please forgive any silly queries that may be posted!

Input switch and LED must stay as active low due to the external hardware I would be interfacing with.

I have hit a major stumbling block with what may be an issue with "trissing" inputs and outputs within my flowcode program (attached)
It may also be, because I'm trying to use one i/o pin as both input and output. This is required by me, because I will eventually need up to 64 inputs and 64 outputs in my future design, therefore by utilising one i/o pin for both input and output, I would be able to use a 18f8310 PIC (64 i/o pins of its 70 i/o).

Basic problem is, my led will not stay permanently lite for the 255 countdown period.....it goes out as the program returns to top of the program loop.
As far "as I thought" I understood, when any PIC is switched on, (before config is loaded) all I/o are set to inputs, and when an i/o pin was "trissed" with a 0, that i/o pin would stay as an output until changed in coding (say by tris with 1) to an input?.....and vica/versa?
Is there something fundamental to PIC coding that I'm missing here?
eg. inputs and outputs not allowed on same pin?
......or is it, when my program returns to top and then checks it's input variable, it must tris i/o as a 1 first, to allow checking of this input variable.....hence switching LED i/o pin to input and causing led to go out?

It definitely seems to be a problem of having one i/o pin as both output and input, because if I move my LED to any another i/o pin, it works (stays on) 100%

Again, this may be, on my behalf, a "rookie" misunderstanding of PICs in general, but I have searched your forums, delved deep into the 16f877 datasheets and "Googled" for more detailed explanations on this tris issue before posting, to no avail.

I really hope you can shed some light and unravel this mystery for me.

Many thanks in advance for your help,
John.
Attachments
Flowcode1.fcf
(13.5 KiB) Downloaded 282 times

User avatar
DavidA
Matrix Staff
Posts: 1076
Joined: Fri Apr 23, 2010 2:18 pm
Location: Matrix Multimedia Ltd
Has thanked: 58 times
Been thanked: 258 times
Contact:

Re: Problem with TRIS?

Post by DavidA »

Hi,

I altered the program to direcly use inputs and outputs, dont know if this works how you want it, let me know.

Edit: i see the problem, this doesnt solve it, im afraid i dont know enough about PICs on this one, will query someone who knows a bit more.
Attachments
Flowcode1.fcf
(10 KiB) Downloaded 290 times

User avatar
DavidA
Matrix Staff
Posts: 1076
Joined: Fri Apr 23, 2010 2:18 pm
Location: Matrix Multimedia Ltd
Has thanked: 58 times
Been thanked: 258 times
Contact:

Re: Problem with TRIS?

Post by DavidA »

Additional question:

Is this in hardware or simulation?

PicHead
Posts: 4
Joined: Thu Jul 26, 2012 1:41 pm
Has thanked: 4 times
Contact:

Re: Problem with TRIS?

Post by PicHead »

Hi David,

Many thanks for your fast replies.
Yes it happens in both simulation and hardware. I did think that it may have been just a Flowcode sim problem, so sent the hex to chip, built the circuit on bread board, tied up the D0 pin to + rail via 10k resistor so that i/o pin D0 wasn't floating and it did exactly the same thing.....LED flickering
Another thought.....is it my Flowcode 5.1 freeware version by any chance? I see an upgrade to 5.2.......downloaded the file just now and tried to install on my free version but it returned error 1328 and a lot of files had to be ignored to get out of install, so no joy with upgrade either.

many thanks for all your efforts,
John

dazz
Posts: 1314
Joined: Sun Jan 15, 2012 3:15 pm
Has thanked: 474 times
Been thanked: 458 times
Contact:

Re: Problem with TRIS?

Post by dazz »

Hi
not exactly what you wanted to do but have you considered port expanders, ive attached a pdf, the mcp23017 has 16 ports and can be cascaded to 8 chips which gives 128 pins, so a smaller pic can be used it comes in 2 versions i2c or spi and although you will still have lots of wires to the pins you need the mcu can be fairly uncluttered

Regards
Dazz
Attachments
mcp23017.pdf
(669.97 KiB) Downloaded 295 times
To sign up to the V5 forum follow this link http://www.matrixmultimedia.com/forum_upgrades.php

PicHead
Posts: 4
Joined: Thu Jul 26, 2012 1:41 pm
Has thanked: 4 times
Contact:

Re: Problem with TRIS?

Post by PicHead »

Hi again DavidA and Dazz,

Appreciate your replies and suggested alternative solutions, many thanks

First ....to DavidA .....downloaded your recoding, but couldn't get it to run at all.....I think, I notice a couple of 1's in there that should be 0's but you've give me another angle on how to produce outputs and inputs, without using the simple component macro, so I'll recode using that method and try simulation and hardware tests......and let you know how it goes.....thank you.

To Dazz.....yes, that solution would probably work OK.....expanding i/o's and using a smaller PIC. .....but, unfortunately it leads to a larger pcb layout design, parts cost etc, plus doubling (128 wires to i/o's instead of 64) the manual hard wiring of my intended project. Also due to requiring to track and time each of my 64 outputs, individually, in my future final coding, I will need quite a large program memory space in my PIC, therefore, downsizing the PIC is most likely a no-go, unfortunately.

Don't get me wrong here, I really appreciate all thoughts and ideas put forward here, ......please keep them coming, thanks guys/girls

I just can't believe something this simple (1 switch and 1 LED) on a single i/o pin cannot be made to work (ie. LED to stay fully on) by straightforward trising the port.

regards,
John

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Problem with TRIS?

Post by medelec35 »

Hi John,
How long do u want port D0 to stay high for after you pressed and released switch?
I accept that simulation is not working however hardware is working correctly.
The reason you can't see it working is because the time you press and release switch is longer than the few hundred microseconds D0 is high for.
To prove that point, try attached file. I have set LED to stay on for 5 seconds only after switch is pressed and then released is not flickering at all.

Martin
Attachments
tris issue V2.fcf
(10.5 KiB) Downloaded 292 times
Martin

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: Problem with TRIS?

Post by Spanish_dude »

Here's my version :).
Don't know what that countdown is there for. I didn't use that.
Haven't tested it on breadboard but I'm fairly confident it will work.

Cheers,
Nicolas
Attachments
Flowcode1.fcf
(9.5 KiB) Downloaded 270 times

PicHead
Posts: 4
Joined: Thu Jul 26, 2012 1:41 pm
Has thanked: 4 times
Contact:

Re: Problem with TRIS?

Post by PicHead »

To Martin (Medelec35).....sorry for delay in returning reply,
........You have totally solved my problem!!!! Thank you so much for looking into and solving this issue.

How stupid I was.

Granted, there is a flaw in Flowcode simulation mode, ( ie. when I "trised" SWITCH/LED io to become an output by using the LED component macro , the LED would light in simulation mode but then on next Flowcode chart icon, the LED would immediately switch off.) which means that when running in simulation mode the LED blinks on and off.
.......then when I compiled my flowchart to hardware and it didn't seem to work either, I jumped to a conclusion that I had an issue with tris registers

Your diagnostics Martin was spot on......I overlooked the fact that my countdown for LED on time was way too short. My countdown from 255 to 0 had occurred by the time I had released the switch, therefore I was never going to see the LED on!!!!.... I really feel so stupid.
I also compounded the problem by running the hardware test at 4Mhz clock instead of my planned 32khz (ie 4Mhz clock = 1Mhz instruction cycle) which equates to 1 microsecond. If I average on approx 8 cycles when my program gets into coundown loop, that means that my LED would be lite for 8 x 1uS x 255 loops = approx 2 milliseconds. I would say that might be darn difficult for anyone to physically see, upon pressing the switch!!!!!! (unless they hook up an oscilloscope to the LED) .....stupid, stupid, stupid.....bangs head on wall......muttering "rookie, rookie, rookie"


To Flowcode admins / coders...... Can you tell me if this trivial simulation flaw is also within the latest fully licensed version 5.2? ie. do I have this problem because I'm running the free version?

Don't get me wrong, everyone reading this, I'm not here to find trivial faults with this excellent program, THIS IS an amazing application for quickly designing complicated project PIC code WITHOUT the need to have a masters degree in programming.

many thanks Medelec35, DavidA, Dazz, Spanish-dude and Flowcode team for all your help and rapid responses,
John.

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: Problem with TRIS?

Post by Spanish_dude »

Doing my version of your program I saw that too. Don't really know why the LED turns off even thought it's set to be on.
Anyways, it should work on hardware.

Nicolas

User avatar
JonnyW
Posts: 1230
Joined: Fri Oct 29, 2010 9:13 am
Location: Matrix Multimedia Ltd
Has thanked: 63 times
Been thanked: 290 times
Contact:

Re: Problem with TRIS?

Post by JonnyW »

Hello. With regard to the simulation issue, I believe this is down to the switch.

The components as they stand do not simulate TRIS - the switch always assumes it is on an input so holds the pin to its state. What you are seeing when the LED is forced off is the component code deciding the port should be cleared.

This will only be an issue when you have an input and an output connected to the same pin.

Jonny

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Problem with TRIS?

Post by medelec35 »

Hi John,
Your welcome.
Glad your sorted.
No need to feel stupid at all!
I know for a fact loads of things can easily get over looked, as I'm often guilty of that.
Hi Jonny,
That is a logical reason, thanks for your reply.

Martin
Martin

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: Problem with TRIS?

Post by Spanish_dude »

Woops, made a little error in my code :oops: .

The "prevswitchA0 = switchA0" should not be in a branch of the if-statement, but right after the if-statement.
Programs simulates perfectly when setting the switch to A1 and LED to A0, so it should work on hardware now :).

Nicolas

Post Reply