Difference between revisions of "BoostC Forum Extracts 2007"

From OpenCircuits
Jump to navigation Jump to search
Line 290: Line 290:
 
-------
 
-------
  
=== stop at ===
 
  
  
http://forum.sourceboost.com/index.php?showtopic=2707&pid=10443&mode=threaded&start=#entry10443
+
---------
is there a way to fill data to an address relative to _EEPROM
+
== EEProm Data ==
 +
*From:  http://forum.sourceboost.com/index.php?showtopic=2707&pid=10443&mode=threaded&start=#entry10443
  
like
+
Is there a way to fill data to an address relative to _EEPROM like:
CODE
+
 
#pragma DATA _EEPROM,    1, 2, 3
+
    #pragma DATA _EEPROM,    1, 2, 3
#pragma DATA _EEPROM+10,  1, 2, 3
+
    #pragma DATA _EEPROM+10,  1, 2, 3
#pragma DATA _EEPROM+20,  1, 2, 3
+
    #pragma DATA _EEPROM+20,  1, 2, 3
  
  
 
because the preprocessor doesn't seem to accept this one
 
because the preprocessor doesn't seem to accept this one
  
No this is a limitation  
+
No this is a limitation Have a look at where _EPROM is defined, use this address manually adding the required offset.
Have a look at where _EPROM is defined, use this address manually adding the required offset.
 
  
  
 
-------
 
-------
http://forum.sourceboost.com/index.php?showtopic=3358&pid=12600&mode=threaded&start=#entry12600
+
=== Plugins ===
Tried the LCD display plugin with the sample picdem2+ project.
 
 
 
Built ok, but when I run it in debug mode, the lcd window disappears?
 
 
 
What am I doing wrong?
 
 
 
J
 
 
 
 
 
IDE has 2 layouts: for edit and for debug modes. It seems that you opened the lcd plugin when debugger was in edit mode but when you starte debugging ide uses its debug mode layout that does not have this plugin open in there. Just open the ldc plugin while debugging.
 
 
 
  
 +
*From:  http://forum.sourceboost.com/index.php?showtopic=3358&pid=12600&mode=threaded&start=#entry12600
  
 +
Q:  Tried the LCD display plugin with the sample picdem2+ project.  Built ok, but when I run it in debug mode, the lcd window disappears?
  
 +
A:  IDE has 2 layouts: for edit and for debug modes. It seems that you opened the lcd plugin when debugger was in edit mode but when you starte debugging ide uses its debug mode layout that does not have this plugin open in there. Just open the ldc plugin while debugging.
  
  
  
 
------
 
------
http://forum.sourceboost.com/index.php?showtopic=3348&pid=12571&mode=threaded&start=#entry12571
+
=== what ===
 +
* From:  http://forum.sourceboost.com/index.php?showtopic=3348&pid=12571&mode=threaded&start=#entry12571
  
'm curious if it is possible to turn off all the optimizations within the ASM code.
+
Is possible to turn off all the optimizations within the ASM code.
 
Well, i need to make some very time paced routines that jump into different tables and output it on different pins.
 
Well, i need to make some very time paced routines that jump into different tables and output it on different pins.
 
But now BoostC compiles in my ASM code all the different bank switching instructions.
 
But now BoostC compiles in my ASM code all the different bank switching instructions.
Line 341: Line 333:
 
Btw: The "goto $+1" seem very stupid for a c compiler, but it would be neat if that's possible somehow.
 
Btw: The "goto $+1" seem very stupid for a c compiler, but it would be neat if that's possible somehow.
 
I even tried
 
I even tried
CODE
 
_asm{
 
  goto label
 
  label:
 
}
 
 
Regards,
 
Thomas Interested in advertising here? Contact support@sourceboost.com
 
 
 
 
 
  
Use:
+
  _asm{
 +
      goto label
 +
      label:
 +
  }
  
CODE
+
Use:
asm{
 
  goto label
 
  label:
 
}
 
  
 +
