Pic12f683 - rs232 FL8 in target do not work

An area to discuss 8-bit PIC specific problems and examples

Moderator: Benj

castabob
Posts: 22
Joined: Sun May 20, 2018 10:41 pm
Has thanked: 3 times
Been thanked: 1 time
Contact:

Pic12f683 - rs232 FL8 in target do not work

Postby castabob » Tue Jan 21, 2020 12:20 pm

Hi,
I ask for help to solve a problem of my program not working.
In emulation with FL8 the program works but once loaded in the target it does not work. I had created the same program with FL6 and it worked without problems even in the target. I was unable to compile (HEX) it with FL7 because it gave me errors that I was unable to interpret. For each version (FL6, FL7, FL8) the program was created using the right MACROs related to the FL version.
It is a program that receives commands via the serial line and behaves accordingly.
The chip used does not have UART which is emulated via software.

Can you tell me where I'm wrong?
Thank you
Regards
Attachments
Oscillatore 70Hz.fcfx
(24.39 KiB) Downloaded 7 times

User avatar
Benj
Matrix Staff
Posts: 14559
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4591 times
Been thanked: 4237 times
Contact:

Re: Pic12f683 - rs232 FL8 in target do not work

Postby Benj » Tue Jan 21, 2020 1:05 pm

Hello,

Flowcode v7 and v8 uses a different C compiler to v6 which is known to be better overall but can throw up some issues with tight loops such as the software UART.

Please can you try running the chip at 8MHz instead of 4MHz.

To do this simply add the following line of code in a C icon at the very start of your program.

Code: Select all

OSCCON = 0x70;


Also remember to change the project options clock speed to 8000000.

This should be all you need to do and fingers crossed this will allow things to work correctly.

The error I get in v7 looks like this which confirms my suspicions that it's a clock speed issue.

206: #error "Software UART Baud Rate Not Available At This Clock Speed"


Let us know how you get on.

castabob
Posts: 22
Joined: Sun May 20, 2018 10:41 pm
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: Pic12f683 - rs232 FL8 in target do not work

Postby castabob » Tue Jan 21, 2020 4:18 pm

Hi Benj,
thanks for the tips but unfortunately even after the changes only emulation works but not yet in the target.
I don't know if it's important, but I always compile in HEX.
Attached the program with the changes.

Regards
Attachments
Oscillatore 70Hz.fcfx
(24.52 KiB) Downloaded 6 times

User avatar
Benj
Matrix Staff
Posts: 14559
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4591 times
Been thanked: 4237 times
Contact:

Re: Pic12f683 - rs232 FL8 in target do not work

Postby Benj » Wed Jan 22, 2020 11:01 am

Hello,

In the C icon you have added the line of code inside the comments.

Code: Select all

/*
OSCCON = 0x70;
*/


Please change to just

Code: Select all

OSCCON = 0x70;

castabob
Posts: 22
Joined: Sun May 20, 2018 10:41 pm
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: Pic12f683 - rs232 FL8 in target do not work

Postby castabob » Wed Jan 22, 2020 11:43 am

Hi Benj,
my serious distraction error but after correcting it again my target doesn't want to work.
I have adapted the program to FL6, which I am attaching, and recompiled (HEX) and it also works on my target .
(?)
Regards
Attachments
Oscillatore 70Hz FL6.fcfx
(18.98 KiB) Downloaded 6 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8533
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2456 times
Been thanked: 3522 times
Contact:

Re: Pic12f683 - rs232 FL8 in target do not work

Postby medelec35 » Wed Jan 22, 2020 2:41 pm

Hi castabob,
castabob wrote:I have adapted the program to FL6, which I am attaching, and recompiled (HEX) and it also works on my target .

It may compile, but did it reliably receive correct values?
Normally if place RS232 ReceiveChar within main or any other not RX interrupt then it will miss transmitted characters.

