Reply by "'an...@gmail.com' anthonyha2011●July 11, 20142014-07-11
I agree. Using timer interrupt - Basic timer or watchdog timer, or any
timer of timer A or timer B will do the job. Here is examples in
assembler:
;********************** SETUP DELAY TIMES
*********************************** ; ;TIMERB CONTINUOUSLY OPERATES WITH A
CLOCK OF 32KHZ THUS THE PERIOD PER PULSE ;IS 30.518uS. THE COUNT IS
ADDED TO THE DELAY TIME AND THEN IS SET INTO ;REGISTER CCBR2. THE
COMPARE FLAG GOES HI WHEN THE DELAY PERIOD HAS ELAPSED.
Subject: RE: [msp430]
function not executed when called from main program
Please
note:
Whether you use the for loop or the
while loop, this is NOT portable code.
You are letting the cpu cycle time
of the instructions being generated by a particular compiler to delay an amount
of time that you probably calculated using the same code, as to how long it
would take to reach your desired time value.
While a certain compiler will
generate certain code for the while loop, does not guarantee that the same
compiler will generate similar code taking up the same amount of cpu time for
the for loop.
Then you get into the differences
of different compilers.
Can’t you use a timer
interrupt?? That would be more exact as to the value that you want, regardless
of what compiler you use or what code you use.
From: m... [mailto:msp430] Sent:
Friday, July 11, 2014 9:54 AM To: msp430 Subject: Re:
[msp430] function not executed when called from main
program
I'm very new to controllers
and I have some troubles with my first programs. I use CC Studio from TI and a
Launchpad with the MSP430G2553.
I wrote a waiting
function:
void wait(int
j){ int i;
for(i=0;i<j;i++){ }; }
When I call this function in the
main program (wait(50000) ), it is not called at all. In debug mode the program
does not stop at the line that calls the function. I cannot even put a
breakpoint on that particular line, the breakpoint is automatically shifted one
instruction further.
Is this some compiling optimization
that takes my function out?
Reply by "Gab...@uol.com.br [msp430]"●July 11, 20142014-07-11
In CCS use __delay_cycles instead:
// Using 25MHz XTal
void DelayMs(unsigned int n) {
while(n--) {
__delay_cycles(25000);
}
}
gcalin
On 11/07/2014 10:54, Alexander Espinosa i...@yahoo.com [msp430] wrote: > hi.. i've used this:
>
> void wait(unsigned int delay){
> while(--delay);
>
> }
> On Friday, July 11, 2014 1:36 AM, "c...@yahoo.com [msp430]"
> wrote:
> Hello
>
> I'm very new to controllers and I have some troubles with my first
> programs. I use CC Studio from TI and a Launchpad with the MSP430G2553.
>
> I wrote a waiting function:
>
> void wait(int j){
> int i;
> for(i=0;i
> }
>
> When I call this function in the main program (wait(50000) ), it is
> not called at all. In debug mode the program does not stop at the line
> that calls the function. I cannot even put a breakpoint on that
> particular line, the breakpoint is automatically shifted one
> instruction further.
>
> Is this some compiling optimization that takes my function out?
>
> Thanks!
> Cristian
>
Reply by "'Hu...@coxandco.com [msp430]"●July 11, 20142014-07-11
Please note:
Whether you use the for loop or the while loop, this is NOT portable code.
You are letting the cpu cycle time of the instructions being generated by a
particular compiler to delay an amount of time that you probably calculated
using the same code, as to how long it would take to reach your desired time
value.
While a certain compiler will generate certain code for the while loop, does not
guarantee that the same compiler will generate similar code taking up the same
amount of cpu time for the for loop.
Then you get into the differences of different compilers.
Can’t you use a timer interrupt?? That would be more exact as to the value
that you want, regardless of what compiler you use or what code you use.
From: m... [mailto:m...]
Sent: Friday, July 11, 2014 9:54 AM
To: m...
Subject: Re: [msp430] function not executed when called from main program
hi.. i've used this:
void wait(unsigned int delay){
while(--delay);
}
On Friday, July 11, 2014 1:36 AM, "c...@yahoo.com [msp430]
" wrote:
Hello
I'm very new to controllers and I have some troubles with my first
programs. I use CC Studio from TI and a Launchpad with the MSP430G2553.
I wrote a waiting function:
void wait(int j){
int i;
for(i=0;i
}
When I call this function in the main program (wait(50000) ), it is not called
at all. In debug mode the program does not stop at the line that calls the
function. I cannot even put a breakpoint on that particular line, the breakpoint
is automatically shifted one instruction further.
Is this some compiling optimization that takes my function out?
Thanks!
Cristian
Reply by "Ale...@yahoo.com [msp430]"●July 11, 20142014-07-11
hi.. i've used this:
void wait(unsigned int delay){
while(--delay);
}
On Friday, July 11, 2014 1:36 AM, "c...@yahoo.com [msp430]" wrote:
Hello
I'm very new to controllers and I have some troubles with my first
programs. I use CC Studio from TI and a Launchpad with the MSP430G2553.
I wrote a waiting function:
void wait(int j){
int i;
for(i=0;i
}
When I call this function in the main program (wait(50000) ), it is not called
at all. In debug mode the program does not stop at the line that calls the
function. I cannot even put a breakpoint on that particular line, the breakpoint
is automatically shifted one instruction further.
Is this some compiling optimization that takes my function out?
Thanks!
Cristian
Reply by "Mi ...@gmail.com [msp430]"●July 11, 20142014-07-11
I would change your function to;
void wait(unsigned int j){
volatile unsigned int i;
for(i=0;i
{
}
}
Hints:
volatile should help the complier not optimize away your delay loop.
unsigned int should give you the range you require; 50,000 (See
below for int sizes)
Data type Size Range
signed int 16 bits -32768 to 32767
unsigned int 16 bits 0 to 65535
Posted by: Mi Ke
Reply by "pse...@gmail.com [msp430]"●July 11, 20142014-07-11
> I still do not get why the compiler took my function
out > of the code when I did not wrote volatile int…
Because the function does not return anything, and does not have any
side-effect (it doesn't modify any global variables or call other functions
that might) so calling it is basically useless from the compiler's point of
view.
By specifying that the 'i' is volatile, you tell the compiler that
the variable can be accessed from outside your program (typically by the
hardware). In that case, your function does have a side-effect and it won't
be optimized out.
Reply by "cva...@yahoo.com [msp430]"●July 11, 20142014-07-11
Thank you Brian. It works perfectly now. I still do not get why the compiler
took my function out of the code when I did not wrote volatile int...
@Paulo
The fact that the number I gave as parameter to the function was not the
problem. This generated a warning at compile time only. The function was not
called at all.
Thanks a lot!
Reply by "Bri...@shapes.demon.co.uk [msp430]"●July 11, 20142014-07-11
On Thu, 2014-07-10 at 23:36 -0700, c...@yahoo.com [msp430] wrote: > Hello
> I wrote a waiting function:
>
> void wait(int j){
> int i;
> for(i=0;i
> }
volatile int i;
may prevent the optimisations.
- Brian
Posted by: Brian Drummond
Reply by "Pau...@eetips.net [msp430]"●July 11, 20142014-07-11
You are using an int parameter. The maximum positive value is 32767. Try using
a wait time less than 32767.
-- Paulo Ricardo
On 11 de julho de 2014 03h36min24s BRT, "c...@yahoo.com [msp430]"
wrote: >Hello
>I'm very new to controllers and I have some troubles with my first
>programs. I use CC Studio from TI and a Launchpad with the MSP430G2553.
>
> I wrote a waiting function:
> void wait(int j){
> int i;
> for(i=0;i
>}
>
>When I call this function in the main program (wait(50000) ), it is not
>called at all. In debug mode the program does not stop at the line that
>calls the function. I cannot even put a breakpoint on that particular
>line, the breakpoint is automatically shifted one instruction further.
> Is this some compiling optimization that takes my function out?
> Thanks!
>
> Cristian