HELP! - Simulates perfectly but not on breadboard

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

HELP! - Simulates perfectly but not on breadboard

Post by christoph »

Hi all,
The attached flowchart simulates exactly as required but I am getting no outputs from port A when breadboarded. All 'rules and regs' have been followed and checked with PIC data. The same chip works perfectly in simulation and on the breadboard if re-programmed to just receiving the RS232 Data and lights the Port A LED correctly, according to the binary number sent. A new chip acts the same which indicates there isn't a hardware problem. The problem arose after adding the latching for the 3 pushbuttons but I dont see how it would affect the Port B binary data outputs! I have checked the output pins and they read zero volts (nominal operating voltage is 3.3 on my breadboard supply). Also, L3 LED is ON at the start when run on the breadboard which as one sees on simulation should not be the case. Neither do the PB1, 2 & 3 pushbuttons work on breadboard but DO in simulation.

Operation is: No Data = No LEDs lit.. Data zero and 255 = no LEDs lit. Data 1 to 254 = appropriate binary LEDs lit plus L1 & L2 and data 'locked to prevent any other data change. At this point it is possible to switch OFF/ON/OFF/ON...etc. L1 & L2 at will. L3 can be switched ON/OFF/ON/OFF etc. at any time before or during any Data input.

I have tried 'everything and have no idea what else to try.

Would really appreciate it if someone could suggest what needs tweaking.

Many thanks in advance,

Chris

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: HELP! - Simulates perfectly but not on breadboard

Post by medelec35 »

Hi Chris,
To me it looks like when data is>0 for the first time then your flowchart will be in a forever loop!
It will always be sent back to connection point A
So not sure how it simulates perfectly, unless I'm missing something?

Also I would highly recommend using the RX interrupt for receiving data.
Then no data will be missed.
For simulation purposes RX Interrupt does not simulate, so for simulation purposes only,you will need to add a call macro
Don't forget to delete it before compiling to target device.

Also you have the read switches & masking function duplicated.
It's good practice to use a separate macro for the repeated function.

I can post a modified flowchart if you like?

So have I got the principle correct:
on start up, if data is received and between 1 and 254 then sent to portB.
L1 & L2 light.
No data can be received (if data is transmitted it's ignored). If any switch is pressed then data can be received.

While waiting for data only PB3 can be pressed (Which changes stated of L3) , and if L3 is on then no data can be received.
Data can only be received if L3 is out.
?

Martin
Martin

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: HELP! - Simulates perfectly but not on breadboard

Post by medelec35 »

Hi Chris,
I have modified your flowchart.
Not sure if it will work the way you want it to or not?
if you leave it as is then its for simulation only.
If you want to compile to chip then you must delete the call macro.

Martin
Attachments
HELP - Simulates perfectly but not on breadboard V2.fcf
(19.35 KiB) Downloaded 434 times
Martin

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: HELP! - Simulates perfectly but not on breadboard

Post by christoph »

Hi Martin,
Thankyou so much for your post. Sorry I didn't answer sooner but out until just now so I have only just logged in and so not tried your flowchart yet but before doing so, I have a feeling that maybe it might need a slight adjustment if I clarify the operation in more detail. (I find this grey area between simulation and breadboarding to be a real challenge because I dont know whether it is the software, the hardware or what that is causing the problem).

Clarification of the operational aim:-

1) Basically it is just a 'First-UP-Alarm''. ONLY the first binary number received is locked and held and turns ON L1 and L2 at the same time.
2) L1 and L2 are simply representing outputs that will ultimately be connected to two different area audible alarms and PB1 and PB2 are their respective mute pushbuttons (but can be pushed again to turn the appropriate L1 and L2 alarms alternately ON and OFF at will).
3) L3 is simply representing an output operated by the ON/OFF/ON/OFF etc pushbutton PB3 which will be used to turn on the lights in the same two areas but is required ALL of the time and is totally independant of the alarms themselves. It is operable at any time the chip is powered up regardless of alarm data being received or not.

a) When chip is powered up, nothing must happen.
b) In the unlikely event of a 0 or 255 being received, nothing must happen either.
c) If any number from 1 to 254 is received though, item 1) above, takes place and no further received data is to be acted upon and that specific binary number is 'locked in'. (although, as you can see, it will still be able to RECEIVE data and store it but that is no problem and might be useful sometime in the future).