asm{
 +
    goto label
 +
    label:
 +
}
  
  
Line 368: Line 351:
 
http://forum.sourceboost.com/index.php?showtopic=3337&pid=12527&mode=threaded&start=#entry12527
 
http://forum.sourceboost.com/index.php?showtopic=3337&pid=12527&mode=threaded&start=#entry12527
  
would like to know if BoostC supports pointers to function; are there any limitations or not?
+
Would like to know if BoostC supports pointers to function; are there any limitations or not?
Thank you.
 
 
 
Paolo. Interested in advertising here? Contact support@sourceboost.com
 
 
 
 
 
 
 
 
 
 
 
 
 
Replies manuel123 Oct 31 2007, 01:46 PM
 
Post #2
 
 
 
 
 
Newbrie
 
 
 
 
 
Group: EstablishedMember
 
Posts: 19
 
Joined: 21-September 05
 
Member No.: 829
 
 
 
  
Hi Paolo,
 
  
 
function pointers are supported since v6.70. See
 
function pointers are supported since v6.70. See

Revision as of 20:21, 6 February 2009

Almost Ready For Reading

A macro like MAKESHORT can initialize a variable but the compiler does not know that and generates a warning. Is there a way to solve this without initializing the variable explicitly?

    u16_t timestamp;

    t1con.TMR1ON = 0; // stop timer
    MAKESHORT(timestamp, tmr1l, tmr1h);

    en_of_pulse = timestamp; <<==== causes warning

It's not the macro that's the problem, but the inline assembly it uses. The compiler doesn't notice if you set a variable with inline assembly statements and warns that it's possibly uninitialized. Declaring the variable as 'volatile' gets rid of the warning, but isn't a great solution as you might miss a true 'uninitialized' case.

I am not an expert, but I think I have seen compilers that have pragma's that give hints to compiler about these things.

initializing struct

Problem initializing struct. Whah, this doesn't work!

typedef struct {
    char foo[11];
    bar_enum bar;
} baz_list;

baz_list baz[] = { "0123456789", quux,
                   "0123456789", quuux,
                   "0123456789", quuuux
                 };

I can create a two dimensional array of strings and initialize them or a array of enums and initialize them but not an array of structs.

A more premitive question to ask would be why:

CODE
struct thing {
  char ch_1;
  char ch_2;
};
 
struct thing thingy = {2,2};

doesn't work.

I believe you're going to have to assign the values yourself. I'd say use an inline function or something to make it look neater:

struct thing {
  char ch_1;
  char ch_2;
};

inline void set_thing( struct thing &i_thing, 
                       unsigned char ch_1, 
                       unsigned char ch_2 ) {
  i_thing.ch_1 = ch_1;
  i_thing.ch_2 = ch_2;
}

