Difference between revisions of "BoostC Forum Extracts 2007"

From OpenCircuits
Jump to navigation Jump to search
Line 241: Line 241:
  
 
----
 
----
 +
 +
http://forum.sourceboost.com/index.php?showtopic=3431&pid=12843&mode=threaded&start=#entry12843
 +
 +
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 ) -> 12us
 +
delay_us(12) -> 23us
 +
delay_us(13) -> 24us
 +
or
 +
delay_us(1) -> 12us
 +
delay_us(12) -> 12us
 +
delay_us(13) -> 13us
 +
or
 +
??? Interested in advertising here? Contact support@sourceboost.com
 +
 +
 +
 
 +
 +
 +
 +
 +
Replies fred Dec 23 2007, 05:11 PM
 +
Post #2
 +
 +
 +
Enthusiast
 +
 +
 +
Group: EstablishedMember
 +
Posts: 100
 +
Joined: 1-December 06
 +
From: Netherlands
 +
Member No.: 2,116
 +
 +
 +
 +
thanks
 +
 +
uhhh, so delay_us(0) results in 0.01ms + (0 * 0.001ms) = 10us..!?
 +
No, minimum delay value for delay us is 1.
 +
 +
delay_us(0) results in 0.01ms + (255 * 0.001ms) = 265us 
 +
 +
--------------
 +
http://forum.sourceboost.com/index.php?showtopic=3424&pid=12822&mode=threaded&start=#entry12822
 +
 +
QUOTE (gbgb @ Dec 19 2007, 11:49 PM)
 +
I have a structure - e.g
 +
 +
typdef struct
 +
{
 +
unsigned int a;
 +
unsigned int b;
 +
unsigned int c;
 +
etc......
 +
} Structype
 +
 +
Structype st;
 +
 +
while throughout the code it is very convenient to access the structure elements as st.a, st.b (or st->a, st->b) etc., I have a section where I would like to read/write the values of the structure to/from the eeprom, where they are stored sequencially.
 +
This would be more conveniently done as a loop like
 +
for (i=start, i<end, i++)
 +
{
 +
x = compute address in eeprom based on value of i and some kind of offset;
 +
element i in the structure = read value from eeprom address x ;
 +
}
 +
 +
I simply cannot figure out the way to implement the left side of this last statement. Obviously if instead of a structure I would have used an array it would be a simple matter, but I am still trying to do it as a structure. All my attempt to do it by supplying the pointer to the structure and performing some kind of arihtmetics to produce a pointer to the correct address failed (failed already during compilation - I could not generate a statement that will be accepted).
 +
 +
Any ideas how this would be done?
 +
 +
 +
I use a union to do essentially the same...
 +
 +
typedef union _unionType {
 +
Structype ST;
 +
unsigned char bytes[sizeof(Structype)];
 +
} Uniontype;
 +
 +
Uniontype ut;
 +
 +
// Convenience definition for access of the structure
 +
#define st ut.ST
 +
 +
Accessing the structure looks the same as before and produces no additional code.
 +
Accessing as individual bytes is as simple as ut.bytes[byteIndex];
 +
 +
If you only have one of them, the code may well be smaller than using pointers as pointers carry the baggage of the bank select bits.
 +
 +
These are some of my working definitions:
 +
 +
CODE
 +
#define DATABYTES        2    // Number of bytes of data in our packets
 +
 +
//
 +
// Packet Payload including the Protocol Byte.
 +
// Also packet as received.
 +
//
 +
typedef struct _Payload
 +
{
 +
    unsigned char    protocolByte;
 +
    unsigned char    data[DATABYTES];
 +
    unsigned char    checksumByte;
 +
} Payload;
 +
 +
 +
//
 +
// Union to access packet as received as a byte array.
 +
//
 +
typedef union _RecvPacketUnion
 +
{
 +
    unsigned char    bytes[sizeof(Payload)];
 +
    Payload            payload;
 +
} RecvPacketUnion;
 +
 +
RecvPacketUnion    PacketReceived;
 +
 +
