• AVR Freaks

Helpful ReplyHot!Division cycle !!!!!

Page: 12345 > Showing page 1 of 5
Author
hichamrol
Starting Member
  • Total Posts : 84
  • Reward points : 0
  • Joined: 2019/07/10 07:22:53
  • Location: 0
  • Status: offline
2019/09/25 02:06:06 (permalink)
0

Division cycle !!!!!

Hello forum..
i am programming pic24fj with complier xc16 and for the division operation, it take about 460 cycles !!!!!! 
my question is there is another way to reduce that time  ???!!
 
thank you
#1
ric
Super Member
  • Total Posts : 24167
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Division cycle !!!!! 2019/09/25 02:09:48 (permalink)
4 (1)
You don't mention what size (or type) variables you are dividing.
You do realise this chip does not have a Floating Point Unit, so division has to be done by code.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#2
hichamrol
Starting Member
  • Total Posts : 84
  • Reward points : 0
  • Joined: 2019/07/10 07:22:53
  • Location: 0
  • Status: offline
Re: Division cycle !!!!! 2019/09/25 02:18:40 (permalink)
0
Ric both type uint32_t  'm' and 'n' 
i need only the integer value 
m=m/n; 
#3
ric
Super Member
  • Total Posts : 24167
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Division cycle !!!!! 2019/09/25 03:32:39 (permalink)
0
Is either of the values a constant?
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#4
hichamrol
Starting Member
  • Total Posts : 84
  • Reward points : 0
  • Joined: 2019/07/10 07:22:53
  • Location: 0
  • Status: offline
Re: Division cycle !!!!! 2019/09/25 03:56:51 (permalink)
0
false
post edited by hichamrol - 2019/09/25 04:39:43
#5
Antipodean
Super Member
  • Total Posts : 1761
  • Reward points : 0
  • Joined: 2008/12/09 10:19:08
  • Location: Didcot, United Kingdom
  • Status: offline
Re: Division cycle !!!!! 2019/09/25 03:57:24 (permalink)
0
This is the same guy as over here ...
https://www.microchip.com/forums/m1113279.aspx
 
 

Do not use my alias in your message body when replying, your message will disappear ...

Alan
#6
ric
Super Member
  • Total Posts : 24167
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Division cycle !!!!! 2019/09/25 04:09:11 (permalink)
5 (2)
hichamrol
...
n increases
Here the programm
For(i=0;i<2000;i++)
{
m=(tab+n*tab_1);
m=m/(n+1);
}


Your code is corrupted because you did not use code tags. There's probably one or more "[i]" expressions in there that have been interpreted as "start italics" by the forum.
"n" does not change value in the code you posted. In fact this code tells us very little as we have no idea what "tab" or "tab_1" are.
Have you confused "n" and "i" ?
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#7
hichamrol
Starting Member
  • Total Posts : 84
  • Reward points : 0
  • Joined: 2019/07/10 07:22:53
  • Location: 0
  • Status: offline
Re: Division cycle !!!!! 2019/09/25 04:41:50 (permalink)
0
Ric i just asked for division cycle !! i dont know why u need the program  but here a part of it 
 
while(n<nbf && stop==0)
{
if(start==1)
{
start=0;
LATE=3;
while(confirme==0); // boucle d'attente pour ne pas rater le premier flash //
}
if(confirme==1)
{
LED_D7_LAT=~LED_D7_LAT;
IEC0bits.INT0IE=0; // disable int0
for(i=0;i<5000;i++)
{

AD1CHS =4;
AD1CON1bits.SAMP = 1;
while (!AD1CON1bits.DONE);
m=(ADC1BUF0+n*voie_1[i]);

m=m/(n+1);
voie_1[i]=m;
}



n=n+1;
confirme=0;
IEC0bits.INT0IE=1;
}

}

post edited by hichamrol - 2019/09/25 05:17:26
#8
paulmtcuk
Starting Member
  • Total Posts : 43
  • Reward points : 0
  • Joined: 2007/08/23 05:16:51
  • Location: 0
  • Status: offline