Reset is simply a 'power off and back on' action.

I will certainly look through your flowchart now but will just hold off programming chip and trying it until you have seen if my post may adjust some part of it.

Thanks everso for looking at this one'

Best regards,

Chris

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: HELP! - Simulates perfectly but not on breadboard

Post by christoph »

Hi again Martin,

I have run the flowchart simulation and it isn't running quite as intended but my last post describes the way it works more clearly I think.

THIS might help - ignore if not - but....

Yes, the intention WAS to loop from power up UNTIL the binary number was received (and prevent it going to 'A' but that is why I have the 'Read Switch' part in that loop because I need to be picking up the ON/OFF/ON etc. of PB3 right from the start and regardless of data received or not). ONLY when the binary number is received, will it proceed to the 'A' loop where I need L1 and L2 lit but the next Pb1 and PB2 presses have now to start from 1's (not 0's) so that when pressed they indicate 0's and turn OFF L1 and L2. That is why there are two 'read switch' loops.

Sorry Martin, I think just the previous post will probably be clearer!! - but I will send this anyway, now I've written it...

Chris

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: HELP! - Simulates perfectly but not on breadboard

Post by medelec35 »

Hi Chris,
Have changed the flowchart to what I believe to be what you're describing?

It's just a starting point, this one will allow you to capture any data for storage after 1st data has been received.

Hope it works the way you have intended, if not then I can change it.

Clever storage can be done if required later.

It will not change value going to port or enable data until power is reset.
This flowchart will let that be changed if necessary.
E.g perhaps by pressing two switches simultaneously or long pressing a switch?

Note for simulation purposes I have added key mapping to the switches.
So when running or single stepping during simulation, just press 1 to 3 on keyboard to operate each switch respectively.

If simulation works but hardware does not then we should start investigating your hardware.

It would make things easier if you can post a full circuit diagram.

Martin
Attachments
HELP - Simulates perfectly but not on breadboard V3.fcf
(17.76 KiB) Downloaded 412 times
Martin

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: HELP! - Simulates perfectly but not on breadboard

Post by christoph »

Hi Martin,

Yes, that is spot on and exactly as intended and I will give it an airing on the hardware shortly.

Just as a matter of interest, what I find a bit difficult to understand, is that I use Flowcode because I dont want to get into all the interesting but time consuming aspects of programming languages. Therefore, I have always thought that if the Flowcode simulation works OK but it doesn't work on the hardware, then the hardware was the problem. When I first started THIS particular project, I got it up and running correctly in simulation with no problem but I selected 'LATCHED' for the push button operation and then spent hours trying to find out why it wouldn't work on the breadboard! After I had made sure there wasn't a HARDWARE problem, I turned to the web and forumto see if I could get any clues before posting on it. I happened to follow a link to a YOU-tube clip about something to do with Flowcode and during the video there was a 2 second comment that the push button operatos (including LATCHING) were only for simulation - and of course I was using them and that's whyit didn't work on the breadboard! The buttons themselves worked ok as momentary inputs but of course they didnt LATCH. Hence the inclusion of the latching arrangement that you saw in my original flowchart post. You have also mentiond other things differing between simulation and real world results like the "Rx interrupt not simulating and therefore needs a macro" - how does one know this?? This could explain why I have some of the problems I come up against. I was wondering if there anywhere I can look to see what ONLY simulates and needs a 'work-arounds' for hardware? The problem is that a 'work-around itself might not work and it all becomes a bit complicated!

Chris

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: HELP! - Simulates perfectly but not on breadboard

Post by medelec35 »

Hi Chris,

Glad flowchart posted simulates as intended. :)

Re Switches:
You have to select the type of switches within simulator that match your hardware.
So if you have momentary switches on your hardware then you should select momentary switch on the simulator.

Simulator is just a simulator so if you have momentary switch for hardware and select latching within simulator, then it will not convert your hardware momentary switch into a latcing operation since the simulator does not know what hardware you have got.

Timers:
Only timer0 simulates with Flowocde V4, but with newer versions Most timer interrupts simulate.
C code:
No version of flowcode simulate C code.
Most of the components do simulate ok.
It's Flowcode V6 where simulation is take to the next level.

