PIC16F1936 software set UART... NOT correct.

Moderator: Benj

Post Reply
DCW
Posts: 64
Joined: Mon Sep 28, 2015 8:19 pm
Has thanked: 14 times
Been thanked: 10 times
Contact:

PIC16F1936 software set UART... NOT correct.

Post by DCW »

Hello anyone.. and someone .. this is a small problem with a SOFTWARE setup UART port. I using the built in TX/RX .. C6/C7 for another communication.
BUT.. I need to have another TX port to help / aid.. in operation of the project... so I took RB4.. and 'turned' it into a TX port, using the SOFTWARE setting of the properties of the UART. I set the BAUDRATE to only 1200. I not using any flow control. I just need text strings to bubble out the TX port.

So the circuit is simple.. select a PIC16F1936.. set it at 4 mHz. set the config to a working system. set OSCCON=0x68; set int OSC with port functions etc etc.. All the rest are setup correctly.

When I setup the UART... it's initialized .. outside a loop.. inside the loop I use the UART macro.. to sendstring "simple text output".. and when I connect a RS232 chip.. the rubbish that comes out the port is not anything like it should be.

How can this be fixed... I have set 8 bits... no echo .. and the port on the laptop, is set to 1200 BAUDRATE - 8 bits.. 1 stop bit.. and the serial port is ordered through a ST-labs prolific hardware connection. - on a USB port...

I need the real C6/C7 pins for a real TX/RX job... so cannot use them at all...
SO - what offers - in a bug - debug.. to get this to work please.?? Is there another option...possibly.??
Kindest Regards
DCW ...
Last edited by EtsDriver on Mon Jan 13, 2020 7:16 pm, edited 1 time in total.
Reason: Removed personal information for GDPR reasons.

DCW
Posts: 64
Joined: Mon Sep 28, 2015 8:19 pm
Has thanked: 14 times
Been thanked: 10 times
Contact:

Re: PIC16F1936 software set UART... NOT correct.

Post by DCW »

Hello peeps... and anyone... and someone...
So the problem - I sorted out...!
I forgot that I was working with BAUD RATES ... which are special ... OLD FASHONED time .. frequencies...

So the solution is to set the microprocessor crystal "speed" to this number... OR a multiple of it...
3276800 Hz... is like say a base frequency...
and 4X that "speed"... is 13107200 Hz...

Then the SOFTWARE configuration of a pin on the processor should be pretty simple.!!

Thanks folks / peeps / anyone / someone ....
Kindest Regards
DCW ...
Last edited by EtsDriver on Mon Jan 13, 2020 7:17 pm, edited 1 time in total.
Reason: Removed personal information for GDPR reasons.

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:

Re: PIC16F1936 software set UART... NOT correct.

Post by Benj »

Hi Spencer,

Glad you've got it working now. This is a nice and simple tool I often use to help ensure things are running at the correct speed.

https://www.matrixtsl.com/wiki/index.ph ... ED_flasher

DCW
Posts: 64
Joined: Mon Sep 28, 2015 8:19 pm
Has thanked: 14 times
Been thanked: 10 times
Contact:

Re: PIC16F1936 software set UART... NOT correct.

Post by DCW »

WE NOT OUT THE WOODS YET...?????
GREATER TROUBLES AHEAD... PLEASE READ BELOW...

Okay guys so I have a simple circuit... utilizing a PIC16F1936... 28 pin ..as I have posted in the above posts...

So I have used the UART in hardware, on Tx and Rx, on the chip... and because I need a simple RS232 output for monitoring puposes, I have used pin 25.. RB4, calling the UART component, and using it in Software, instead of Channel mode.

My processor need not be a great speed, so I set it to 4000000 Hz setting.

So the hardware from pin 25, works into a RS232 chip, so that the TTL level of RS232 signals, is converted to correct levels for RS232 into "the outside world"... I have a correctly working USB - RS232 COM port, on my PC.

Right so having setup all the hardware correctly, I proceeded to start attempting to write and compile the needed software.

After a while, of trying all sorts of settings / "tricks", I thought were okay, I discovered

1) that no matter what setting I set on BAUD rate of my serial port, into the program, called TERA TERM... I could not get a responsible - correct BAUD RATE setting to produce correct characters, on the Tera Term terminal program.