Re: Division cycle !!!!! 2019/09/25 05:13:45 (permalink)
4 (1)
i dont know why u need the program

 
You may not be able to reduce the number of cycles it takes for a division operation without knowing the variable types. (Also your code still doesn't show the variable types)... But you can also reduce the number of division operations. To reduce the number of division operations we would need to understand what your program is trying to do so you/we may be able to optimise the program to reduce the number of division operations. 
post edited by paulmtcuk - 2019/09/25 05:18:46
#9
hichamrol
Starting Member
  • Total Posts : 84
  • Reward points : 0
  • Joined: 2019/07/10 07:22:53
  • Location: 0
  • Status: offline
Re: Division cycle !!!!! 2019/09/25 05:21:50 (permalink)
0
paulmtcuk
 To reduce the number of division operations we would need to understand what your program is trying to do so you/we may be able to optimise the program to reduce the number of division operations. 



I see dude , btw  "" n and m type uint32_t ""
#10
Antipodean
Super Member
  • Total Posts : 1761
  • Reward points : 0
  • Joined: 2008/12/09 10:19:08
  • Location: Didcot, United Kingdom
  • Status: offline
Re: Division cycle !!!!! 2019/09/25 06:16:57 (permalink)
5 (1)
If you are worried about the number of cycles a division is taking maybe this code should be run on a PIC32 which does have a 32 bit bus, instead of a PIC24 with a 16 bit bus.

Do not use my alias in your message body when replying, your message will disappear ...

Alan
#11
NKurzman
A Guy on the Net
  • Total Posts : 17912
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: offline
Re: Division cycle !!!!! 2019/09/25 06:19:42 (permalink)
0
Many pic32mz have an FPU.
#12
NorthGuy
Super Member
  • Total Posts : 5733
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: offline
Re: Division cycle !!!!! 2019/09/25 06:35:02 (permalink)
3.67 (3)
PIC24 has hardware 32-bit by 16-bit division which takes 18 cycles. If you make the divisor a 16-bit variable, the compiler may pick up on hardware division.
 
Since you're using ADC values, they're all 16-bit. If you move to 16-bit arithmetic it'll be faster - you're working with 16-bit PIC after all.
 
At any rate, 450 cycles for emulating 32-bit by 32-bit division on PIC24 is way too much. Either the compiler does it very inefficiently, or you measure it incorrectly.
#13
NorthGuy
Super Member
  • Total Posts : 5733
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: offline
Re: Division cycle !!!!! 2019/09/25 06:59:11 (permalink)
5 (1)
hichamrol
i dont know why u need the program 



When it comes to performance, it's 99% code and 1% hardware.
 
If you look at your code, there are certainly ways to improve it. Arithmetic can be simplified. The time while you're waiting for ADC may be used for calculations. Once you do all this, you won't be so much dependent on the division speed, and most likely will not have any divisions at all.
 
Also (although this has nothing to do with efficiency) you probably should work on better rounding.
#14
Jim Nickerson
User 452
  • Total Posts : 6322
  • Reward points : 0
  • Joined: 2003/11/07 12:35:10
  • Location: San Diego, CA
  • Status: offline
Re: Division cycle !!!!! 2019/09/25 07:07:30 (permalink)
0
missing post, blinking page
#15
Jim Nickerson
User 452
  • Total Posts : 6322
  • Reward points : 0
  • Joined: 2003/11/07 12:35:10
  • Location: San Diego, CA
  • Status: offline
Re: Division cycle !!!!! 2019/09/25 07:07:59 (permalink)
0
blinking page, missing 2nd post
#16
Jim Nickerson
User 452
  • Total Posts : 6322
  • Reward points : 0
  • Joined: 2003/11/07 12:35:10
  • Location: San Diego, CA
  • Status: offline
Re: Division cycle !!!!! 2019/09/25 07:08:32 (permalink)
0
blinking page 3rd missing post
#17
Jim Nickerson
User 452
  • Total Posts : 6322
  • Reward points : 0
  • Joined: 2003/11/07 12:35:10
  • Location: San Diego, CA
  • Status: offline
Re: Division cycle !!!!! 2019/09/25 07:09:05 (permalink)
0
blinking page 4th missing post
 
#18
Jim Nickerson
User 452
  • Total Posts : 6322
  • Reward points : 0
  • Joined: 2003/11/07 12:35:10
  • Location: San Diego, CA
  • Status: offline
Re: Division cycle !!!!! 2019/09/25 07:09:48 (permalink)
5 (1)
enough of this blink page 
#19
hichamrol
Starting Member
  • Total Posts : 84
  • Reward points : 0
  • Joined: 2019/07/10 07:22:53
  • Location: 0
  • Status: offline
Re: Division cycle !!!!! 2019/09/25 07:11:54 (permalink)
0
problem with page i can't see anything ..... !!!
 
#20
Page: 12345 > Showing page 1 of 5
Jump to:
© 2019 APG vNext Commercial Version 4.5