LF_II

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
1,538 Views
poppy2008
Contributor II

can any one tell me what this export symbol XDEF LF_II  function doing.?,i couldnt understand from assembly codes,please

 

thanks in advance

Labels (1)
0 Kudos
1 Solution
405 Views
poppy2008
Contributor II

Dear peg,bigmac  help me,please

(actually for rms current calculation, this library function is used in one program  ,i want to know what  this fn doing) 

here i  have attached the LF_II code 

Message Edited by poppy2008 on 2009-05-12 10:30 PM
Message Edited by poppy2008 on 2009-05-12 10:31 PM

View solution in original post

0 Kudos
4 Replies
406 Views
poppy2008
Contributor II

Dear peg,bigmac  help me,please

(actually for rms current calculation, this library function is used in one program  ,i want to know what  this fn doing) 

here i  have attached the LF_II code 

Message Edited by poppy2008 on 2009-05-12 10:30 PM
Message Edited by poppy2008 on 2009-05-12 10:31 PM
0 Kudos
405 Views
poppy2008
Contributor II

great explanation,thank you so much bigmac,

after test this code again i will contact you!

 

Regards

...Juliet

Message Edited by poppy2008 on 2009-05-14 08:17 PM
0 Kudos
405 Views
bigmac
Specialist III

Hello,

 

As far as I can judge, the sub-routine seems to be calculating the "mean-squared" value of the 10-bit Iac_10b unsigned value, and placing the 20-bit result within an assumed 24-bit variable Iac_LFR.  The filtering algorithm (to obtain the mean) is unknown to me.

 

The code is poorly written on at least two counts -

  1. The almost complete absence of comments to describe the purpose of the sub-routine, and the operation of each section of the code. There may also be some unexplained initialisation requirements for some of the registers.
  2. Some of the variables allocated within Z_RAM seem to have only temporary use.  For HCS08 devices, the stack would be better used for these.  The current usage of dedicated RAM is about 30 bytes.

The following comments describe what each section of code seems to be doing.  Perhaps others may be able to explain the filtering method.

 

          ; Square 10-bit value: result -> IX
          ; Calculate IX += IY
          ; Right shift IY by 6 places
          ; Calculate IY = IX - IY
          ; SECOND FILTER
          ; Calculate IT = IY - IZ
          ; Right shift IT by 6 places

          ; Calculate IZ += IT; IR = IZ

          ; Right shift IR by 6 places
          ; Calculate Iac_LFR = IR + 2 (20-bit result)

Regards,

Mac

0 Kudos
405 Views
bigmac
Specialist III

Hello,

 

I made a further attempt to understand the operation of the filter algorithm, and it appears that a standard form of filter is actually used, that gives results close to a single RC circuit in the analog domain. In fact the filter is applied twice, to give the effect of two cascaded CR circuits with equal time constants.

 

The registers IY and IZ are the filtered values, that must remain static, and must be initialised. Also keep in mind that shift right 6 places is identical to divide by 64. So the calculation of each updated filtered value may be derived.

 

IY = IX + IY*63/64

IZ = IY + IZ*63/64

 

Each filtered value is 64 times greater than the final mean (20-bit) value. This is why IZ needs to be divided by 64. I am not sure why the final value has then been incremented by 2.

 

I also observe that the dword registers IX, IR and IT are for temporary use only, and only a single register (say IX) is actually necessary. This should reduce the dedicated RAM requirement to 12 bytes.

 

I have attempted to "clean up" the code, but the attached code remains untested so there might possibly be some overlooked errors.

 

Regards,

Mac

 

Message Edited by bigmac on 2009-05-14 10:21 PM
0 Kudos