My suggestion is to use a 12F1840 microcontroller so you can place the RS232 ReceiveChar within a UART RX interrupt.
There are other advantages to the 12F1840.
Cheap, much faster, more memory, more functions including interrupts etc.
These users thanked the author medelec35 for the post:
Benj (Wed Jan 22, 2020 3:08 pm)
Rating: 5.26%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

castabob
Posts: 22
Joined: Sun May 20, 2018 10:41 pm
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: Pic12f683 - rs232 FL8 in target do not work

Postby castabob » Wed Jan 22, 2020 4:48 pm

Hi Martin,

the project compiled with FL6 with reception of characters up to 1200 BD sometimes loses characters but at 600BD it still responds well (it must recognize only a sequence of 3 characters). However if you tell me that it is risky I will certainly change the processor with what you recommend
(12F1840) that I have seen it has everything I need for this job.
Thank you
Yours sincerely
These users thanked the author castabob for the post:
Benj (Thu Jan 23, 2020 10:49 am)
Rating: 5.26%
 

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8533
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2456 times
Been thanked: 3522 times
Contact:

Re: Pic12f683 - rs232 FL8 in target do not work

Postby medelec35 » Wed Jan 22, 2020 6:07 pm

You're welcome.
Yes, it will much better, and if using RX interrupt, should not loose any chars at 9600 baud or even greater!
If there was a lot of chars you could even use a circular buffer.
These users thanked the author medelec35 for the post (total 2):
Benj (Thu Jan 23, 2020 10:49 am) • castabob (Thu Jan 23, 2020 5:07 pm)
Rating: 10.53%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

castabob
Posts: 22
Joined: Sun May 20, 2018 10:41 pm
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: Pic12f683 - rs232 FL8 in target do not work

Postby castabob » Tue Feb 04, 2020 12:12 pm

Hi Martin,

as you suggested I applied the 12F1840 chip but while in simulation it works as I expect, on my target the program does not work.
Maybe some chip settings are incorrect?
Please tell me where am I wrong? I am compiling in HEX using FL8.
Regards
castarob
Attachments
Oscillatore 70Hz FL8 1840.fcfx
(32.51 KiB) Downloaded 4 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8533
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2456 times
Been thanked: 3522 times
Contact:

Re: Pic12f683 - rs232 FL8 in target do not work

Postby medelec35 » Tue Feb 04, 2020 1:36 pm

Hi castarob,
There are indeed issues with your configuration settings.
I generally run internal osc at 32MHz
What frequency do you want internal osc to run at and do you have anything connected to pin 4?
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

castabob
Posts: 22
Joined: Sun May 20, 2018 10:41 pm
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: Pic12f683 - rs232 FL8 in target do not work

Postby castabob » Tue Feb 04, 2020 4:52 pm

Hi Martin,

I had set the working frequency to 8 Mhz with the internal oscillator (I hadn't thought of a frequency of 32 Mhz).
Pin 4 is connected to the reset which is constantly high.
regards

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8533
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2456 times
Been thanked: 3522 times
Contact:

Re: Pic12f683 - rs232 FL8 in target do not work

Postby medelec35 » Tue Feb 04, 2020 6:04 pm

I have made some changes for a working frequency of 8MHz.
If it works we can also try 32MHz.
If it does not then check all setting are correct following this link for a 1 sec flasher.
Attachments
Oscillatore 8MHz FL8 1840.fcfx
(31.59 KiB) Downloaded 6 times
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

castabob
Posts: 22
Joined: Sun May 20, 2018 10:41 pm
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: Pic12f683 - rs232 FL8 in target do not work

Postby castabob » Wed Feb 05, 2020 8:12 pm

Hi,

I can't make it work even in simulation.

regards

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8533
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2456 times
Been thanked: 3522 times
Contact:

Re: Pic12f683 - rs232 FL8 in target do not work

Postby medelec35 » Wed Feb 05, 2020 10:50 pm

Hi castarob,
RX interrupt does not simulate.
I have thought of a way to simulate RX interrupt using Ben's excellent Is Sim function.
As I don't know what all the working functions are see if the attached works in simulation mode.
If it does then I don't see why it does not work on your hardware.
Make sure the 1 sec flasher works and that the connections of UART withing flowchart, matches actual hardware.
Also check baud rates match.
Attachments
Oscillatore 8MHz FL8 1840 sim RX int.fcfx
(32.71 KiB) Downloaded 5 times
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

castabob
Posts: 22
Joined: Sun May 20, 2018 10:41 pm
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: Pic12f683 - rs232 FL8 in target do not work

Postby castabob » Thu Feb 06, 2020 6:28 pm

Hi Martin,
excellent method to emulate. In fact in emulation it now works as I expect. Unfortunately, however, the firmware installed in the target still does not want to work. As you suggested, I tried the target with the flashing program for one second, affecting all the ports except the reset (pin 4), even the frequency of one second is correct. If it can be useful, I tell you that the serial signal is applied to RA1 (pin 6) and is normally high (should it normally be low?). The BD of the PC with which I transmit is correct and I also tried at 1200BD (changing the program on the target).
I don't know if it is important but, as I said at the beginning, a similar target that mounts a Pic12F683 works without problems (max 1200BD) if I compile the program with FL6 but I never managed to make it work by compiling it with FL8 (after the necessary changes for FL8). Do you have any other suggestions? Maybe I have to set some bits inherent to the serial line of this micro (12F1840)?

attached the test performed on the target.

Regards
castarob
Attachments
Simula 1S.fcfx
(14.96 KiB) Downloaded 4 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8533
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2456 times
Been thanked: 3522 times
Contact:

Re: Pic12f683 - rs232 FL8 in target do not work

Postby medelec35 » Thu Feb 06, 2020 10:13 pm

castabob wrote:and is normally high (should it normally be low?)

Normally high is correct.
Can you also try setting up TX to send received chars.
You could use a terminal program like Teraterm to display received chars.
Have you got a scope to monitor RX pin to 12F1840?
When I get a chance, I can test UART on a 12F1840 to see if there is an issue with Flowcode or not.
Perhaps just try a more common baud rate of 9600?
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8533
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2456 times
Been thanked: 3522 times
Contact:

Re: Pic12f683 - rs232 FL8 in target do not work

Postby medelec35 » Fri Feb 07, 2020 12:03 pm

One thing I have spotted with your flowchart.
Where you have

Code: Select all

Abbandona_Loop = 0
, you will need to add an additional calculation:

Code: Select all

Char_ricevuto = 0

So you should have:

Code: Select all

Abbandona_Loop = 0
Char_ricevuto = 0

Not your fault, but I have realised RX interrupt won't work if the interrupt is called before the UART initilise.
Makes sense now I think about it.
Just move the interrupt after the initialise and before the main loop.
Then along with the code adding, hopefully, will work on hardware.

I can confirm that UART TX and RX (with RX Interrupt) is working on hardware.
These users thanked the author medelec35 for the post:
Benj (Fri Feb 07, 2020 1:58 pm)
Rating: 5.26%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

castabob
Posts: 22
Joined: Sun May 20, 2018 10:41 pm
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: Pic12f683 - rs232 FL8 in target do not work

Postby castabob » Fri Feb 07, 2020 7:46 pm

Hi Martin,
now it gets more interesting ...
I cleaned up the program but without success: on the target it still doesn't work. There is probably something conceptual about my program that doesn't make it work. An important novelty is that I have enabled the transmission of the character received within the receiving int and this is working and the same character received is re-transmitted. I am able to visualize the flow of data with an oscilloscope and also I can verify the correctness of the data received / transmitted because I am using the "Hercules" program and I see the data transmitted / received. I am also able to transmit sentences that are correctly retransmitted.
By inserting the activation of an output (A2) as the continuation flag of the program, I noticed that the program does not continue beyond the second stage of "switchPointer_chars_first_reception" as if it did not recognize the character received (now the flag is at the fourth stage but the program never got there). Everything I tell you is related to target behavior.
Do you have any suggestions on what I could test?

Regards
castarob
Attachments
Oscillatore 8MHz FL8 1840 sim RX int.fcfx
(32.77 KiB) Downloaded 4 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8533
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2456 times
Been thanked: 3522 times
Contact:

Re: Pic12f683 - rs232 FL8 in target do not work

Postby medelec35 » Sat Feb 08, 2020 12:19 am

Can you try the attached flowchart.
If does not work then post all the chars transmitted so I can test further.
Attachments
Oscillatore 8MHz FL8 1840 sim RX 2.fcfx
(32.93 KiB) Downloaded 4 times
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

castabob
Posts: 22
Joined: Sun May 20, 2018 10:41 pm
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: Pic12f683 - rs232 FL8 in target do not work

Postby castabob » Sat Feb 08, 2020 7:41 pm

Hi Martin,
I compiled (HEX) the program you sent me and I loaded it into the target.
If I understood correctly, you wanted to see what I send to the target at pin 6 and what was retransmitted from pin 7. Through the Hercules terminal program I sent the contents of the 3 "send" fields separately and the result is what you see in the window "received / sent data".
In pink what I sent and in black what pin 7 retransmitted to the terminal. Is this what you asked me or did you mean something else?
Attached is the photo of the test.
Regards
castabob

PS.
I still didn't get the result I wanted, but maybe that wasn't the purpose of this test ..
Attachments
IMG_0143.JPG
IMG_0143.JPG (148.3 KiB) Viewed 210 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8533
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2456 times
Been thanked: 3522 times
Contact:

Re: Pic12f683 - rs232 FL8 in target do not work

Postby medelec35 » Sat Feb 08, 2020 9:58 pm

The main purpose was to see what chars receiving,by sending received chars back to the monitor.
At least you can see if receiving correct chars or not.
This was successful.
I can spot an issue with your flowchart.
It will work with PGM ,but will fail after that because you have a test which it triggered by the next char C
to prove this is the case try sending PGMCCOMA123456789 etc
If you make sure that IsSim component is enabled, you will see what I'm referring to.
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

castabob
Posts: 22
Joined: Sun May 20, 2018 10:41 pm
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: Pic12f683 - rs232 FL8 in target do not work

Postby castabob » Sun Feb 09, 2020 4:54 pm

Hi Martin,
I corrected the program that now "in simulation" works correctly. Unfortunately there is no way to make it work on the target. The program does not even arrive until the end of the "PGM" character recognition. If it did, it would turn on the output (A2), as seen in the program, but this does not happen.
(Note: when I compile for the target I disable "IsSim").
Can I still try other tests?
regards

castabob
Attachments
Oscillatore 8MHz FL8 1840 sim RX 2A.fcfx
(31.99 KiB) Downloaded 4 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8533
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2456 times
Been thanked: 3522 times
Contact:

Re: Pic12f683 - rs232 FL8 in target do not work

Postby medelec35 » Sun Feb 09, 2020 6:16 pm

Hi castabob,
IsSim does not require disabling as it will not be accessed when running on hardware.
I'm surprised its not working as the chars are being received since they are also being sent back via TX.
I will make the hardware and test it my end.
Will report back when I have results.
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

castabob
Posts: 22
Joined: Sun May 20, 2018 10:41 pm
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: Pic12f683 - rs232 FL8 in target do not work

Postby castabob » Sun Feb 09, 2020 6:23 pm

I thank you for the time you are spending on my problem.
Regards
Castabob

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8533
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2456 times
Been thanked: 3522 times
Contact:

Re: Pic12f683 - rs232 FL8 in target do not work

Postby medelec35 » Mon Feb 10, 2020 10:40 am

Hi, Not a problem.
I had some time free this morning and modified flowchart.
Hardware is working for me.
LED flashes after sent the final A in COMA.
Attachments
Oscillatore 8MHz FL8 1840 sim RX 2B.fcfx
(32.09 KiB) Downloaded 2 times
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.