PDA

View Full Version : Problem with SEROUT after compiling with PBP3



Muzza
- 14th June 2013, 08:57
Help needed.
I have a display unit with a program created originally with PBP 2.5 that has been working correctly for many years.
The unit uses a 16F876A and has a USB interface that sends ASCII to a PC.
The units function and data displayed on the PC worked OK.

A few days ago I needed a small hardware change so decided to alter the program to display a different version in the header sent to the PC.

I changed the :-
@ DEVICE pic16F876A, hs_osc, wdt_on, pwrt_on, lvp_off, protect_on
to :-
#CONFIG
__config _FOSC_HS & _WDT_ON & _PWRTE_ON & _BODEN_ON & _CP_ALL & _LVP_OFF
#ENDCONFIG

In my header the change was from :-
serout USBport,T9600,[12,"*** Diagnostic Display Unit v1.3 ***",13,10]
to :-
serout USBport,T9600,[12,"*** Diagnostic Display Unit v1.4 ***",13,10]

Compiled and loaded OK except now the PC does not receive valid data.
If I load in the 1.3 version originally compiled with PBP2.5 all works OK.
If I then load in the changed version created with PBP3 then the Serout data is corrupted (no display or strange characters).

The only changes made were the #Config and the single change to the Serout line.

I downloaded and installed the latest versions of PBP3 (3.0.7.4), latest MPLAB 8.90 and MCSP 5.0.0.5 and melabs programmer 4.50.
Compiled and loaded the program again and still incorrect operation.

I tried replacing Serout with:-
Serout2 USBport, 84,[12,"*** Diagnostic Display Unit v1.4 ***",13,10] and the display behavior is incorrect and identical to the Serout.

I removed the #CONFIG lines and set the config bits manually in the programmer --- still not working correctly.

I reduced the speed down to 1200 but problem persists.

Anyone have any suggestions ?

Demon
- 14th June 2013, 14:27
What if you don't use this?
_BODEN_ON

Is your voltage stable?

Edit: Did you select correct PIC in MCS dropdown list?

Robert

Muzza
- 14th June 2013, 15:34
Robert,
Yes, voltage is stable.
Yes, definitely selected 16F876A.
Tried it with only _HS_OSC (am using a 8MHz crystal and Define OSC 8) and all other config items set to OFF ... no joy.
Tried deleting all my program except the basic requirements to print one word of text i.e. serout PortB.5,T9600,[" TEST ",13,10]... no joy.
If I load the old version HEX file it works perfectly.
If I load a HEX file created with PBP3 it fails to print.
Tried serout USBport,2,[12,"*** Diagnostic Display Unit v1.4 ***",13,10] with no modedefs.bas included and no joy.
Tried another PCB assembly and another PC and behaviour is the same (no text on version compiled with PBP3 but works correctly with the old HEX file loaded).

I also tried installing the PBP3 etc on an old PC I have (Windows XP) in case the issue was related to the Windows 7 on the PC I had been using... no joy there either.

HenrikOlsson
- 14th June 2013, 16:50
Hi,
It looks like you might have the wrong syntax/constant name. Try:

#CONFIG
__config _CONFIG1, _HS_OSC & _WDT_ON & _PWRTE_ON & _BODEN_ON & _CP_ALL & _LVP_OFF
#ENDCONFIG


/Henrik.

AvionicsMaster1
- 14th June 2013, 19:18
I think you have to indent the __config line. I know it sounds stupid but it may solve the problem.

Demon
- 14th June 2013, 22:05
Yup, indentation counts in assembler. I think column 1 was for labels.

Robert

Muzza
- 14th June 2013, 23:43
Thanks, __CONFIG line was indented:-
In one test I copied the example from the 16F876A.INFO file and only changed XT to HS.
I have even removed the the #CONFIG/#ENDCONFIG completely and set the config bits via the programmer.
Have tried a bunch of variations around the config bits down to having everything Off except OSC=HS (8MHz crystal)

The software functions perfectly except for the corrupted Serout in all cases above.
The software reads a data pulse train and timing is critical.
There is a 3 digit LED display on the unit and that displays correctly...only Serout (or Serout2) does not work.
My logic probe confirms that data is being sent but no variation of setup (baud, bits, stops, parity) in the PC will result in a display other that gobbledygook.
BTW, my ASCII output is on RB5 and that pin feeds into a FTDI FT232R.

So, methinks my issue is either:-
Config (but I have tried heaps of variations there) or,
a corrupted modedefs.bas (but I have tried Serout USBport,2,etc and I have tried Serout2) or,
it is MCSP/PBP3/MPASM3 not being happy with the 16F876A (have tried two sets of hardware) or,
some issue between MCSP/PBP3/MPASM themselves (have tried these loaded on Windows 7 and on XP).

I did develop a little timing control unit (for variable wipers) using PBP3 and had Serout setup to help with development.
The unit took input from the speed of the vehicle to vary the wipe timing and used Serout to get the speedo pulse rate vs speed.
This was on a 16F88 and Serout worked just fine.... which why I am suspecting some issue between MCSP/PBP3/MPASM and the 16F876A ?

I have not tried starting a new .PBP file and typing up the basic program needed to just get an ASCII output.
I can also reload the older version of PBP (have the disks) onto the XP machine and see how that goes.

BTW, I created this unit design over 5 years ago and they have performed without issue until recently when one site was not displaying data correctly.
Tracked that down to a noise on the input signal (unique to the site) so I added some filtering to the input circuit... problem solved.
I can leave it running with the old .HEX file for now.. changing the header is just a nicety.

My issue is that, if in the future I do have an issue that needs to be fixed in software, this Serout issue is going to be a big problem... would rather find a solution sooner rather than later.

Appreciate the queries raised so far... please keep going... there must be something ....

AvionicsMaster1
- 15th June 2013, 00:25
From what I'm understanding you're saying is the only thing you changed in your probram was the config line. So, to me, there has to be something wrong with that. I'm not familiar with machine language but the formatting of that line doesn't match the manual. There is supposed to be a space between config and ampersand(&) character. You also say the line is indented but, may sound stupid, did you use tab and is tab giving enough columns for the asm to work?

There also not the same config items from PBP2.6 to the PBP3.0 code snippet. Are those config names correct?

If you do figure this out, please let us all know.

Demon
- 15th June 2013, 00:49
Can you blink an LED?

Robert

Muzza
- 15th June 2013, 03:22
AvionicsMaster1 - yes, only changed the CONFIG part.
Does not matter if I delete the #CONFIG part from the code and set OSC=HS in the programmer... same result.
I tried indent, just now, with TAB as well with varying number of spaces...same result.
Contents of the Config line are as per PIC16F876A.INFO... see below.

Robert - all other aspects work correctly:-
The code determines the data from the incoming pulse stream and displays correctly on the 3 digit 7 seg display, operates a buzzer with a beep to advise on a new code being displayed etc. All this is based on pulse duration timings via interrupts and using Timer1.
Except for Serout it all appears to be working correctly.

My striped down code is as follows:-

define osc 8
include "modedefs.bas"

#CONFIG
__config _HS_OSC & _WDT_ON & _BODEN_ON & _PWRTE_ON & _CP_OFF & _LVP_OFF
#ENDCONFIG

' Setup Ports
ADCON0 = $00 'Disable AD ports
ADCON1 = $07 'Disable AD ports
Segments Var PORTC 'Data
LEDdigit Var PORTA 'Control
TRISC = $80 ' Set segment pins to output
TRISA = $f0 ' Set digit pins to output
PortC = $FF
PortA = $FF
TRISB = %00000011 ' Set RB0, RB1 i/p rest o/p
TRISA = %00001000 ' Set RA3 i/p rest o/p
USBport var PortB.5
Buzzer var PortB.4
Buzzer=0
ModeSw var PortB.1
Modesw=0

Once var bit ; added so print only occurs once
once=0

pause 1000

'=========== Print Header ==============

mainloop:
if once = 0 then
serout USBport,T9600,[12,"*** Diagnostic Code Unit v1.4 ***",13,10]

once = 1
endif

goto mainloop


Note that if I use :-
__config _HS_OSC & _WDT_OFF & _BODEN_OFF & _PWRTE_OFF & _CP_OFF & _LVP_OFF
Result is the same.

ALSO, I noticed in this post that the Indent is missing from the __CONFIG line.
The editor in this posting system must remove leading spaces.
It is there in MCSP.

LinkMTech
- 15th June 2013, 03:52
Noticed that your posted "define" is not uppercase. It will be ignored and the clock speed will default to 4MHz throwing off your expected SEROUT generator baud rate.

Muzza
- 15th June 2013, 05:35
LinkMTech, when I type in "DEFINE" in uppercase it is converted to lowercase in MCSP.
Same is true for INCLUDE and for #ENDCONFIG - these are also converted to lowercase automatically by MCSP.
Note that #CONFIG stays in uppercase.

Muzza
- 15th June 2013, 06:07
OK, something interesting....

I opened a new tab in MCSP and physically typed the following (shown as it appeared in MCSP):-

define OSC 8
include "modedefs.bas"

#CONFIG
__config _HS_OSC & _WDT_OFF & _BODEN_OFF & _PWRTE_OFF & _CP_OFF & _LVP_OFF
#endconfig