2) I then looked through the possible frequency settings numbers, of the processors, and saw that instead of 4000000 Hz... I could select 3276800 Hz... which I did...
WOW then all of a sudden... the correct BAUD RATE was 1200 BAUD... to allow totally readable figures, to be displayed on the screen of Tera Term...

The problems, then really compounded, as ..... then I had...the software UART working okay... NOT PERFECT, but right then, at 1200 BAUD RATE..
I then noted that the hardware UART now stopped working. It was needed that the hardware BAUD RATE be 9600 BAUD RATE. When eventually I caught up with that hardware, there was just gibberish coming out the 9600 BAUD RATE UART... I tried other BAUD RATE settings, BUT NO GO,.... NONE of the tested range of BAUD RATE settings produced workable figures.

I set the CPU frequency back from 3276800 Hz, to 4000000 Hz... and the the hardware UART started to work correctly, and the software UART, stopped working.

So this is version 8.2 odd of FLOWCODE, the latest flagship of FLOWCODE... WOW what a pity. What have I done wrong??

Can anyone tell me what I have done wrong. I do not see any reason to post the program, as both UART are working, provided the correct frequency is set.

What I would like... to be done, is that...

1) someone help me construct a software UART in C-code which I can add in the C-code icon, so that I can use pin 25 of the PIC, and have the correct operation of BAUD RATE readable characters. I would like to have a processor frequency of 4000000 Hz, and a BAUD RATE of say 2400 BAUD...

2) the boffins in MatrixTsl, rewrite the UART software in FLOWCODE, so that the software mode actually works correctly. It's version 8.2 odd, and I spose one would have expected the UART software to be functioning all correctly.???. by this release.!!!

Thank you guys.. for reading, and any help would be really appreciated.

My problems have NOT been sorted... So I have re-advised this fault...
Regards
DCW.

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:

Re: PIC16F1936 software set UART... NOT correct.

Post by Benj »

Hi Spencer,

I see you're using the PIC16F1936, are you using the internal oscillator or an external crystal? If a crystal then what frequency is the crystal?

For software UART a faster clock rate is better as the jumping in and out of functions and other required logic etc will have less of an impact.

DCW
Posts: 64
Joined: Mon Sep 28, 2015 8:19 pm
Has thanked: 14 times
Been thanked: 10 times
Contact:

Re: PIC16F1936 software set UART... NOT correct.

Post by DCW »

Hello Ben... can you not rewrite the routines of FLOWCODE... so that they work correctly....???? you should by rights... do this...!! please..???

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: PIC16F1936 software set UART... NOT correct.

Post by kersing »

DCW wrote:can you not rewrite the routines of FLOWCODE... so that they work correctly....????
Could you provide answers to the questions Ben asked? That would help finding issues.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

Re: PIC16F1936 software set UART... NOT correct.

Post by QMESAR »

Hello Ben... can you not rewrite the routines of FLOWCODE... so that they work correctly....???? you should by rights... do this...!! please..???
Why always attack and be aggressive when surly you are doing things wrong in your Flowchart

