Revision: 1180 Author: jsuijs Date: Sun Aug 9 11:24:50 2009 Log: Accuracy of delay.jal improved. I guess this is as good as it gets (for 10us-based). http://code.google.com/p/jallib/source/detail?r=1180
Added: /trunk/include/jal/lowpassfilter.jal Modified: /trunk/include/jal/delay.jal /trunk/project/delay_calibrate/delay_calibrate.jal ======================================= --- /dev/null +++ /trunk/include/jal/lowpassfilter.jal Sun Aug 9 11:24:50 2009 @@ -0,0 +1,62 @@ +-- Title: low pass filter +-- Author: Joep Suijs, Copyright (c) 2009, all rights reserved. +-- Compiler: >=2.4k +-- +-- This file is part of jallib (http://jallib.googlecode.com) +-- Released under the ZLIB license (http://www.opensource.org/licenses/zlib-license.html) +-- +-- Description: 1st and 2nd order low pass fitlers +-- + +-- --------------------------------------------------------------------------- +-- lpr_2nd_order +-- --------------------------------------------------------------------------- +-- time_const = aantal bits dat naar rechts wordt geshift, +-- bijv 3 = delen door 8, 1 tau = 8 aanroepen. +-- u1 en u2 zijn hulpvars voor het tweede orde filter. +-- u1 is een maat voor de eerste afgeleide van de output. +-- u2 bevat de return-waarde << 16 +-- Bug: bij input 0 kan output -1 (=65535) worden +-- --------------------------------------------------------------------------- +function lpf_2nd_order(sword in ui, sdword in out u1, sdword in out u2, byte in time_const) return sword is + var sdword tmp +; var bit asign at tmp : 31 +; var bit sign + + ; tmp = (ui * 65536) - u1 * 2 - u2 + tmp = ui + tmp = tmp << 16 + tmp = tmp - (u1 * 2) + tmp = tmp - u2 + + u1 = u1 + (tmp >> time_const) + + u2 = u2 + (u1 >> time_const) + + ; return (u2 + 32768) / 65536 tmp = u2 + tmp = u2 + tmp = tmp + 32768 ; juist afronden + tmp = tmp >> 16 + return sword(tmp) + +end function + +-- --------------------------------------------------------------------------- +-- lpr_1st_order +-- --------------------------------------------------------------------------- +-- --------------------------------------------------------------------------- +function lpf_1st_order( sword in ui, sdword in out u1, byte in time_const) return sword is + var sdword tmp + +; Result = Result - (Result / 64) + adc + + u1 = u1 - (u1 >> time_const) + u1 = u1 + ui + + ; return (u2 + 32768) / 65536 tmp = u2 + tmp = u1 +;; tmp = tmp + 32768 ; juist afronden + tmp = tmp >> time_const + return sword(tmp) + +end function ======================================= --- /trunk/include/jal/delay.jal Thu Aug 6 13:03:39 2009 +++ /trunk/include/jal/delay.jal Sun Aug 9 11:24:50 2009 @@ -89,7 +89,7 @@ end if else n = n - 1; - const _ten_us_delay2 = 10 - ((24 * instruction_time) / 100) + const _ten_us_delay2 = 10 - ((29 * instruction_time) / 100) if (_ten_us_delay2 <= 10) then _usec_delay(_ten_us_delay2) else ======================================= --- /trunk/project/delay_calibrate/delay_calibrate.jal Sat Aug 8 10:02:14 2009 +++ /trunk/project/delay_calibrate/delay_calibrate.jal Sun Aug 9 11:24:50 2009 @@ -49,7 +49,7 @@ serial_hw_init() include print -include ndelay +include delay t1con = 0x01 ; TMR1ON, prescaler 1 (1 tick = 0.2 us) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "jallib" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/jallib?hl=en -~----------~----~----~----~------~----~------~--~---
