Difference between revisions of "BoostC from the Fourm"

From OpenCircuits
Jump to navigation Jump to search
Line 225: Line 225:
  
 
I ran into a 'bug' in the PIC part itself. I found the solution here: http://forum.microchip.com/fb.aspx?m=306403  The 16F88 and a few other chips become unprogrammable if you use MCLR as an IO pin, you use the internal osc, and you set TIMER1 to use the internal osc as a clock source.  If you do all three, you can no longer program the part. The post gives the solution to recovering the chips.
 
I ran into a 'bug' in the PIC part itself. I found the solution here: http://forum.microchip.com/fb.aspx?m=306403  The 16F88 and a few other chips become unprogrammable if you use MCLR as an IO pin, you use the internal osc, and you set TIMER1 to use the internal osc as a clock source.  If you do all three, you can no longer program the part. The post gives the solution to recovering the chips.
 +
 +
 +
== going on ==
 +
 +
 +
  
 
stopped on the one above
 
stopped on the one above

Revision as of 09:35, 18 January 2009

Introduction

This is the extraction of useful info on BoostC from its forum. Each extract starts with a link to the foum thered, read it in full if you wish. I have removed names and edited the text in a way that I hope makes it more readable. It is just a forum, the postings may be outright wrong, or out of date. The final product is mine ( I am responsible for posting the material ( check page history), I claim no ownership, nor am I responsible for the accuracy of the material or your results using it. ) If you object let me [russ_hensel] know, or fix it yourself. It is a wiki so others than [russ_hensel] may have added/edited the content. Not included:

  • Things unresolved:
  • Errors made by questioner
  • Compiler issues that should have been fixed by now or soon
  • Most hardware issues
  • Things that i thnik are covered in the manual
  • Documentation of most things you cannot do.
  • Notices of projects, websites.... we should have these in the PIC Links or some other place.
  • Things I do not understand.

2008 Extracts

User had problem geting consistent data reading and writing to an IO port: Response:

Sounds like the classic read modify write issue, when ports externally are being dragged down by whatever is connected to them. Remember that when a port is read on a PIC16 the actually logic level on the pins are read, not the last data written. This is not a problem on PIC18 if you use the LAT register as this actually holds the last data written.

Possible solutions: 1) Don't drag down the outputs with excessive load. 2) Use a shadow register to hold the data written to the port.


Is This Technique Ok?, Implementing an array of function pointers .....

Russ says: do not understand well enough to summarize, someone else want to take a wack at it


You can use the standard C macros for time and date which will generate text strings.

CODE
char time[] = __TIME__;  // "16:38:53"
char date[] = __DATE__;  // "Nov 30 2008"


Question: I can understand that the isr may interrupt the 'main loop' at any point and hence (global) variables may be in a inderterminate state, but why can't functions be used in both isr and main routines.

Surley the sw stack is used for 'main' and 'interrupt' functions, so local vars so they should be safe while the isr is running??

Answer: The software stack (or memory overlay) means that all the memory useage on the "stack" has to be known at the time of linking the program. That makes functions that use the software stack un-interruptible or corruption will occur.


I am using the BoostC compiler using the MPLAB environment (to be able to use the ICD2) and am doing a project that uses a number of source files (11 or so C files at the moment) to keep it all nice and modular.

However, I can't seem to find any way of doing a 'make' of the project (i.e. only recompile changed source files).

There only seems to be a 'build' that explicitly deletes all object files and then rebuilds the whole lot!

Am I missing something? No. Thats the only option under MPLAB

Regards Dave

Question: Does anyone know how to set the configuration for the PIC16F877A? In general, how do we know to set the configuration for any specific PIC, let's say PIC18F452?

Answers:

    • The 887 has a wizzard, use it.
    • Use any number of example programs out there.
    • Use a guide for assembler, port.bit = xxx or set_bit clear_bit are easy to translate.
    • pragma s are used for some settings rtfm
    • be prepared to be amaized at how many mistakes can be made.

http://forum.sourceboost.com/index.php?showtopic=3762&pid=14225&mode=threaded&start=#entry14225

GPIO is not currently supported by the PIC simulator. Its on the todo list, but we haven't got round to it yet


To build (compile) a library, goto "Settings -> Options...", select Output Type: Library radio button.

To add a library to your project, goto the Workspace (project) window (left of screen usually), right click and add the .lib file you want to include.

I think left out a subtle point in that most libraries need not only a .lib but also a .h which defines the function prototypes that the library contains. Then, the user of the library would also include the .h file in the source that is using it so that the compiler knows what to expect. This is the same as if you have multiple files in a stand-alone compile.

KeyLib.h

Header files (.h) are not generated automatically. You have to build them yourself.

