|
|
View previous topic :: View next topic |
Author |
Message |
Michael Thompson Guest
|
32-bit integer division inside and outside an interrupt |
Posted: Tue Mar 11, 2003 5:51 pm |
|
|
How does one perform 32-bit integer division inside and outside of an interrupt since they use the same internal compiler divide function?
Is there 32-bit compiler division code available to make a duplicate function for use within an interrupt?
Regards,
Mike
___________________________
This message was ported from CCS's old forum
Original Post ID: 12550 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: 32-bit integer division inside and outside an interrupt |
Posted: Tue Mar 11, 2003 6:41 pm |
|
|
<font face="Courier New" size=-1>:=How does one perform 32-bit integer division inside and outside of an interrupt since they use the same internal compiler divide function?
:=
:=Is there 32-bit compiler division code available to make a duplicate function for use within an interrupt?
:=
-----------------------------------------------------
To answer the 2nd question, here's a code generator
that will create ASM code for 32-bit division.
But, it requires that the divisor be a constant.
For example, suppose you want to make code to divide by 5.
You would set it for 32 bits, and to multiply by .2 (same
thing as divide by 5). Also, if you reduce the "maximum error"
to 0.1\% (for example), it will increase the size of the
generated code.
<a href="http://www.piclist.com/cgi-bin/constdivmul.exe" TARGET="_blank">http://www.piclist.com/cgi-bin/constdivmul.exe</a>
--</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 12552 |
|
|
Al
Joined: 13 Nov 2003 Posts: 28 Location: Belfast
|
32-bit integer division inside and outside an interrupt |
Posted: Fri Jan 30, 2004 10:03 am |
|
|
The following code handles 32-bit integer division both inside and outside of the interrupt. Try it yourself. If this does not solve your problem, post a snippet of your code so that I can see exactly what you are doing.
#include <16f877A.h>
#fuses HS,NOLVP,NOWDT,PUT
#use delay (clock=20000000)
#use rs232(baud=4800, parity=N, bits=8, xmit=PIN_C6, rcv=PIN_C7)
char status;
char ch;
int32 a,b;
float k,l;
// This ISR is called every time a character arrives on the RS232 buffer
#int_rda
void serial_isr() {
disable_interrupts(GLOBAL);
ch=getc();
//32-bit integer division inside interrupt
k = a/b;
putc(ch);
delay_ms(200);
enable_interrupts(GLOBAL);
}
void main() {
BYTE start;
a = 10;
b = 5;
k = 0; l = 0;
//32-bit integer division outside interrupt
l = a/b;
ch = (char)(65);
ch = 'N';
enable_interrupts(GLOBAL);
enable_interrupts(INT_RDA);
do {
if(ch=='c')
printf("\r\n inside interrupt = %f\r\n
outside interrupt = %f\r\n", k, l);
} while (TRUE);
} _________________ Alan Murray |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|