Телесистемы
 Разработка, производство и продажа радиоэлектронной аппаратуры
На главную   | Карта сайта | Пишите нам | В избранное
Требуется программист в Зеленограде
- обработка данных с датчиков; ColdFire; 40 тыс.
e-mail:jobsmp@pochta.ru

Телесистемы | Электроника | Конференция «Микроконтроллеры и их применение»

Есть вот такая хитрая генерилка

Отправлено =AVR= 09 августа 2007 г. 11:19
В ответ на: Вычисление значения функции sin(x)...(+) отправлено <font color=gray>igorenja</font> 09 августа 2007 г. 08:31


;Fast, Continuous, Sine GeneratorFast, Continuous, Sine Generator
;Alex Boudreau – Ph.D. – junior eng.
;Director of DSP department
;Soft dB inc.
;a.boudreau@softdb.com

;Bruno Paillard - Ph.D. - eng.
;Director of Research and Development
;D-Box Technology
;bruno.paillard@d-box.com


;____________________________________________________________________________
;
; Sine generator
;
; (Developed and tested on a TMS320C5402 DSP)
;
; This function generates successive samples of a sine wave. The sine wave
; is generated with an amplitude of 1 in Q15 representation.
;
;
;
; - Inputs:
;
; - Cre: Static variable that contains the present value of the
; real part of the rotating vector. Cre must be
; initialized to 1 (0x7FFF) before the first call of the
; function.
;
; Cre must be pointed to by AR2 before the call.
;
; - Cim: Static variable that contains the present value of the
; imaginary part of the rotating vector. Cim must be
; initialized to 0 before the first call of the function.
;
; Cim must be pointed to by AR3 before the call.
;
; - Dre: Static variable that contains the real part of the
; increment vector. Dre/Dim must be initialized with
; values such that (Dre^2 + Dim^2) = 1
;
; Dre must be pointed to by AR4 before the call.
;
; - Dim: Static variable that contains the imaginary part of the
; increment vector. Dre/Dim must be initialized with
; values such that (Dre^2 + Dim^2) = 1
;
; Dim must be pointed to by AR5 before the call.
;
; - Outputs:
;
; - Cre: After the call, Cre contains the updated real part of
; the rotating vector. It is the next sine sample.
;
; - Cim: After the call, Cim contains the updated imaginary part
; of the rotating vector. It is the next cosine sample.
;
;
; Execution time: 32 cycles
;
;
; Written December 21 2001 by:
;
; Alex Boudreau, Bruno Paillard
;
;____________________________________________________________________________

.width 80
.length 55
.title "asm_sine"
.mmregs
;____________________________________________________________________________
;
; Context save
;
; « C » register protection rules are used, so only ST1 is protected
;____________________________________________________________________________

pshm ST1
;____________________________________________________________________________
;
; Set DSP mode:
;
; SXM = 1
; OVM = 1
; FRCT = 1
; CPL = 1
;____________________________________________________________________________

orm #0100001101000000b,*(ST1)
;____________________________________________________________________________
;
; Reserve 2 words on the stack:
;
; SP(0) assigned to Raw_Cre (Cre value before normalization)
; SP(1) assigned to Raw_Cim (Cim value before normalization)
;____________________________________________________________________________

frame -2
;____________________________________________________________________________
;
; Calculate Raw_Cre
;____________________________________________________________________________

mpy *ar2,*ar4,a ; a = Cre * Dre
masr *ar3,*ar5,a,a ; a = rnd(a - Cim * Dim)
sth a,*sp(0) ; Raw_Cre = ah
;____________________________________________________________________________
;
; Calculate Raw_Cim
;____________________________________________________________________________

mpy *ar4,*ar3,b ; b = Dre * Cim
macr *ar2,*ar5,b,b ; b = rnd(b + Cre * Dim)
sth b,*sp(1) ; Raw_Cim = bh
;____________________________________________________________________________
;
; Calculate amplitude correction factor
;
; (1 - (Raw_Cre^2 + Raw_Cim^2))/2
;____________________________________________________________________________

ld #0x7FFF,16,a ; initialize a with 1 in Q31.
squrs *sp(0),a ; a = a - Raw_Cre^2
squrs *sp(1),a ; a = a - Raw_Cim^2
add #1,15,a,a ; rnd a
sfta a,-1,a ; a = a/2
;____________________________________________________________________________
;
; Update Cre and Cim using correction factor in A
;
; Cre = Cre (1 + (1 - (Raw_Cre^2 + Raw_Cim^2))/2)
; Cre = Cre + Cre x A
;
; Cim = Cim (1 + (1 - (Raw_Cre^2 + Raw_Cim^2))/2)
; Cim = Cim + Cim * A
;
;____________________________________________________________________________

ld *sp(1),T ; Cim -> T
; Cim is already in b
macar T,b,b ; b = rnd(Cim + ah * Cim)
sth b,*ar3 ; bh -> Cim

ld *sp(0),T ; Cre -> T
ld *sp(0),16,b ; Cre -> bh
macar T,b,b ; b = rnd(Cre + ah * Cre)
sth b,*ar2 ; bh -> Cre
;____________________________________________________________________________
;
; Flushes 2 automatic variable reserved on the stack
;____________________________________________________________________________

frame 2
;____________________________________________________________________________
;
; Context restore
;____________________________________________________________________________

popm ST1

ret

.end



Составить ответ | Вернуться на конференцию

Ответы


Отправка ответа
Имя*: 
Пароль: 
E-mail: 
Тема*:

Сообщение:

Ссылка на URL: 
URL изображения: 

если вы незарегистрированный на форуме пользователь, то
для успешного добавления сообщения заполните поле, как указано ниже:
введите число 90:

Перейти к списку ответов | Конференция | Раздел "Электроника" | Главная страница | Карта сайта

Rambler's Top100 Рейтинг@Mail.ru
 
Web telesys.ru