(1) The PIC161938 you can not use 40 000000 Hz a maximum of 32Mhz
look at the datasheets before ranting at FC and BEN (NOTE 8MIPS x4 = 32MHZ(MIPS) :twisted:
setting any other speeds above 32MHZ unpredictable results will be obtained
p7.jpg
p7.jpg (56.08 KiB) Viewed 4999 times
(2) You are not setting the Frequency correctly in FC flowchart as well which is essential when using softuart ,because if you did you would have noticed that FC tells you can not use this frequency
P8.jpg
P8.jpg (66.5 KiB) Viewed 4999 times
before blaming FC firts makesure you are not at fault and have some issues in your flowchart

DCW
Posts: 64
Joined: Mon Sep 28, 2015 8:19 pm
Has thanked: 14 times
Been thanked: 10 times
Contact:

Re: PIC16F1936 software set UART... NOT correct.

Post by DCW »

Hello guys.... you got a greater problem - than you expect...

It seems none of you can READ the post correctly...???

Where the HELL - did I state - 40 mHz...??? GO ON TELL ME PLEASE..???... GO ON PLEASE SHOW ME..!!!!

It seems very obvious to me - that NONE of you guys have tried - WHAT I HAVE tried...!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - BUT you very quick to shoot me down.... !!! huh..??????

It is also quite obvious that BEN has not read my post either..!!!

Now can someone please also tell me why - the INTERNAL OSCILLATOR ... little helper does not have all the frequencies - available - that you can select from the settings - in build,.. I want to use 6 x 3276800 Hz.... which is the 19660800 frequency setting... BUT ..NO... I can't cause I thought that the INTERNAL OSCILLATOR module - would have that in it - to help me... work out which OSCCON setting to use..!!!!

I wonder when FLOWCODE will come of age..!!! and JUST WORK.,.. like it sposed to...!!!!???? I wonder which incarnation..???

CAN someone now please FIX ... FLOWCODE to work correctly..!!!!!!!!
thanks guys....
(CAN ANYONE - venture to fix FLOWCODE..????? I wonder....?????)

OR - plainly show me - like I asked.... to just do this in the C-code icon...???? please..????
...................................................................................
Make your processor work two UART's one in software mode...??? and one in hardware mode... so that at any frequency - you like....??? you will get like maybe 1200 BAUD out the software UART.... and 9600 BAUD out the hardware channel... of the chip... (8 bits chip please)...

Hey ..!!!! DO the hardware... huh... DO NOT JUST MAKE IT IN SOFTWARE... DO THE HARDWARE thing as well... make it on breadboard - or on stick-in breadboard - BUT use real chips- like RS232 and an 8 bit PIC .. with at least one UART... (NOT MORE - than ONE UART... and use any other pin to be a SOFTWARE UART..!!!! GO DO IT GUYS and GALS.... please PROVE ME A FOOL...!!!! And then PLEASE SHOW ME how you do it.... I would really appreciate that....!!!I really would.... I need to learn....!!!

Then I will have possibly - learned something...!!!!! (I love to learn something new every day..)...

Thanks guys.... GOD BLESS YOU ALL.... The UNIVERSE loves you..!!!.....

BTW - THE EARTH SHIFT.... is coming... it has already started....!! It sposed to be here - latest - 2029....!!!

chows - for now....
Regards

DCW
Posts: 64
Joined: Mon Sep 28, 2015 8:19 pm
Has thanked: 14 times
Been thanked: 10 times
Contact:

Re: PIC16F1936 software set UART... NOT correct.

Post by DCW »

Hello Folks.... DCW here again...!!!

OKAY - SO I WAS THE STUPID ONE..!!!!

I spent some time looking at the chip that MICROCHIP made so beautifully for us...!!!! BRILLIANT PIECE OF ENGINEERING.!!!!

So it has a range of frequencies it can work on.... so I selected 4000000 Hz... to begin with..... hmmm... AND NOTHING WORKED.... excepting the hardware parts... in UART....

So I looked further... and saw that - hey there is a 3276800 Hz frequency I could use... and BINGO the software UART worked okay at 1200 BAUD... (not good enough really for us guys... you see.... (so I gave it to you folks...)

Then NOT SATISFIED - I had done all.... I went BACK AGAIN... and looked at everything.... and THOUGHT - I AM THE MUTT..!!! YES..!!!!

So then I saw in the frequency helper program... that there was NONE of 3276800 or 19....bla bla... BUT ONLY 16000000 Hz... and 32000000 Hz... options.... SO I JUST SETTLED ON THE 16000000 Hz option.... and set up the program... put the correct OSCCON value in place.... and tried again...

So the result was that... if I used the 16000000 Hz option in the project setup.... and just used the software setup for the UART accordingly - IT ALL WORKS.... (maybe now when I get back to the desk .. it will have spited me... and stopped working...)???? we will see... shhhh..!!!

So folks- yeah - I was the STUPID ONE.... and thanks for being like you were and not really reading my posts - but it triggered something - and I went back and checked everything....

So what I found was at 16000000 Hz, and the CORRECT OSCCON figures....
1) that the software UART works very well....
2) the hardware UART works very well....
3)... and a few different BAUD rate settings were tested - AND ALL WORKED... (or so it seemed...) - let's hope it - carries on working....!!!

GOD BLESS you all...!!
Last edited by medelec35 on Sun Jan 12, 2020 11:02 am, edited 1 time in total.
Reason: Opinions regarding Earth shift and amount of deaths is not suitable for this forum.

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:

Re: PIC16F1936 software set UART... NOT correct.

Post by Benj »

Glad you've got it working now. Thanks for letting us know.

Post Reply