If you're not sure what simulates then just ask.

Martin
Martin

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: HELP! - Simulates perfectly but not on breadboard

Post by christoph »

Hi Martin,

OK I understand and note what you say - thanks for that.

I have now re-programmed the chip but unfortunately it doesnt work on the hardware. I get no binary output on any of Port B or L1, L2 or L3 and push buttons dont change L1, L2 or L3 either.

I re-programmed the SAME chip with my original flowchart which simulates OK (but the momentary push buttons dont latch - and of course I know why now!) AND it DOES light the binary LEDs on Port B and L1 and L2 but not L3 and the PUSH buttons have no effect although I will double check the switches by by-passing each one directly, when I have posted this.

I have attached the appropriate flowchart for you to see/try out.

Chris
Works correctly but buttons need to latch.fcf
(19.21 KiB) Downloaded 433 times

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: HELP! - Simulates perfectly but not on breadboard

Post by medelec35 »

christoph wrote:I have now re-programmed the chip but unfortunately it doesnt work on the hardware.
Woops, I left out the variable initiations, sorry about that.
If you don't initialise variables then they will not start up with 0 like they do on the simulator but will start with a random number.

I will try both flowcharts on hardware & report my findings.

Martin
Attachments
HELP - Simulates perfectly but not on breadboard V3 with var ini.fcf
(17.95 KiB) Downloaded 458 times
Martin

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: HELP! - Simulates perfectly but not on breadboard

Post by christoph »

Many thanks - much appreciated Martin

Chris

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: HELP! - Simulates perfectly but not on breadboard

Post by medelec35 »

Right,
I have found the main cause of the problem.

When using RS232 and you read the switches then switch connected to pin C6 will always read high.
That is because RS232 always takes over both pins associated with TX (RC6) and RX (RC7) even if one is not used.
So with no switches pressed, the input will always be reading 64.
Therefor will not get passed wait for switch release loop!
There are a couple of ways around this.
1. Change switch connected to C6 to C5 (and change output A6 to A5) See attached Flowchart.

2. Place C code to disable TX (RC6) while reading switches.

Your call, but option 1 is easiest if not committed to hardware.

I have tested on hardware the attached flowcharts:
'HELP - Simulates perfectly but not on breadboard V4 with var ini' is keeping the RS232 format from your original flowchart. Used for PIC to PIC communication.
'HELP - Simulates perfectly but not on breadboard V4a with var ini' I have converted ASCII to decimal equivalent. So if press 2 with emulation software like Hyperterminal then ASCII 2 will be converted directly into number 2 (0b10) and sent to portB (Now removed to avoid confusion).
On hardware only port B1 was high, so is working for me.
Attachments
HELP - Simulates perfectly but not on breadboard V4 with var ini.fcf
(17.95 KiB) Downloaded 420 times
Last edited by medelec35 on Sun Apr 20, 2014 12:39 pm, edited 1 time in total.
Reason: Removed a flowchart that's not required
Martin

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: HELP! - Simulates perfectly but not on breadboard

Post by christoph »

Hi Martin,

Just got back to this and looking at your feed back - yes I WAS concerned as to why C6 was ON all the time! Ahh so that's the answer and another of those little 'catches' is now exposed thanks to your experience and help. Yes, I can use C5 and uncommitted A5 so thats fine. I assume the fact that C5 is not simulating because of this catch situation but will on hardware.

I am not really understanding the rest of your answer regarding Port B LEDs so I just wanted to check something before I re-prog the chip:- If I send the number 17 the LEDs need to be lit as the binary code for the number 17 which is of course 00010001 but you mentioned "only port B1 was high..." which alerted me to this so whenI sent 17 in simulation, I got Port B looking like this 11100001 which of course is 225! but I have to have the number lit in binary aa the LEDs represent the input to a piece of kit that only recognises the binary of the number sent. Could you modify the flowchart with this in view.

Chris

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: HELP! - Simulates perfectly but not on breadboard

Post by medelec35 »

