"Not getting the ASCII codes expected for 2 out of the 3 byt

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

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

"Not getting the ASCII codes expected for 2 out of the 3 byt

Post by christoph »

Hi all,
Re the attachment included, if switch A0 is selected, the UART output is 17,17,17, repeatadly: which is correct in simulation. I would therefor,be expecting my logic analyser to see (s) (49) (55) (44) repeating with a small delay between each group and equating to start bit, decimal 1, decimal 7, and a comma. I get the comma ( I understand that as it is a string format ) but my LOGIC ANALYSER DECODES THIS AS (s) (53) (56) (,) meaning 58,58,58, repeatedly. I have tried every which way to get it right but I dont understand why it is happening or how to sort it.

Can anyone enlighten me please?

Regards

Chris

[attachment=0]UART TRANSMITTER.fcf[/attachment
Attachments
UART TRANSMITTER.fcf
(10 KiB) Downloaded 456 times

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

Re: "Not getting the ASCII codes expected for 2 out of the 3

Post by medelec35 »

Hi Chris,
It it was me getting unpredicted results, I would do a switch test.
If you run the attached program, and let me know what the results from TX?
I need to know what the tx value is with no switch pressed then with A1 pressed?
I could be wrong but I suspect a switch is being detected has high when it should be low?

All the attached flowchart does is read the value of port A, and transmits value via RS232

Martin
Attachments
UART TRANSMITTER Switch test..fcf
(13.3 KiB) Downloaded 487 times
Martin

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

Re: "Not getting the ASCII codes expected for 2 out of the 3

Post by christoph »

Hi Martin,
Thanks on this query. Unfortunately I cant download the chart though, the first plaque refers to yours being a later version (of flowcode ?) to mine and the subsequent plaque after pressing ok says "unable to create microcontroller PIC8. FCD is missing or corrupt. [0x200]

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

Re: "Not getting the ASCII codes expected for 2 out of the 3

Post by medelec35 »

Oops,
Sorry wrong version posted.
Can you try attached version please.

Martin
Attachments
UART TRANSMITTER Switch test..fcf
(7.5 KiB) Downloaded 490 times
Martin

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

Re: "Not getting the ASCII codes expected for 2 out of the 3

Post by christoph »

Tried it with switch not pressed and no code appears but output HI and output also HI when switch IS pressed. Have just spent the time between programming chip with your posted chart and now, checking everything again and cant fault anything. This is a new chip and to be doubly certain of no damage have taken care to not corrupt thro' static etc etc but I have never had any problem with PICs before.

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

Re: "Not getting the ASCII codes expected for 2 out of the 3

Post by medelec35 »

christoph wrote:Tried it with switch not pressed and no code appears
Flowchart is designed to give an output all the time.
With no switches pressed since i/p will read 0, RS232 should display 0.
With A1 pressed i/p will read 2 etc:
Switch test results.png
(32.93 KiB) Downloaded 9103 times
If nothing appears with no switches pressed, then you need to re-look at your hardware.
Only thing I can think of is change RA5/MCLR from MCLR to RA5 and re compile to chip.

Martin
Martin

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

Re: "Not getting the ASCII codes expected for 2 out of the 3

Post by christoph »

My hardware is this:

+ve 4.5v supply to pin 14
-ve to pin 5
6.8k resistor from pin 4 to +ve
1k pull down resitor from pin 11 to -ve
10k resistor from pin 18 (A1) to clean contact, normally open switch and also from this point, a pull down 1k resistor to -ve.
The free side of the switch is connected to +ve rail

.....is that what you have or similar?

I am baffled - I really dont think there is anything else I can try.

Then again the same chip (and others) do 'work' with exactly these same connections but produce those incorrect numbers!!!

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

Re: "Not getting the ASCII codes expected for 2 out of the 3

Post by christoph »

Hi Martin,

Is it possible for you to run this attached flowchart on your hardware because I have re-programmed the self-same chip and it DOES produce the UART output of (49) and (55) and (44) correctly and repeatadly but has the odd 'lone' 255 or 299 interspaced occasionally which seems to point to either syncronisation or the pulse timing percentage error but I was wondering if that is partly my logic analyser since it doesnt show up on the simulation - but I'm not into all those aspects - have you any thoughts on that?
UART TRANSMITTER.fcf
(10 KiB) Downloaded 484 times

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

Re: "Not getting the ASCII codes expected for 2 out of the 3

Post by christoph »

with no switch pressed and saying it is 230400 baud rate!, it is repeating about 6 or 7 different numbers one after another MOST of which do not have an associated ASCII character such as 255 for example.

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

Re: "Not getting the ASCII codes expected for 2 out of the 3

Post by medelec35 »

christoph wrote:Is it possible for you to run this attached flowchart on your hardware
I have and it runs perfectly.
there is nothing at TX until say switch connected to A0 goes high then:
A1 high.png
(45.01 KiB) Downloaded 9054 times
My analyser shows:
A1 high2.png
(62.85 KiB) Downloaded 9054 times
As you can see the smallest bit is 103 uS = 9708 baud. Close enough for an internal osc.
Martin

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

Re: "Not getting the ASCII codes expected for 2 out of the 3

Post by christoph »

Hi Martin,

I getting plenty of UART out of pin 11 and by tweaking things on the logic analyser, it actually says 9600 for the baud rate when I select 'AUTO DETECT'. However, it is churning out only two bytes: 51 and 44 (i.e. ASCII 3 and ASCII ,) regardless of pressing A0 or A1 switch! I am beginning to suspect the logic analyser now!!

Is your hardware connected as per my description in a recent post of mine but PARTICULARLY in respect of the switch connection with its two resistors and their values as I would prefer to do it exactly as you have.

Would like to get answer on that if you wouldn't mind and if it doesnt work after that I give up! :((

Chris

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

Re: "Not getting the ASCII codes expected for 2 out of the 3

Post by christoph »

Forgot to say, I have changed pin 4 from MCLR to RA5 and is currently the situation....

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

Re: "Not getting the ASCII codes expected for 2 out of the 3

Post by medelec35 »

I have had a thought.
Double click in the input component and select mask.
Now make sure only the pins that have 1k resistors going to 0v are selected.
It could be a floating input that is causing all these issues.
Martin

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

Re: "Not getting the ASCII codes expected for 2 out of the 3

Post by christoph »

Hi Martin,

SORTED111

You're a genius, that is EXACTLY what the problem has been! It seems to have also been the reason that I wasn't getting any outputs at all every now and then, because I am now able to use the same chips that I couldnt get to work before and was going to bin! Amazing that this can cause randome numbers when no switches were activated and weird results when and if the switches operated at all. However, it all works perfectly now so thankyou for that inspirational thought!!

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

Re: "Not getting the ASCII codes expected for 2 out of the 3

Post by christoph »

Might be a good one to post on @If youre hardware is not working correctly....etc but you deserve the credit and will explain it better than I !

Thanks again

Chris

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

Re: "Not getting the ASCII codes expected for 2 out of the 3

Post by medelec35 »

Hi Chris.
Glad its all sorted for you and we got there in the end. :)
christoph wrote:Hi Martin,
Amazing that this can cause randome numbers when no switches were activated and weird results when and if the switches operated at all. However, it all works
This is because you are using a decision branch based on the value of the whole port.
Since there were pins that are floating, then they will easily drift from logic 0 to logic1 Randomly.
This will change the value of input, hence not working ex expected.
christoph wrote:Might be a good one to post on @If youre hardware is not working correctly
Good idea,
Thanks.... done.

Martin
Martin

Post Reply