|
|
View previous topic :: View next topic |
Author |
Message |
ljbeng
Joined: 10 Feb 2004 Posts: 205
|
#int_rda and math routines |
Posted: Thu Jun 01, 2006 4:03 pm |
|
|
3.249
18F2620
In my int_rda routine, I do a short math function.
Code: | rposition = rposition * 225 / 256; |
In my main routine, I am mostly just writing data to the lcd. I found that sometimes when this line ran:
Code: | printf(lcd_putc,"OpHr%06lu",hoursrun); |
I know hoursrun = 0 but I would see a flicker on the lcd and I found that 225 was being displayed sometimes. So I changed 225 in my int_rda equation to 245. Guess what, 245 was displayed in flickers. Will the compiler use the same ram for math in an interrupt routine as it uses for the main loop routines?
Here is the listing for that area....
Code: | .................... rposition = rposition * 225 / 256;
2330: MOVFF 1C5,84B
2334: MOVFF 1C4,84A
2338: MOVFF 1C3,849
233C: MOVFF 1C2,848
2340: MOVLB 8
2342: CLRF x4F
2344: CLRF x4E
2346: CLRF x4D
2348: MOVLW E1
234A: MOVWF x4C
234C: MOVLB 0
234E: RCALL 1D86
2350: MOVFF 01,1C2
2354: MOVFF 02,1C3
2358: MOVFF 03,1C4
235C: MOVLB 1
235E: CLRF xC5 |
225 (E1) is being written to x4C. If I search the listing for other places that x4C is used, it shows up in a lot of places in my main routine. How can I fix this? |
|
|
Ttelmah Guest
|
|
Posted: Fri Jun 02, 2006 4:24 am |
|
|
Unfortunately, without seeing a lot more of your code, it is not possible to see where the problem lies. There is a temporary 'scratch' are used for arithmetic, but this is automatically preserved by the interrupt handler. Things that might cause problems, are:
1) Enabling int_global inside a handler.
2) Accessing a 2byte, or 4byte value in 'main', which is updated in the handler.
3) Using your own int_global handler, which does not protect the scratch area.
4) Using the 'fast' keyword on an interrupt, while doing such operations.
5) A bug. Possible, but a lot of people have been using 3.249 for a while, and while there are problems in some places, I have not seen this one.
Best Wishes |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Fri Jun 02, 2006 8:58 am |
|
|
If, at all possible, do not do any math calculations inside an interrupt. They should be short...short...short. If you need to calculate or print something then simply grab the data, that is coming in, store it and then set a flag. In main() look for that flag and do your time intensive stuff there. If you try to do calculations or print inside your int_rda you could very well lose data while doing them.
Ronald |
|
|
|
|
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
|