You are on page 1of 5

EL-203

Lab Report : 2

Group Member: Group No. : 07

Bhavya Shah : 201901017

Manav Jain : 201901177

Tirthraj : 201901185

Dev Joshi : 201901304

Aim : - Generating sine wave in STM32407VGtx using Keil.

1) Code of Modelling Sine Wave in MATLAB

clc;
f=10;
a=2;
ts=0.001;
T=5;
t=0: ts:T;
y=a*sin(2*pi*f*t);
plot(t,y);
csvwrite("sine_discreat1.txt",y);
disp(length(y));

We have taken 5001 samples of sine wave. Amplitude of sine


wave is 2 unit and frequency is 10 unit. We are changing t from 0
to T=5 second with increment of 0.001 second. So we are getting
(5-0) / (0.001) = 5000 +1 = 5001 samples (1 more for zero).

2) Simulation code of sine wave :

#include "stm32f4xx_hal.h" // Keil::Device:STM32Cube


HAL:Common
#include "arm_math.h" // ARM::CMSIS:DSP
#define SIG_LENGTH 5001
uint32_t freq;
float32_t inputSample;
extern float32_t _10Hz_sine_wave[SIG_LENGTH];
void SysTick_Handler(void)
{
HAL_IncTick();
HAL_SYSTICK_IRQHandler();
}
void plot_sine_wave() {
for(int i=0; i<SIG_LENGTH ; ++i) {
inputSample = _10Hz_sine_wave[i];
HAL_Delay(1);
}
}
int main()
{
int i;
HAL_Init();
freq = HAL_RCC_GetHCLKFreq();
plot_sine_wave();
while(1){
}
}

sinewave.c file :-

This file is too big because it contains 5001 samples.


So we are attaching pastebin link of this file.
Link for 5001 samples :
https://pastebin.com/raw/hfLbeY8N

3) Result of simulation :

* For 5001 samples :

This is result of code which has 5001 samples. In


this simulation amplitude of sine wave is 2 unit.

4) Conclution :
In this lab we have generated sine wave in
STM32407VGtx microcontroller. We have used two .c files
to generate sine wave. sinewave.c file contains samples of
sine wave of amplitude = 5 which we have generated
through MATLAB code. In the main file we have used this
samples to generate sine wave. Different to previous lab
we have added DSP in ‘Manage Runtime Environment’
which is used for mathematical calculations. We can
change amplitude and frequency by generating samples
accordingly from MATLAB file.

We could have generated sine wave from only main.c file


by calculating amplitudes at run time but it could have
increased calculations at microcontroller So that, what we
have done here is, we have stored amplitudes in different
file and from main file we have iterated in that amplitudes
and got the sine wave.

You might also like