Hi Chris,
Which flowchart you use depends on the type of data and what is transmitting the data.
Im guessing your just sending a byte value via RS232 from one PIC to another?
If that is the case then you can forget about V4a and just concentrate on HELP - Simulates perfectly but not on breadboard V4 with var ini.fcf
4a is only when sending ASCII via PC and not PIC

The way HELP - Simulates perfectly but not on breadboard V4 with var ini.fcf works should be like your original version.
I.e send 17 from one pic and binary equivalent of 17 should be on port B (10001) of the receiving PIC
christoph wrote:the fact that C5 is not simulating because of this catch situation but will on hardware.
No sorry, trying to do too many things today.

I did not test the hardware for C5/A5 just tried the other two.
Reason C5/A5 are not working (simulation or hardware) is because when I changed from C6/A6 to C5/A5, I did not change the masking on the output component:
Change masking.png
(111.09 KiB) Downloaded 11995 times
christoph wrote:so I just wanted to check something before I re-prog the chip:- If I send the number 17 the LEDs need to be lit as the binary code for the number 17 which is of course 00010001
Yes after making the port A mask correction to:
HELP - Simulates perfectly but not on breadboard V4 with var ini.fcf it should do that along with working C5/A5 function.

Martin
Martin

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: HELP! - Simulates perfectly but not on breadboard

Post by christoph »

Hi Martin,

I thought V4a was the definitive flowchart so hadn't tried V4 but when I realised IT was giving the binary code, I re-programmed the chip and sure enough it all works EXCEPT for C5/A5. The LED doesnt come on and the switch doesnt have any effect at any time in simulation or in bread board. I cant see why at the moment but it's 2;20 am and need some sleep! Looks as though it is almost there though!...!

Ohh! I was just about to post this and I saw your latest post and OK brill - thanks for pointing that out re C5/A5 so I will apply that tomorrow and report back but that should do the trick.

Yes - as you say I am doing exactly that: sending a byte value from another PIC to this one.

I'm really grateful for the help and I will stick it all together tomorrow and let you know your efforts have been worthwhile.

Best regards,

Chris

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: HELP! - Simulates perfectly but not on breadboard

Post by medelec35 »

Hi Chris,
christoph wrote:I thought V4a was the definitive flowchart
No worries, I have removed this flowchart as its not the type your after.
I can understand how you thought that.
christoph wrote:I'm really grateful for the help and I will stick it all together tomorrow and let you know your efforts have been worthwhile.
That would be great, as its good to know the end results.

I have left unused variables within flowchart since you created them and not used them I thought they are for future use.
If not required they can be deleted.

Martin
Martin

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: HELP! - Simulates perfectly but not on breadboard

Post by christoph »

Hi Martin,

Thanks for your last post - will have a tidy up of un-used variables etc.
Havent had a chance to do anything today as family duties intervened but will finalise tomorrow and definitely let you know results.

Best regards,

Chris

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: HELP! - Simulates perfectly but not on breadboard

Post by christoph »

Hi Martin,

SUCCESS! Yes it all works fine and as intended so thankyou sooooo much for the input needed to get things on the right track.
Not ONLY that but thanks for your enlightenment on the Flowcode 'catches' by which other people seeing this post, might be helped too1 It has opened my eyes to the possibilities of checking Flowcodes 'modus operandum' if simulation works and hardware is checked as being correct but something is not working in the 'real world' scenario and that could save a lot of time.

So, many thanks again,

Have a good day,

Best regards,

Chris

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: HELP! - Simulates perfectly but not on breadboard

Post by medelec35 »

hi Chris,
Just glad it's all working now.
Thanks for letting us know
christoph wrote:Not ONLY that but thanks for your enlightenment on the Flowcode 'catches' by which other people seeing this post, might be helped too1 It has opened my eyes to the possibilities of checking Flowcodes 'modus operandum' if simulation works and hardware is checked as being correct but something is not working in the 'real world' scenario and that could save a lot of time.
I guess it just down to experience in the end and posting findings like we have done.

Martin
Martin

christoph
Flowcode V4 User
Posts: 382
Joined: Tue Nov 01, 2011 4:28 pm
Has thanked: 196 times
Been thanked: 26 times
Contact:

Re: HELP! - Simulates perfectly but not on breadboard

Post by christoph »

Cheers,

Chris

Post Reply