Open a blank page. Insert you function prototypes as trossin says (char ScanKeyMatrix(void). Save the file as test.h

You now have your .h file to match your .lib file.

Remember: If you use #include <test.h> , the compiler expects the .h file to be in the ...\SourceBoost\include directory. Use #include "test.h" if the header is in your local project directory. Or just use the full path name.

Settings -> Options -> BoostC compiler Options -> Extra linker options. What you add in the extra linker options is appended to the regular linker command line. You can append anything you want


It is not be possible to alter configuration words from the bootloader context. That is your program should have the same configuration as the bootloader.


This looks like well documented but included as a goctgha Have you tried reading the GPIO ports before clearing the interrupt flag GPIF? The port has to be read to end the change mismatch condition otherwise GPIF will just set itself again (page 21 of data sheet).




...Is it not possible to get quick access to bits in an array?... No it's not. You have to use good old bitwise operators.

I had the UART on my USB/Serial thinger configured for 3V. That makes sure it does not work correctly gotcha.


All features supported by SourceBoost IDE built-in simulator are listed in Users Manual. So anything NOT listed in the Users Manual (such as the Comparator), is NOT supported in the Simulator.


Well as it turns out, once you come back from interrupt, the ports doesn´t retain the original configuration( analog comparators get turn on when they where off before interrupt). So now, I turn comparators off again, and load values in porta and portb, before coming back from interrupt. Also I put a "while" loop in the interrupt service routine, to compare the value that portb should have with no key pressed, so if the key still pressed I scan the keyboard again BEFORE leaving the interrupt service routine. As soon as I have the time I think I´ll upload a post on dealing with wake up from sleep on interrupts, because I think it might benefit beginners like me.

I have a mystery. After using BoostC for some time all of a sudden there's no *.map file generated Boostc compiler and linker has never generated a map file. The best option is to look in the *.lst file to find where everything is.


The BoostC compiler does not currently support PIC18 Extended instructions. This may change, rtfm.


Post- and pre-build steps are now implemented in our working ide copy and will be available in the next release. It will work like this: when build command is issued IDE first looks in the project directory for a file called prebuild.bat and if found executes it. At the end of a successful build IDE looks in the project directory for a file called postbuild.bat and if found executes it. It's up to a developer to create those files. If such files don't exist build goes how it used to do. -- Should be implemented by the time you read this.


BoostC does not have much of a stimulus, but wait: there is the signal generator in the extra plugins. Some devices have full ADC support and so the signal generator can be used on those with the ADC. Also the signal generator can be connected to digital pins to provide other stimulation. Also highly exact timings can be had with the stopwatch plugin.


Boostc doesn't support 12 bit instruction PICs. See the list of supported devices to see what is supported, it is a lot.

extracted but not yet cleaned up

http://forum.sourceboost.com/index.php?showtopic=3593&pid=13553&mode=threaded&start=#entry13553

The problem is that Debug Express reserves RAM, as well as some program memory, for its own use. e.g. on the 16F887 it reserves 0x070, 0x0f0, 0x165 to 0x170 inclusive and 0x1f0. (These are shown as RR in the MPLAB IDE file registers window). On larger projects requiring more RAM BoostC has no knowledge of these reserved locations and simply overwrites them.

Does anyone know the best way, if there is one, of reserving these or any other locations to prevent them being used by BoostC? Declare fixed address variables at the locations you want to protect. BoostLink will work around any fixed address variables.

Something like this would fit the bill: CODE char reserved_0x070 @ 0x070; char reserved_0x0F0 @ 0x0F0; char reserved_0x165[ 11 ] @ 0x0165; char reserved_0x1F0 @ 0x1F0;

Regards Dave

even still more

...Is it not possible to get quick access to bits in an array?... No it's not. You have to use good old bitwise operators.

When a project contains multiple source files, is there a way to compile a single file? You can try using "Project -> Quick", then select the source (.c) file you are interested in, and a mini project will be created containing only that single file. When you are done, just delete the mini project file and go back to the main project.

I am going to use the float.h and float.pic18.lib files. Since I am going to calculate floats and I need to represent them on a LCD display, I have only one idea to work-around the missing "%f" in the lprintf format; I multiplicate the float variable by 10 (for example, needing only one decimal digit), convert it into long variable and then calculate the integer part (with sign) and the decimal of that long variable. That should give me more possibilities to show a float-to-long variable on LCD... Any other ideas?

This basically does what you suggested. Just format the intPart and fracPart with a decimal point between into a string.

void main(void) {
    float    myfloat;
    int32    intPart;
    int32    fracPart;
 
    myfloat = 3.14;
     
    intPart = float32_to_int32(myfloat);
    fracPart = float32_to_int32(float32_mul(float32_sub(myfloat, float32_from_int32(intPart)), 10.0));
}

I ran into a 'bug' in the PIC part itself. I found the solution here: http://forum.microchip.com/fb.aspx?m=306403 The 16F88 and a few other chips become unprogrammable if you use MCLR as an IO pin, you use the internal osc, and you set TIMER1 to use the internal osc as a clock source. If you do all three, you can no longer program the part. The post gives the solution to recovering the chips.


going on

stopped on the one above