From 1aea46f8205d92960ba561fd7eceef359289cb7e Mon Sep 17 00:00:00 2001 From: Enzo Slamnia Date: Wed, 12 Apr 2023 15:21:44 +0200 Subject: [PATCH] partie PWM --- elec/spice/pwm/PWM.net | 16 +++++++++ soft/PjtKEIL_StepSon/Src/GestionSon.s | 50 +++++++++------------------ soft/PjtKEIL_StepSon/Src/principal.c | 8 +++-- soft/PjtKEIL_StepSon/StepSon.uvoptx | 31 +++++++++++------ 4 files changed, 60 insertions(+), 45 deletions(-) create mode 100644 elec/spice/pwm/PWM.net diff --git a/elec/spice/pwm/PWM.net b/elec/spice/pwm/PWM.net new file mode 100644 index 0000000..e0b939e --- /dev/null +++ b/elec/spice/pwm/PWM.net @@ -0,0 +1,16 @@ +* U:\3MIC\s2\BE-CHTI\assembleur\chti23\elec\spice\pwm\PWM.asc +V1 Compteur 0 PULSE(0 3.3 0 5u 0 0 5u) +C1 Filtre 0 10n +R1 Filtre PWM 3.9k +V2 CompValue 0 SINE(1.65 1 2k) +B1 PWM 0 V=if(V(CompValue)>V(Compteur),3.3,0) +;ac dec 100 1 10meg +.tran 0 1.5m 0 0.01u +* Compteur de l'unité Timer +* Partie PWM de l'unité Timer +* TIMER3 +* PB0 +* Chanel 3 +* STM32F103 +.backanno +.end diff --git a/soft/PjtKEIL_StepSon/Src/GestionSon.s b/soft/PjtKEIL_StepSon/Src/GestionSon.s index 493b83b..bb3b731 100644 --- a/soft/PjtKEIL_StepSon/Src/GestionSon.s +++ b/soft/PjtKEIL_StepSon/Src/GestionSon.s @@ -28,42 +28,26 @@ SortieSon dcw 0 CallbackSon proc ;; 1. Il faut pouvoir utiliser SortieSon comme index d'iteration dans le tableau bruitverre - push {r4,r5,r6,r7} - ldr r7,=SortieSon - ldr r1,=LongueurSon - ldr r2,=Son - mov r3,#0 - mov r4,#719 - lsr r4,r4,#1 + push {r4,r5,r6} + ldr r1,=SortieSon ;sortie + ldr r2,=LongueurSon ;nb de sons + ldr r3,=Son ;adresse du tableau de sons + mov r4,#0 ;compteur + mov r5,#(1<<15) ;registre pour operations + mov r6,#719 ;sauvegarde de 719 calcul - ldrsh r0, [r2,r3,lsl #1] - ;cmp r0,#0x00007FFF - ;bgt calcul_neg - ;faire +32768, ensuite x719, puis diviser par 2^16 - mov r5,#32767 - udiv r6,r5,r4 - mul r0,r6 - add r0,r4 - str r0,[r7] - add r3,#1 - cmp r1,r3 - bne calcul - bl fin - -calcul_neg - mov r5,#32768 - udiv r6,r4,r5 - mul r0,r6 - sub r0,r4 - lsl r5,r0,#1 - sub r0,r5 - str r0,[r7] - add r3,#1 - cmp r1,r3 + ldrsh r0, [r3,r4,lsl #1] + ;faire +32768, ensuite x719, puis diviser par 2^16 + add r0,r5 + mul r0,r0,r6 + lsr r0,#16 + str r0,[r1] + add r4,#1 + cmp r2,r4 bne calcul -fin - pop {r4,r5,r6,r7} + pop {r4,r5,r6} + endp END \ No newline at end of file diff --git a/soft/PjtKEIL_StepSon/Src/principal.c b/soft/PjtKEIL_StepSon/Src/principal.c index 9d3e7c3..4cd54f3 100644 --- a/soft/PjtKEIL_StepSon/Src/principal.c +++ b/soft/PjtKEIL_StepSon/Src/principal.c @@ -1,6 +1,7 @@ #include "DriverJeuLaser.h" +//#include "../Driver/DriverJeuLaser.inc" extern void CallbackSon(void); extern int PeriodeSonMicroSec; @@ -17,9 +18,12 @@ CLOCK_Configure(); Timer_1234_Init_ff(TIM4, (1/PeriodeSonMicroSec*0.000001) ); Active_IT_Debordement_Timer( TIM4, 2, CallbackSon ); + +//Timer_1234_Init_ff(TIM3, 720 ); +char GPIO_Configure(GPIOB, 0, OUTPUT, ALT_PPULL); +PWM_Init_ff(TIM3,3,720); +PWM_Set_Value_TIM3_Ch3(720); - - //============================================================================ diff --git a/soft/PjtKEIL_StepSon/StepSon.uvoptx b/soft/PjtKEIL_StepSon/StepSon.uvoptx index 765bc55..608ab4e 100644 --- a/soft/PjtKEIL_StepSon/StepSon.uvoptx +++ b/soft/PjtKEIL_StepSon/StepSon.uvoptx @@ -157,9 +157,9 @@ 0 0 - 37 + 42 1 -
134220580
+
134220588
0 0 0 @@ -168,7 +168,23 @@ 1 .\Src\GestionSon.s - \\StepSon\Src/GestionSon.s\37 + \\StepSon\Src/GestionSon.s\42 +
+ + 1 + 0 + 38 + 1 +
0
+ 0 + 0 + 0 + 0 + 0 + 0 + .\Src\GestionSon.s + +
@@ -187,17 +203,12 @@ 1 r0 - - 3 - 1 - r7 - 1 0 - r7 + r3 0 @@ -271,7 +282,7 @@ 0 `SortieSon - FF0000000000000000000000000000000080864000000000000000000000000000000000536F72746965536F6E00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000700000001000000000000000000F03F1000000000000000000000000000000000000000C40A0008 + FF0000000000000000000000000000000078864000000000000000000000000000000000536F72746965536F6E00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000700000001000000000000000000F03F1000000000000000000000000000000000000000C40A0008