Page 1 of 2

Pic12f683 - rs232 FL8 in target do not work

Posted: Tue Jan 21, 2020 12:20 pm
by castabob
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

Re: Pic12f683 - rs232 FL8 in target do not work

Posted: Tue Jan 21, 2020 1:05 pm
by Benj
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.

Re: Pic12f683 - rs232 FL8 in target do not work

Posted: Tue Jan 21, 2020 4:18 pm
by castabob
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

Re: Pic12f683 - rs232 FL8 in target do not work

Posted: Wed Jan 22, 2020 11:01 am
by Benj
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;

Re: Pic12f683 - rs232 FL8 in target do not work

Posted: Wed Jan 22, 2020 11:43 am
by castabob
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

Re: Pic12f683 - rs232 FL8 in target do not work

Posted: Wed Jan 22, 2020 2:41 pm
by medelec35
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.

Re: Pic12f683 - rs232 FL8 in target do not work

Posted: Wed Jan 22, 2020 4:48 pm
by castabob
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

Re: Pic12f683 - rs232 FL8 in target do not work

Posted: Wed Jan 22, 2020 6:07 pm
by medelec35
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.

Re: Pic12f683 - rs232 FL8 in target do not work

Posted: Tue Feb 04, 2020 12:12 pm
by castabob
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

Re: Pic12f683 - rs232 FL8 in target do not work

Posted: Tue Feb 04, 2020 1:36 pm
by medelec35
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?

Re: Pic12f683 - rs232 FL8 in target do not work

Posted: Tue Feb 04, 2020 4:52 pm
by castabob
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

Re: Pic12f683 - rs232 FL8 in target do not work

Posted: Tue Feb 04, 2020 6:04 pm
by medelec35
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.

Re: Pic12f683 - rs232 FL8 in target do not work

Posted: Wed Feb 05, 2020 8:12 pm
by castabob
Hi,

I can't make it work even in simulation.

regards

Re: Pic12f683 - rs232 FL8 in target do not work

Posted: Wed Feb 05, 2020 10:50 pm
by medelec35
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.

Re: Pic12f683 - rs232 FL8 in target do not work

Posted: Thu Feb 06, 2020 6:28 pm
by castabob
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

Re: Pic12f683 - rs232 FL8 in target do not work

Posted: Thu Feb 06, 2020 10:13 pm
by medelec35
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?

Re: Pic12f683 - rs232 FL8 in target do not work

Posted: Fri Feb 07, 2020 12:03 pm
by medelec35
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.

Re: Pic12f683 - rs232 FL8 in target do not work

Posted: Fri Feb 07, 2020 7:46 pm
by castabob
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

Re: Pic12f683 - rs232 FL8 in target do not work

Posted: Sat Feb 08, 2020 12:19 am
by medelec35
Can you try the attached flowchart.
If does not work then post all the chars transmitted so I can test further.

Re: Pic12f683 - rs232 FL8 in target do not work

Posted: Sat Feb 08, 2020 7:41 pm
by castabob
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 ..

Re: Pic12f683 - rs232 FL8 in target do not work

Posted: Sat Feb 08, 2020 9:58 pm
by medelec35
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.

Re: Pic12f683 - rs232 FL8 in target do not work

Posted: Sun Feb 09, 2020 4:54 pm
by castabob
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

Re: Pic12f683 - rs232 FL8 in target do not work

Posted: Sun Feb 09, 2020 6:16 pm
by medelec35
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.

Re: Pic12f683 - rs232 FL8 in target do not work

Posted: Sun Feb 09, 2020 6:23 pm
by castabob
I thank you for the time you are spending on my problem.
Regards
Castabob

Re: Pic12f683 - rs232 FL8 in target do not work

Posted: Mon Feb 10, 2020 10:40 am
by medelec35
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.