#define RXProtocolByte        PacketReceived.payload.protocolByte
 +
#define RXData            PacketReceived.payload.data
 +
#define RXChecksum            PacketReceived.payload.checksumByte
 +
 +
 +
Orin.
 +
 +
 +
-----------------
 +
 +
 +
http://forum.sourceboost.com/index.php?showtopic=3416&pid=12807&mode=threaded&start=#entry12807
 +
 +
Best Method For Accumulated Timer  -- go read it
 +
 +
 +
 +
-----------
 +
http://forum.sourceboost.com/index.php?showtopic=3408&pid=12790&mode=threaded&start=#entry12790
 +
 +
go read it
 +
 +
may be useful for lcd read and other ? 
 +
Here is my basic template when working with the 684 chip.
 +
 +
 +
=== more ===
 +
 +
 +
It may be of some help to you...... 
 +
 +
  LCD_684.txt ( 4.03K ) Number of downloads: 41

Revision as of 09:08, 26 January 2009

Just Starting

http://forum.sourceboost.com/index.php?showtopic=3444&pid=12904&mode=threaded&start=#entry12904


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?


FredericG, QUOTE (FredericG @ Dec 30 2007, 06:59 PM) 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? Please provide an example of what you mean exactly.

Regards Dave



s u16_t timestamp;

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

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

QUOTE 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. Thanks for the workaround, I can for sure live with that solution




http://forum.sourceboost.com/index.php?showtopic=3430&pid=12890&mode=threaded&start=#entry12890


Whah, this doesn't work!

CODE 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, and that sucks!!! (rhyme intended)

Any suggestions???

Jacob BoostC 6.81

This post has been edited by Jacob Christ: Dec 23 2007, 12:23 AM Interested in advertising here? Contact support@sourceboost.com




Replies twomers Dec 27 2007, 05:04 PM Post #2


Regular


Group: EstablishedMember Posts: 42 Joined: 28-November 07 From: Ireland Member No.: 3,919


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 can't find the thread I'm thinking of but 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:

CODE 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 );

// Or if you wish // i_thing[0].ch_1 = 2; i_thing[0].ch_2 = 3; // i_thing[1].ch_1 = 5; i_thing[1].ch_2 = 3; // i_thing[2].ch_1 = 1; i_thing[2].ch_2 = 9; }


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




http://forum.sourceboost.com/index.php?showtopic=3440&pid=12882&mode=threaded&start=#entry12882

Dec 28 2007, 12:28 PM 

Post #1


Newbrie


Group: EstablishedMember Posts: 12 Joined: 27-December 07 Member No.: 3,967


Hi, I'm a Windows C++ programmer, used to using doubles, just because why not and making huge classes. So this pic stuff is pretty different to say the least.

So far so good, still trying to get an interrupt to work, but it's obviously me, not the compiler, I did a search, popular topic!

Anyway about the compiler, BoostC, I like it better that Hitec, it seems to be a little C++ like in some ways( thats good :-).

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

If I call delay_ms(1000 ); I get no warnings.

Is there a way to make it more strict? I don't see a warning level setting anywhere, maybe I missed it?


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

Can I put the interrupt handler in any file? ( seems weird not to have to 'hook it up')


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? Why would the compiler make a copy of it for the interrupt??

Thanks Keith Interested in advertising here? Contact support@sourceboost.com




Replies Reynard Dec 29 2007, 06:42 AM Post #2


Enthusiast


Group: EstablishedMember Posts: 186 Joined: 24-October 07 From: Scotland Member No.: 3,861


Hi Keith,

This compiler is a bit different than MSC.

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.

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

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.

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.

Hitec is a very good compiler if you can afford it. Other low cost ones are MikroC and Wiz-C.

Cheers

Reynard




http://forum.sourceboost.com/index.php?showtopic=3427&pid=12856&mode=threaded&start=#entry12856

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.

I tracked it down to some uses of porta which were getting both RP0 and RP1 cleared each time before it was used. Even though in some cases, the flow of control made it obviously unnecessary, the initial clear was necessary due to accessing trisa a while back in the call tree. What was particularly bad was the bank switching instructions were inside a loop.

The simplest solution was to force a local variable that is set before the loop into bank 0 only RAM so the bank switching is done to set this variable. The extra unwanted bank switching then went away. All other access in the loop turned out to be in locations which are shared between banks.

Another solution was to force the array I'd changed out into bank 1 and yet another was to use a global variable for the bit count which just happened to be in bank 0 only RAM.

Here is the offending function. It makes no difference whether the C or assembly version is used:


read more on the thread for possible optimizations involving bank switching



http://forum.sourceboost.com/index.php?showtopic=3431&pid=12843&mode=threaded&start=#entry12843

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 ) -> 12us delay_us(12) -> 23us delay_us(13) -> 24us or delay_us(1) -> 12us delay_us(12) -> 12us delay_us(13) -> 13us or ??? Interested in advertising here? Contact support@sourceboost.com




Replies fred Dec 23 2007, 05:11 PM Post #2


Enthusiast


Group: EstablishedMember Posts: 100 Joined: 1-December 06 From: Netherlands Member No.: 2,116


thanks

uhhh, so delay_us(0) results in 0.01ms + (0 * 0.001ms) = 10us..!? No, minimum delay value for delay us is 1.

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


http://forum.sourceboost.com/index.php?showtopic=3424&pid=12822&mode=threaded&start=#entry12822

QUOTE (gbgb @ Dec 19 2007, 11:49 PM) I have a structure - e.g

typdef struct { unsigned int a; unsigned int b; unsigned int c; etc...... } Structype

Structype st;

while throughout the code it is very convenient to access the structure elements as st.a, st.b (or st->a, st->b) etc., I have a section where I would like to read/write the values of the structure to/from the eeprom, where they are stored sequencially. This would be more conveniently done as a loop like for (i=start, i<end, i++) { x = compute address in eeprom based on value of i and some kind of offset; element i in the structure = read value from eeprom address x ; }

I simply cannot figure out the way to implement the left side of this last statement. Obviously if instead of a structure I would have used an array it would be a simple matter, but I am still trying to do it as a structure. All my attempt to do it by supplying the pointer to the structure and performing some kind of arihtmetics to produce a pointer to the correct address failed (failed already during compilation - I could not generate a statement that will be accepted).

Any ideas how this would be done?


I use a union to do essentially the same...

typedef union _unionType { Structype ST; unsigned char bytes[sizeof(Structype)]; } Uniontype;

Uniontype ut;

// Convenience definition for access of the structure

  1. define st ut.ST

Accessing the structure looks the same as before and produces no additional code. Accessing as individual bytes is as simple as ut.bytes[byteIndex];

If you only have one of them, the code may well be smaller than using pointers as pointers carry the baggage of the bank select bits.

These are some of my working definitions:

CODE

  1. define DATABYTES 2 // Number of bytes of data in our packets

// // Packet Payload including the Protocol Byte. // Also packet as received. // typedef struct _Payload {

   unsigned char    protocolByte;
   unsigned char    data[DATABYTES];
   unsigned char    checksumByte;

} Payload;


// // Union to access packet as received as a byte array. // typedef union _RecvPacketUnion {

   unsigned char    bytes[sizeof(Payload)];
   Payload            payload;

} RecvPacketUnion;

RecvPacketUnion PacketReceived;

  1. define RXProtocolByte PacketReceived.payload.protocolByte
  2. define RXData PacketReceived.payload.data
  3. define RXChecksum PacketReceived.payload.checksumByte


Orin.




http://forum.sourceboost.com/index.php?showtopic=3416&pid=12807&mode=threaded&start=#entry12807

Best Method For Accumulated Timer -- go read it



http://forum.sourceboost.com/index.php?showtopic=3408&pid=12790&mode=threaded&start=#entry12790

go read it

may be useful for lcd read and other ? Here is my basic template when working with the 684 chip.


more

It may be of some help to you......

 LCD_684.txt ( 4.03K ) Number of downloads: 41