Delay_us() and Delay_ms() only take constant parameters

Post your requests and ideas on the future development of mikroPascal PRO for AVR.
Post Reply
Author
Message
brelstad
Posts: 14
Joined: 23 May 2010 13:12

Delay_us() and Delay_ms() only take constant parameters

#1 Post by brelstad » 23 Jan 2015 06:38

It would be most convenient if the
Delay_us() and Delay_ms() routines could take variables, not just constant expressions.

Bengt

User avatar
nemanja.nikolic
Posts: 171
Joined: 01 Dec 2014 10:50

Re: Delay_us() and Delay_ms() only take constant parameters

#2 Post by nemanja.nikolic » 23 Jan 2015 14:42

Hello,

You can use delay routines with variables, you can use following function:

Code: Select all

unsignedpause = 1000;
...
Vdelay_ms(pause);  // ~ one second pause
Look at help.

Nemanja.

Best regards.

brelstad
Posts: 14
Joined: 23 May 2010 13:12

Re: Delay_us() and Delay_ms() only take constant parameters

#3 Post by brelstad » 23 Jan 2015 15:43

Hi, I tried this:

procedure TestDelay1(const sTestDelay: dword);
begin
Delay_us(sTestDelay);
end;

procedure TestDelay2;
var zTestDelay: dword;
begin
zTestDelay := 1000;
Delay_us(zTestDelay);
end;

Both procedures fail to compile and the compiler message is:
Syntax error: Expected "constant expression" but "complex expression" found

User avatar
nemanja.nikolic
Posts: 171
Joined: 01 Dec 2014 10:50

Re: Delay_us() and Delay_ms() only take constant parameters

#4 Post by nemanja.nikolic » 26 Jan 2015 09:51

Hello,

You can't use Delay_ms() with variables.
Look at simple example:

Code: Select all

program Vdelay;

var cnt: word;

begin
  cnt := 1;
  while TRUE do
    begin
      cnt := cnt + 1;
      Vdelay_ms(cnt);
    end;
end.
Nemanja.

Best regards.

brelstad
Posts: 14
Joined: 23 May 2010 13:12

Re: Delay_us() and Delay_ms() only take constant parameters

#5 Post by brelstad » 27 Jan 2015 06:56

Yes, finally we agree :)

If you read my first post, you will see that this is exactly my point.
Delay_us() and Delay_ms() can only take constant expressions, not variables.
Which is my reason for writing this post here in the wish list.

It would be most convenient if the Delay_us() and Delay_ms() routines could take variables, not just constant expressions.

Could you please pass this on to the developers?


Thanks,
Bengt

User avatar
nemanja.nikolic
Posts: 171
Joined: 01 Dec 2014 10:50

Re: Delay_us() and Delay_ms() only take constant parameters

#6 Post by nemanja.nikolic » 27 Jan 2015 10:03

Hello,

Because of that we have another routine for variable: Vdelay_ms();

Nemanja.

Best regards.

brelstad
Posts: 14
Joined: 23 May 2010 13:12

Re: Delay_us() and Delay_ms() only take constant parameters

#7 Post by brelstad » 29 Jan 2015 02:53

Ah, thanks, that certainly helps for millisecond delays.

Then my wish for the future is a delay routine for variables, that takes microsecond delays.

Thanks,
Bengt

User avatar
nemanja.nikolic
Posts: 171
Joined: 01 Dec 2014 10:50

Re: Delay_us() and Delay_ms() only take constant parameters

#8 Post by nemanja.nikolic » 29 Jan 2015 14:00

Hello,

For microsecond would not be so exact.
You can create function for that if you haven't much values and if your values isn't too small (more larger then 1/Fosc).
For example:

Code: Select all

procedure Delay_VAR(VAR : word);
  case VAR of
     1: begin
	      Delay_us(100);
		end;
	 2:	begin
          Delay_us(200);
        end;
	 3: begin
          Delay_us(300);
        end;
           .		
		   .
		   .
		   .		   
  end;
end;


Nemanja.

Best regards.

corado
Posts: 399
Joined: 28 Mar 2009 11:03

Re: Delay_us() and Delay_ms() only take constant parameters

#9 Post by corado » 05 Nov 2023 20:34

Why it is made with constand and not Var?
Where is the benefit?
Why not only the delay Version with Variable?
Are the Nachteile Disadvantages?

User avatar
IvanJeremic
mikroElektronika team
Posts: 316
Joined: 05 Sep 2022 14:32

Re: Delay_us() and Delay_ms() only take constant parameters

#10 Post by IvanJeremic » 06 Nov 2023 11:50

Hi,

Because there were precision issues when using variables instead of constants.

Regards,

Ivan.

Post Reply

Return to “mikroPascal PRO for AVR Wish List”