ADCON0 = $00
ADCON1 = $07
TRISB = %00000011
USBport var PortB.5

Once var bit
Once = 0

pause 1000

mainloop:
if once = 0 then
SEROUT USBport,T9600,["TEST",13,10]
once = 1
endif
goto mainloop

AND IT WORKED !!

I then modified the striped down file to be exactly the same as the above and IT DOES NOT WORK.
The "striped down" file was the original .PBP saved as another named file and then the bulk of the lines deleted.

It appears that it has something to do with the .PBP file created with the old version MCSP ???
This could explain why my recent use of Serout on the 16F88 worked as that code was created within the PBP3 version of MCSP.

I went back to old backups and tried those...same problem.
Could it be a corrupted .PBP file or some strange incompatibility between files created in the old version MCSP and the new PBP3 version ?

I'll post a question to Mecanique and see what they suggest.

Depending on what Mecanique come back with I will play around with recreating the 16F876A code, although, am not keen to retype 780-odd lines... will see how much I can paste.

This is a weird one !!

Muzza
- 15th June 2013, 14:01
OK, some developments and clarity on what is going on.....

I worked out that I updated to MCSP 5.0.0.5 a year after my purchased upgrade period had expired, so thought it may be related to doing an upgrade without a valid activation key and hence some limiting factor with MCSP.
So, I paid for the latest MCSP update and installed it.
The latest version is 5.0.0.5
Opened my original .PBP, modified it (config stuff only), compiled and loaded.
Serout still does not work.

Then....
I took the file I created (see my last post above) with the latest MCSP and where I had typed in the basic setup for my 16F876A and that had worked and then pasted in the rest of the code from my original file.
It works !

So, in my case, it is definitely something to do with .PBP created with old MCSP and modified in new MCSP.

It is either a formatting difference between the old version and new version .PBP files within MCSP
or
It could be a general issue with versions of MCSP
or
It could be only my specific case and that my .PBP file was corrupted some time in the past and that the new MCSP is sensitive to that.

Not sure yet.

I have raised this with Mecanique and am awaiting a response.

Thanks for all those that replied... helped me focus down to what the issue really is.
If I hear back from Mecanique I'll do an update to this thread.

LinkMTech
- 15th June 2013, 17:10
Muzza,
I had somewhat of a similar problem when using Darrel's Instant Interrupts.
When I copied/pasted his posted code over my typed "problem" code of the exact wording, it worked!

I thought he had some type of special code in his typed code. But it turned out that I had the Reserved Word Formatting set to "Uppercase all" so I fooled myself into thinking I typed a certain word uppercase when it wasn't.
I immediately changed it to "Default" so I would see what I'm actually hen pecking!

The MSCP setting is under: View --> Editor Options --> Highlighter, then Reserved Word Formatting at the bottom.

You have yours set to "Lowercase all" which may be hiding the real typed word causing the headache!

Muzza
- 16th June 2013, 02:38
Yes, it was set to lowercase.
I set it to Default.

Looked through the code but could not see anything untoward.
Even pressed Enter at the end of each line in case there was some characters to the far right off screen... but no.

Note that Define and Include comes up in Code Explorer, on the left in MCSP, regardless of the case used for those statements.

I then opened my original .PBP deleted the @DEVICE line and typed in the Config stuff, compiled and loaded.
Still the same problem.
I then restored my original .PBP and deleted the @DEVICE line, compiled, set OSC to HS in the programmer and loaded.
Still the same problem.
I then opened a new file and copied and pasted the entirety of the original file, deleted the @DEVICE line, and set the Config bits in the programmer.
Still the same problem.

The only thing that worked was as in a few posts above where I opened a new file, hand typed the lines needed to get Serout working and then pasted in the balance of my program.
If there is a corruption then it must be at the top but I cannot see it after scanning that section a bunch of times.
Hmmm...

Nobby123
- 10th October 2013, 19:46
Hi Muzza.
Did you ever find a solution to this problem?
I am trying to convert a program with SEROUT to PBP3 and just have garbage on the serial LCD screen.

Demon
- 10th October 2013, 19:56
I'd be curious to see what a compare utility would generate. We used to have these in mainframe programming; great for finding muckups like this one.

Robert

Edit: something like this
http://www.prestosoft.com/edp_examdiff.asp

Muzza
- 11th October 2013, 04:00
No, nothing back. I did try a few times but no joy.
Suggest you might try what worked for me....
open a new file in PBP3, hand type the lines needed to get Serout working and then paste in the balance of the program.

Nobby123
- 11th October 2013, 17:55
Thanks for that. I will give it a go.:)