• AVR Freaks

Hot!Problem with PSECT in assembly file

Page: < 12 Showing page 2 of 2
Author
ric
Super Member
  • Total Posts : 23851
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: Problem with PSECT in assembly file 2019/09/19 19:11:35 (permalink)
+1 (1)
1and0
ric
AFAIK, the MOVFF instruction does not observe the access bank, so as 1and0 states, it can't access the PRODx registers. (There's no "a" bit in the opcode).
That calls into question all the example multiply code in the K42 datasheet, which does precisely that...

Another copy 'n paste errata. :(

It would appear that they are silently changing MOVFF instructions to MOVFFL if one of the addresses is not in the first 4k.
Beware if you assumed MOVFF is always two opcodes!
 

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!
#21
1and0
Access is Denied
  • Total Posts : 9748
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Problem with PSECT in assembly file 2019/09/19 19:21:08 (permalink)
0
ric
 
It would appear that they are silently changing MOVFF instructions to MOVFFL if one of the addresses is not in the first 4k.
Beware if you assumed MOVFF is always two opcodes!

I don't agree with that "feature" of the compiler's assembler. If I code in assembly, I want it to be exactly the way I wrote it!!! If it is wrong, throw me a warning or error, but don't go and change my code.
 
Good thing that MPASM is not like that. :)
 
#22
1and0
Access is Denied
  • Total Posts : 9748
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: Problem with PSECT in assembly file 2019/09/19 19:25:33 (permalink)
+2 (2)
dan1138

/*
 * Zero out high DWORD of PRODUCT register
 */
    __asm("    CLRF    _PRODUCT+4,C");
    __asm("    CLRF    _PRODUCT+5,C");
    __asm("    CLRF    _PRODUCT+6,C");
    __asm("    CLRF    _PRODUCT+7,C");

/*
 * do 32 x 32 multiply
 */
    __asm("    CLRF    _PRODUCT+4,C");
    __asm("    CLRF    _PRODUCT+5,C");
    __asm("    CLRF    _PRODUCT+6,C");


There is no need to clear PRODUCT<6:4> again. ;)
 
#23
dan1138
Super Member
  • Total Posts : 3229
  • Reward points : 0
  • Joined: 2007/02/21 23:04:16
  • Location: 0
  • Status: offline
Re: Problem with PSECT in assembly file 2019/09/19 19:56:15 (permalink)
0
1and0
There is no need to clear PRODUCT<6:4> again. ;)

Yea, I know, me and my phat phingers. :)
 
I edited my post. Hope it's better now.
#24
COSMO LITTLE
Starting Member
  • Total Posts : 76
  • Reward points : 0
  • Joined: 2010/07/01 04:29:34
  • Location: 0
  • Status: offline
Re: Problem with PSECT in assembly file 2019/09/20 08:47:45 (permalink)
0
Dear 1and0
 
Yes, I found this , thank you
 
I have noted your C routines which may come in useful
 
regards
 
Cosmo Little
#25
COSMO LITTLE
Starting Member
  • Total Posts : 76
  • Reward points : 0
  • Joined: 2010/07/01 04:29:34
  • Location: 0
  • Status: offline
Re: Problem with PSECT in assembly file 2019/09/20 08:51:44 (permalink)
0
Dear Ric,
Its my favorite 18F46K42-  very low price and good peripherals. I even found a use for the CLCs, which are really complicated to use.
 
regards
 
Cosmo Little
 
#26
COSMO LITTLE
Starting Member
  • Total Posts : 76
  • Reward points : 0
  • Joined: 2010/07/01 04:29:34
  • Location: 0
  • Status: offline
Re: Problem with PSECT in assembly file 2019/09/20 09:58:58 (permalink)
0
Dear All,
 
   I am amazed to get so many replies and so much advice. 
1/- I must admit that I have only tried the assembler routine on the simulator.
2/- The filter that I am trying to program is a 4th order elliptic lowpass made with two biquad sections. The filter has a cutoff frequency of 3uHz, and is only updated once every 20.48 seconds. The cut off normalised to the sampling frequency is 61E-6fs. This is a very narrow band filter and is very sensitive to quantization errors in the calculations.
    My first attempt used 32 bit float for all the coefficients and registers, This was the direct form type 2. This filter works on the hardware, however the quantization noise is very high. This was the reason why I am trying a fixed point version. I have not yet got this to work, even with the simulator.( The software I am using for the filter design is Iowa Hills IIR filter designer. This is free on the Internet, and I highly recommend it.)
    I think that the type 2 implementation will have less quantization noise, so my next step is to try this using floating point. If this is OK, I will thankfully move on to other parts of the algorithm.
3/- When speed is unimportant, I spend no time on optimizing a routine. My fixed point filter version only takes 511us, at 10MIPS.   Even code space is unimportant as if I run out on the 18F46K42, I can always use the 18F47K42.
4/- Looking at the disassembly listing, the linker has converted all the MOVFFs into MOVFFLs.
5/- PRODL and PRODH are definitely in the access bank. I have had problems before with special function registers not in the access bank. Happily the C compiler takes care of the addressing.
6/- I used to program pretty much exclusively in assembler, but now work in C 99.9% of the time. Where speed really is important, I prefer assembler, as one can optimise better. An earlier post I made referred to a 64 by 64 divide routine which used the hardware divide instructions on the dsPIC33E.
 
As an aside, I think there is a hardware bug in the SPI on the 46K42. I get occasional data errors if interrupts are running when using the receive FIFO. This is the subject of a current ticket with Microchip.
 
regards
 
Cosmo Little
 
 
 
 
 
 
#27
COSMO LITTLE
Starting Member
  • Total Posts : 76
  • Reward points : 0
  • Joined: 2010/07/01 04:29:34
  • Location: 0
  • Status: offline
Re: Problem with PSECT in assembly file 2019/09/26 04:42:32 (permalink)
0
Just to say that the fixed point filter finally worked. For those interested, attached are responses to a square wave for the floating point version and the fixed point version. For these tests, the filter was placed in a loop so the sampling frequency was about 2kHz. The overshoot and ringing for the fixed point filer is about right for an elliptic approximation. The floating point version is close to being unstable.
 
Cosmo Little
 
ps .bmp not accepted
#28
dan1138
Super Member
  • Total Posts : 3229
  • Reward points : 0
  • Joined: 2007/02/21 23:04:16
  • Location: 0
  • Status: offline
Re: Problem with PSECT in assembly file 2019/09/26 13:35:44 (permalink)
+1 (1)
@COSMO LITTLE,

I am sure you know that the XC8 compiler only supports the 32-bit floating point format even when you declare a double data type.

Now that you have a fixed point multiply-accumulate function you can improve your filter stability by containing the dynamic range of interim calculations such that the binary point can be selected to maximize the number of fractional bits represented in the accumulator.

Note: The forum does not like BMP graphic files because they are not an efficient way to save images. In future you may want to use a paint program to convert your oscilloscope screen captures to a GIF or PNG format image file.
#29
Page: < 12 Showing page 2 of 2
Jump to:
© 2019 APG vNext Commercial Version 4.5