void main( void ){
  struct thing i_thing[3];
  set_thing( i_thing[0], 2, 3 );
  set_thing( i_thing[1], 5, 3 );
  set_thing( i_thing[2], 1, 9 );

Found the thread - http://forum.sourceboost.com/index.php?showtopic=3404


function prototypes

    • Question 1:

Function prototypes, It looks like they are allowed, but not required nor enforced?

Prototypes are required if you do a forward reference to a function. If you are in the habit of using them, then always use them. I do.

delay timer

    • Question 2:

If I call

 delay_ms(1000 ); 

I get no warnings. Is there a way to make it more strict?

If you go to Settings - Options and enable All warnings the compiler will warn you if you exceed 255 for a delay.

interrupt handlers

    • Question 3:

Interrupts; If I don't put the interrupt function in my code, is there a default handler?

There is no default interrupt handler that I can see. Keep GIE = 0 if you don't want you program to go into the woods.

    • Question 4:

Global variables vs volatile; If I declare a variable in a header file, and wish to use it in both a main thread function and an interrupt handler, do I really need to declare it volatile?

If I was sharing a variable with main and interrupt, I would probably make it volatile. It all depends on how your main code is written and how many times the variable is used in main. The compiler may retain the variable value between uses and the interrupt may change its value between uses. You could always devise a semaphore type system.


location of variables in memory


I had some code that suddenly got bigger and slower and all I'd done was change the size of an array, though no variables ended up placed anywhere but bank 0. ...

read the post for some info an location of variables in memory, bank switching ..... size and speed.



Boostc gives me the warning Caution: Delay inaccurrate: 'delay_us', Delay overhead:0.01ms, Unit delay:0.001ms

How do I interpret the overhead and unit delay....?

delay_us( 1 ) gives 0.01ms + (1 * 0.001ms) = 11us delay_us(12) gives 0.01ms + (12 * 0.001ms) = 22us delay_us(13) gives 0.01ms + (13 * 0.001ms) = 23us

delay_us(0) results in 0.01ms + (255 * 0.001ms) = 265us



notes that I am not able to summarize about structs union and access of sub-components, you need to read this yourself.



Best Method For Accumulated Timer -- Go read it for more info.



May be useful for lcd read and other purposes, I cannot summarize. Go read it for more info.


more


How do i measure the eact timing on my code using boostc?

Set breakpoints in the debugger at the beginning and end of the code you want to evaluate. in the debugger you can see the amount of ticks. so when you let it run from breakpoint to breakpoint you are able to see how manny ticks it took. If I don't oversee something here ( ) this should be a working method to determine the exact time it takes to run that peace of code.....

A tick appears to be an oscillator cycle. If you step through a 1 cycle instruction it will increment the tick count by 4. A 4MHz xtal will give 1us instruction cycle time.

The tick count will change to values in 'kilo' after a while i.e. 10k etc. which cannot be reset to zero.

More exact timings come with using the StopWatch Plugin, get it if exact timing of code is needed.

If you install BoostC within MPLab (Microchip IDE) you can use its watchdog feature measure in real time.



As has been pointed out, you should have i != 100 and i++. But in general, it's said to be safer to use "<" than "!=" in such a loop as it can prevent infinite loops if the "i" gets changed somewhere else in the loop.

If you KNOW that the loop is going to be executed at least once, you are better off using the following:

 i = 0;
 do { /* loop contents */ } while ( ++i != 10 );

Or if "i" is ONLY used as a counter, the following can be better still:

 i = 10;
 do { /* loop contents */ } while ( --i != 0 );

Both can produce shorter, faster code!



You can't cast rom to not-rom types or vice versa. I'd either do 2 switch constructions: one for rom and another for not-rom arrays or use a buffer where rom arrays will be copied before use.

Regards,

New to C and I may be missing it, but I think assignment it the wrong way to go, instesad use a string copy to move from rom to ram. I know this sor of thing works because I do it all the time.

Russ

initializing struct

I have a structure:

    typedef struct 
    {
    unsigned int A; 
    unsigned int B;
    unsigned int c;
    } ConvertCoeff;

and I declare an array of this structure:

    ConvertCoeff coeff[8];

As long as I leave it this way everything is OK. But if I try to intialize the array during decleration as follows:

    ConvertCoeff coeff[3] = { {1,2,3}, {1,2,3}, {1,2,3}};

I get an error during compilation - missing semicolon. Is it not a legitimate initialization? I know it is possible on other compilers - how do I do it in BoostC?

It apears that BoostC does not like initialising structures like other compilers. You will have to fill your structure the hard way.


interrupt handlers

the linker generates a serious stack warning because I have a function which is called within the handling of a rb0 interrupt and also in the program main loop. I can imagine that this can cause problems when the function is called by the interrupt routine and within the main() loop at the same time.

But under specific conditions the rb0 interrupt handler (which contains that function call) is disabling it's interrupt and activates a flag. Depending on that flag the mentioned funtion is called in the main loop.

So that function, referred to in the warning, can never be called in the interrupt routine at the time it´s also being executed because of a call within the main loop!

This is still all tricky or it´s not a problem to ignore this warning under this conditions? If you are sure you are handling this situation correctly you can ignore this warning, your code looks like it maybe ok, but this kind of code can be tricky to understand.


delay timer

Yes, this one bit me too! I wrote the following routine that you can use for any ms value from 1 to 65535. I timed it at 60,000 and it seems to be pretty much on the money.

 void delayMs(unsigned int ms){
      char i;
      char high = ms >> 8;
      char low = ms & 0x00ff;
      for(i = 0; i < high; i++){
           delay_ms(255);
      }
      delay_ms(low); 
 }

You might think that it needs another delay_ms(1) in the loop but I got the most accurate time without it.



Is it possible for lprintf to write a substring to the lcd?

eg. I've got a string 254 bytes long, but I only want to print 16 chars to the first line of the display.

I tried lprintf("%c",buffer[i]) in a for loop, but that didn't work (no compiler error though).


...
    lcd_datamode();
    char c, i;
    for( i = 0; i < 16; i++ )
    {
        c = buffer[i];
        if( c == 0 ) 
            break;
        lcd_write( c );
    }
...




That's it. Adding -d DEBUG to the compiler options does exactly what I want. Thanks very much.

Edward





EEProm Data

Is there a way to fill data to an address relative to _EEPROM like:

    #pragma DATA _EEPROM,     1, 2, 3
    #pragma DATA _EEPROM+10,  1, 2, 3
    #pragma DATA _EEPROM+20,  1, 2, 3


because the preprocessor doesn't seem to accept this one

No this is a limitation Have a look at where _EPROM is defined, use this address manually adding the required offset.



Plugins

Q: Tried the LCD display plugin with the sample picdem2+ project. Built ok, but when I run it in debug mode, the lcd window disappears?

A: IDE has 2 layouts: for edit and for debug modes. It seems that you opened the lcd plugin when debugger was in edit mode but when you starte debugging ide uses its debug mode layout that does not have this plugin open in there. Just open the ldc plugin while debugging.



what

Is possible to turn off all the optimizations within the ASM code. Well, i need to make some very time paced routines that jump into different tables and output it on different pins. But now BoostC compiles in my ASM code all the different bank switching instructions.

Does anybody know if it is possible to turn off all the optimizations? (off course then you have to know exactly what you're doing!) Otherwise it would be a neat enhancement.

Btw: The "goto $+1" seem very stupid for a c compiler, but it would be neat if that's possible somehow. I even tried

 _asm{
      goto label
      label:
 }

Use:

asm{
   goto label
   label:
}



http://forum.sourceboost.com/index.php?showtopic=3337&pid=12527&mode=threaded&start=#entry12527

Would like to know if BoostC supports pointers to function; are there any limitations or not?


function pointers are supported since v6.70. See

http://www.sourceboost.com/CommonDownload/VersionLog.html

Limitations: - As far as I know arrays of function pointers are not supported. - It seems that the call tree is not parsed through function pointers. So, function pointers should be used together with a software stack or -very carfully- with the hardware stack. See http://forum.sourceboost.com/index.php?showtopic=3279


last

16th October 2007 - 05:39 PM http://forum.sourceboost.com/index.php?showtopic=3301&pid=12469&mode=threaded&start=#entry12469

I have a project that needs to save alot of config data ect. The eeprom in the pic is not big enough to store all data: I have alot of free flash in the PIC can I use that to store data whit read and write to flash funtions? It will not be alot of writeing and read. Or should I use a external eeprom? Interested in advertising here? Contact support@sourceboost.com



1. The easiest is to store data in normal RAM using variables or an array. 2. However, I suspect you are referring to program memory (ROM) which can be written to when programming with the BoostC 'rom' command and read at any time. 3. If you want your PIC program to update this data on the fly you need to have a device which supports 'self-write' ('Enhanced Flash' versions in the 16F series or available in most or all? 18F's). Harder than 1 or 2. 4. External memory will be more work than 3. David.