Skip to content

Instantly share code, notes, and snippets.

@gbip
Created April 11, 2018 14:25
Show Gist options
  • Save gbip/ca449013b810d7b9c89f9fc988be7dbd to your computer and use it in GitHub Desktop.
Save gbip/ca449013b810d7b9c89f9fc988be7dbd to your computer and use it in GitHub Desktop.
; ce programme est pour l'assembleur RealView (Keil)
thumb
area myvar, data, readwrite
import the_struct
area moncode, code, readonly
export callback
E_POS equ 0
E_TAI equ 4
E_SON equ 8
E_RES equ 12
E_PER equ 16
OFFSET equ 32768
TIM3_CCR3 equ 0x4000043C ; adresse registre PWM
callback proc
init
ldr r1, =the_struct
; R1 = ADDR_STRUCT
verif_boucle ; Remets index à zéro quand on arrive à taille, et l'incrémente dans le cas contraire
ldr r3, =E_TAI
ldr r2, =E_POS
add r2, r2, r1
ldr r2, [r2] ; R2 contiens l'index actuel
add r3, r3, r1
ldr r3, [r3] ; R3 contiens le nombre d'échantillon
cmp r2, r3 ; On branche sur R3 - R2
bne recup_ech
write_zero ; Cette procédure écris 0 sur la sortie
b ret
;mov r2, #0x0000000
;ldr r1, =TIM3_CCR3
;str r2, [r1]
;b ret
recup_ech ; Cette procédure met dans R4 l'échantillon
ldr r3, =E_SON
add r3, r1
ldr r3, [r3] ; R3 = addresse du tableau
ldr r2, =E_POS
add r2, r1
ldr r2, [r2] ; R2 = index du tableau
add r3, r2 ; R3 = addresse de l'échantillon
ldrsh r4, [r3]
; R4 = ECH
traitement ; Cette procédure raméne l'échantillon entre 0 et MAX
ldr r2, =OFFSET
add r4, r2 ; On remonte l'échantillon
ldr r2, =E_RES
add r2, r1 ; R2 contiens l'adresse de la pleine échelle
ldr r2, [r2]
mul r4, r2 ; R4 = R4 * MAX
lsr r4, #17 ; R4 >> 16
; R4 = ECH_CORRIG
stockage ; Cette procédure stocke l'échantillon sur la PWM
00 ldr r2, =TIM3_CCR3
str r4, [r2]
; R4 a été stocké en TIM3_CCR3
incr
ldr r2, =E_POS
add r2, r1
ldr r2, [r2]
add r2, #0x0002
store_index ; Cette procédure incrémente la valeur de l'index
ldr r3, =E_POS
add r3, r3, r1
str r2, [r3]
b ret
ret
bx lr ; dernière instruction de la fonction
endp
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment