Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*----------------------------------------------------------------------------
- * Name: Blinky.c
- * Purpose: LED Flasher
- * Note(s):
- *----------------------------------------------------------------------------
- * This file is part of the uVision/ARM development tools.
- * This software may only be used under the terms of a valid, current,
- * end user licence from KEIL for a compatible version of KEIL software
- * development tools. Nothing else gives you the right to use this software.
- *
- * This software is supplied "AS IS" without warranties of any kind.
- *
- * Copyright (c) 2011 Keil - An ARM Company. All rights reserved.
- *----------------------------------------------------------------------------*/
- #include <stdio.h>
- #include <math.h>
- #include "stm32f4xx.h"
- #include "tm_stm32f4_usart.h"
- #include "tm_stm32f4_delay.h"
- #include "tm_stm32f4_pwm.h"
- #include "tm_stm32f4_disco.h"
- #include "defines.h"
- #include "stm32f4xx_rcc.h"
- #include "stm32f4xx_tim.h"
- #include "misc.h"
- #include "tm_stm32f4_pwm.h"
- #include "stm32f4_servo_onur.h"
- #include "tm_stm32f4_adc.h"
- #include "tm_stm32f4_mpu6050.h"
- #define HMC5883L_Write 0x3C
- #define HMC5883L_Read 0x3D
- #define ConfigurationRegisterA 0x00
- #define ConfigurationRegisterB 0x01
- #define ModeRegister 0x02
- #define DataRegisterBegin 0x03
- #define Measurement_Continuous 0x00
- #define Measurement_SingleShot 0x01
- #define Measurement_Idle 0x03
- #define ErrorCode_1 "Entered scale was not valid, valid gauss values are: 0.88, 1.3, 1.9, 2.5, 4.0, 4.7, 5.6, 8.1"
- #define ErrorCode_1_Num 1
- #define BUFFER_SIZE 20
- TM_PWM_TIM_t TIM4_Data;
- uint8_t gelenVeri[2] = {0,0},sayac=0,k=0;
- uint16_t denetim=0;
- uint16_t yeniFrekans=0,yeniDoluluk=0,veri=0;
- uint16_t hangiPID[3] = {65001,65002,65003};
- uint16_t hangiMotor[7] = {65005,65006,65007,65008,65010,65011,65012};
- uint16_t Yuvarlanma_P=0,Yuvarlanma_I=0,Yuvarlanma_D=0,Yunuslama_P=0,Yunuslama_I=0,Yunuslama_D=0,Yonelme_P=0,Yonelme_I=0,Yonelme_D=0;
- uint16_t hizMotor_1=0,hizMotor_2=0,hizMotor_3=0,hizMotor_4=0,hizKameraSagSol=0,hizKameraYukariAsagi=0;
- double deger=0;
- GPIO_InitTypeDef GPIO_Init_Struct;
- TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
- TM_MPU6050_t MPU6050_Data1;
- double accX=0,accY=0,accZ=0,gyroX=0,gyroY=0,gyroZ=0,gy_aciX=0,gy_aciY=0,gy_aciZ=0,C_aciX=0,C_aciY=0,C_aciZ=0;
- double yeni_gyroX=0,yeni_gyroY=0,yeni_gyroZ=0,yeni_aciX=0,yeni_aciY=0,yeni_aciZ=0;
- double Katsayi=0.95;
- double roll=0,pitch=0,yaw=0;
- double RAD_TO_DEG = 180/3.1416;
- double pi = 3.1416;
- double dt = 0.1;
- double Q_angleX=0.001,Q_biasX=0.003,R_measureX=0.03,biasX=0,K_aciX=0;
- double Px[4]={0,0,0,0};
- double Q_angleY=0.001,Q_biasY=0.003,R_measureY=0.03,biasY=0,K_aciY=0;
- double Py[4]={0,0,0,0};
- double Q_angleZ=0.001,Q_biasZ=0.003,R_measureZ=0.03,biasZ=0,K_aciZ=0;
- double Pz[4]={0,0,0,0};
- int16_t veriHMC[3];
- int16_t sonveriHMC[3];
- uint8_t gelenHMC[6];
- char hata[30];
- double pusulaVeri=0, pusulaVeriLP=0;
- double kazanc[3];
- double m_Scale;
- uint8_t kontrol=0;
- double Mx2, My2, Mz2;
- double fc=800;
- double srate = 10;
- double sensorDataCircularSum=0;
- int indexBuffer=0;
- double circularBuffer[BUFFER_SIZE];
- double filteredOutput=0;
- double xFiltered=0, yFiltered=0, zFiltered=0, xFilteredOld=0, yFilteredOld=0, zFilteredOld=0;
- double alphaAccel = 0;
- double xMagnetFiltered=0, yMagnetFiltered=0, zMagnetFiltered=0, xMagnetFilteredOld=0, yMagnetFilteredOld=0, zMagnetFilteredOld=0;
- double alphaMagnet=0;
- double xMagnetMax=0, yMagnetMax=0, zMagnetMax=0, xMagnetMin=0, yMagnetMin=0, zMagnetMin=0, xMagnetMap=0, yMagnetMap=0, zMagnetMap=0;
- double doluluk=0;
- double smoothSensorReadings(double sensorRawData){
- // We remove the oldest value from the buffer
- sensorDataCircularSum= sensorDataCircularSum - circularBuffer[indexBuffer];
- // The new input from the sensor is placed in the buffer
- circularBuffer[indexBuffer]=sensorRawData;
- // It is also added to the total sum of the last BUFFER_SIZE readings
- // This method avoids to sum all the elements every time this function is called.
- sensorDataCircularSum+=sensorRawData;
- // We increment the cursor
- indexBuffer++;
- if (indexBuffer>=BUFFER_SIZE) indexBuffer=0;// We test if we arrived to the end
- //of the buffer, in which case we start again from index 0
- filteredOutput =(sensorDataCircularSum/BUFFER_SIZE); // The output is the the mean
- //value of the circular buffer.
- return filteredOutput;
- }
- void HMC5883L_VeriYaz(uint8_t Kaydedici, uint8_t Veri)
- {
- TM_I2C_Start(I2C1, HMC5883L_Write, I2C_Direction_Transmitter, 0);
- TM_I2C_WriteData(I2C1, Kaydedici);
- TM_I2C_WriteData(I2C1, Veri);
- TM_I2C_Stop(I2C1);
- }
- void HMC5883L_Oku()
- {
- // double sonuc=0;
- TM_I2C_ReadMulti(I2C1, HMC5883L_Read, DataRegisterBegin, gelenHMC, 6);
- TM_I2C_Stop(I2C1);
- veriHMC[0] = (gelenHMC[0] << 8) | gelenHMC[1];
- veriHMC[2] = (gelenHMC[2] << 8) | gelenHMC[3];
- veriHMC[1] = (gelenHMC[4] << 8) | gelenHMC[5];
- }
- int SetScale(double gauss)
- {
- uint8_t regValue = 0x00;
- if(gauss == 0.88)
- {
- regValue = 0x00;
- m_Scale = 0.73;
- }
- else if(gauss == 1.3)
- {
- regValue = 0x01;
- m_Scale = 0.92;
- }
- else if(gauss == 1.9)
- {
- regValue = 0x02;
- m_Scale = 1.22;
- }
- else if(gauss == 2.5)
- {
- regValue = 0x03;
- m_Scale = 1.52;
- }
- else if(gauss == 4.0)
- {
- regValue = 0x04;
- m_Scale = 2.27;
- }
- else if(gauss == 4.7)
- {
- regValue = 0x05;
- m_Scale = 2.56;
- }
- else if(gauss == 5.6)
- {
- regValue = 0x06;
- m_Scale = 3.03;
- }
- else if(gauss == 8.1)
- {
- regValue = 0x07;
- m_Scale = 4.35;
- }
- else
- return ErrorCode_1_Num;
- // Setting is in the top 3 bits of the register.
- regValue = regValue << 5;
- HMC5883L_VeriYaz(ConfigurationRegisterB,regValue);
- }
- void SetMeasurementMode(uint8_t durum)
- {
- HMC5883L_VeriYaz(ModeRegister,durum);
- }
- void GetErrorText(int errorCode)
- {
- if(ErrorCode_1_Num == 1)
- sprintf(hata,ErrorCode_1);
- else
- sprintf(hata,"Error not defined.");
- }
- void setupHMC5883L()
- {
- //Setup the HMC5883L, and check for errors
- int error;
- error = SetScale(1.3); //Set the scale of the compass.
- GetErrorText(error);
- if(error != 0)
- {
- // if (TM_USB_VCP_GetStatus() == TM_USB_VCP_CONNECTED)
- // TM_USB_VCP_Puts(hata);
- }
- SetMeasurementMode(Measurement_Continuous); // Set the measurement mode to Continuous
- }
- void ReadScaledAxis()
- {
- HMC5883L_Oku();
- sonveriHMC[0] = veriHMC[0] * m_Scale;
- sonveriHMC[1] = veriHMC[1] * m_Scale;
- sonveriHMC[2] = veriHMC[2] * m_Scale;
- }
- double getHeading()
- {
- //scaled values from compass.
- double heading;
- ReadScaledAxis();
- heading = atan2(sonveriHMC[1], sonveriHMC[0]);
- // if(heading < 0)
- // heading += 2*pi;
- // else if(heading > 2*pi)
- // heading -= 2*pi;
- return heading * RAD_TO_DEG; //radians to degrees
- }
- void HMC5883L_Baslat()
- {
- TM_I2C_Start(I2C1, HMC5883L_Write, I2C_Direction_Transmitter, 0);
- TM_I2C_WriteData(I2C1, 0x00);
- TM_I2C_WriteData(I2C1, 0x70);
- TM_I2C_Stop(I2C1);
- TM_I2C_Start(I2C1, HMC5883L_Write, I2C_Direction_Transmitter, 0);
- TM_I2C_WriteData(I2C1, 0x01);
- TM_I2C_WriteData(I2C1, 0xA0);
- TM_I2C_Stop(I2C1);
- TM_I2C_Start(I2C1, HMC5883L_Write, I2C_Direction_Transmitter, 0);
- TM_I2C_WriteData(I2C1, 0x02);
- TM_I2C_WriteData(I2C1, 0x00);
- TM_I2C_Stop(I2C1);
- }
- void aciAlX(double yeniAciX)
- {
- K_aciX = yeniAciX;
- }
- void aciAlY(double yeniAciY)
- {
- K_aciY = yeniAciY;
- }
- void aciAlZ(double yeniAciZ)
- {
- K_aciZ = yeniAciZ;
- }
- double KalmanX_Hesapla(double gelenAciX,double yeniDegisimX)
- {
- double Sx=0,Kx[2]={0,0},yx=0;
- double P00_tempX=0,P01_tempX=0;
- yeni_gyroX = yeniDegisimX-biasX;
- K_aciX += dt*yeni_gyroX;
- Px[0] += dt * (dt*Px[3]-Px[1]-Px[2]+Q_angleX);
- Px[1] -= dt * Px[3];
- Px[2] -= dt * Px[3];
- Px[3] += Q_biasX * dt;
- Sx = Px[0]+R_measureX;
- Kx[0] = Px[0] / Sx;
- Kx[1] = Px[2] / Sx;
- yx = gelenAciX-K_aciX;
- K_aciX += Kx[0] * yx;
- biasX += Kx[1] * yx;
- P00_tempX = Px[0];
- P01_tempX = Px[1];
- Px[0] -= Kx[0] * P00_tempX;
- Px[1] -= Kx[0] * P01_tempX;
- Px[2] -= Kx[1] * P00_tempX;
- Px[3] -= Kx[1] * P01_tempX;
- return K_aciX;
- }
- double KalmanY_Hesapla(double gelenAciY,double yeniDegisimY)
- {
- double Sy=0,Ky[2]={0,0},yy=0;
- double P00_tempY=0,P01_tempY=0;
- yeni_gyroY = yeniDegisimY-biasY;
- K_aciY += dt*yeni_gyroY;
- Py[0] += dt * (dt*Py[3]-Py[1]-Py[2]+Q_angleY);
- Py[1] -= dt * Py[3];
- Py[2] -= dt * Py[3];
- Py[3] += Q_biasY * dt;
- Sy = Py[0]+R_measureY;
- Ky[0] = Py[0] / Sy;
- Ky[1] = Py[2] / Sy;
- yy = gelenAciY-K_aciY;
- K_aciY += Ky[0] * yy;
- biasY += Ky[1] * yy;
- P00_tempY = Py[0];
- P01_tempY = Py[1];
- Py[0] -= Ky[0] * P00_tempY;
- Py[1] -= Ky[0] * P01_tempY;
- Py[2] -= Ky[1] * P00_tempY;
- Py[3] -= Ky[1] * P01_tempY;
- return K_aciY;
- }
- double KalmanZ_Hesapla(double gelenAciZ,double yeniDegisimZ)
- {
- double Sz=0,Kz[2]={0,0},yz=0;
- double P00_tempZ=0,P01_tempZ=0;
- yeni_gyroZ = yeniDegisimZ-biasZ;
- K_aciZ += dt*yeni_gyroZ;
- Pz[0] += dt * (dt*Pz[3]-Pz[1]-Pz[2]+Q_angleZ);
- Pz[1] -= dt * Pz[3];
- Pz[2] -= dt * Pz[3];
- Pz[3] += Q_biasZ * dt;
- Sz = Pz[0]+R_measureZ;
- Kz[0] = Pz[0] / Sz;
- Kz[1] = Pz[2] / Sz;
- yz = gelenAciZ-K_aciZ;
- K_aciZ += Kz[0] * yz;
- biasZ += Kz[1] * yz;
- P00_tempZ = Pz[0];
- P01_tempZ = Pz[1];
- Pz[0] -= Kz[0] * P00_tempZ;
- Pz[1] -= Kz[0] * P01_tempZ;
- Pz[2] -= Kz[1] * P00_tempZ;
- Pz[3] -= Kz[1] * P01_tempZ;
- return K_aciZ;
- }
- void veriOkuMPU()
- {
- TM_MPU6050_ReadAll(&MPU6050_Data1);
- accX = MPU6050_Data1.Accelerometer_X / 182.0;
- accY = MPU6050_Data1.Accelerometer_Y / 182.0;
- accZ = MPU6050_Data1.Accelerometer_Z / 182.0;
- gyroX = MPU6050_Data1.Gyroscope_X / 131.0;
- gyroY = MPU6050_Data1.Gyroscope_Y / 131.0;
- gyroZ = MPU6050_Data1.Gyroscope_Z / 131.0;
- roll = atan2(accY, accZ) * RAD_TO_DEG;
- pitch = atan(-accX / sqrt(accY * accY + accZ * accZ)) * RAD_TO_DEG;
- }
- void TM_USART1_ReceiveHandler(uint8_t alinanVeri)
- {
- gelenVeri[sayac] = alinanVeri; //Karsidan gelen veriler iki bayt oldugu icin iki adet veri bekliyoruz
- sayac++;
- if(sayac==2) //Iki adet bayt gelmisse
- {
- sayac=0; //Gelecek islemler icin sayac sifirlaniyor
- veri = ( gelenVeri[1] << 8 ) + gelenVeri[0]; //16 bitlik degerimizi aliyoruz
- if((veri==hangiPID[0]) || (veri==hangiPID[1]) || (veri==hangiPID[2]) || (veri==hangiMotor[0]) || (veri==hangiMotor[1]) || (veri==hangiMotor[2]) || (veri==hangiMotor[3]) || (veri==hangiMotor[4]) || (veri==hangiMotor[5]) || (veri==hangiMotor[6])) //Gelen bilgi hangi islem bilgisi verisi mi kontrol ediliyor
- denetim = veri;
- else
- {
- if(denetim == hangiPID[0]) //Eger pwm islemine ait veriyse
- {
- if(k==0)
- {
- k=1;
- Yuvarlanma_P = (gelenVeri[1] << 8) + gelenVeri[0];
- TM_USART_Putc(USART1,gelenVeri[0]); //Gelen verileri hata denetimi icin tekrar yolla
- TM_USART_Putc(USART1,gelenVeri[1]);
- }
- else if(k==1)
- {
- k=2;
- Yuvarlanma_I = (gelenVeri[1] << 8) + gelenVeri[0];
- TM_USART_Putc(USART1,gelenVeri[0]); //Gelen verileri hata denetimi icin tekrar yolla
- TM_USART_Putc(USART1,gelenVeri[1]);
- }
- else if(k==2)
- {
- k=0;
- Yuvarlanma_D = (gelenVeri[1] << 8) + gelenVeri[0];
- TM_USART_Putc(USART1,gelenVeri[0]); //Gelen verileri hata denetimi icin tekrar yolla
- TM_USART_Putc(USART1,gelenVeri[1]);
- }
- }
- else if(denetim == hangiPID[1]) //Eger pwm islemine ait veriyse
- {
- if(k==0)
- {
- k=1;
- Yunuslama_P = (gelenVeri[1] << 8) + gelenVeri[0];
- TM_USART_Putc(USART1,gelenVeri[0]); //Gelen verileri hata denetimi icin tekrar yolla
- TM_USART_Putc(USART1,gelenVeri[1]);
- }
- else if(k==1)
- {
- k=2;
- Yunuslama_I = (gelenVeri[1] << 8) + gelenVeri[0];
- TM_USART_Putc(USART1,gelenVeri[0]); //Gelen verileri hata denetimi icin tekrar yolla
- TM_USART_Putc(USART1,gelenVeri[1]);
- }
- else if(k==2)
- {
- k=0;
- Yunuslama_D = (gelenVeri[1] << 8) + gelenVeri[0];
- TM_USART_Putc(USART1,gelenVeri[0]); //Gelen verileri hata denetimi icin tekrar yolla
- TM_USART_Putc(USART1,gelenVeri[1]);
- }
- }
- else if(denetim == hangiPID[2]) //Eger pwm islemine ait veriyse
- {
- if(k==0)
- {
- k=1;
- Yonelme_P = (gelenVeri[1] << 8) + gelenVeri[0];
- TM_USART_Putc(USART1,gelenVeri[0]); //Gelen verileri hata denetimi icin tekrar yolla
- TM_USART_Putc(USART1,gelenVeri[1]);
- }
- else if(k==1)
- {
- k=2;
- Yonelme_I = (gelenVeri[1] << 8) + gelenVeri[0];
- TM_USART_Putc(USART1,gelenVeri[0]); //Gelen verileri hata denetimi icin tekrar yolla
- TM_USART_Putc(USART1,gelenVeri[1]);
- }
- else if(k==2)
- {
- k=0;
- Yonelme_D = (gelenVeri[1] << 8) + gelenVeri[0];
- TM_USART_Putc(USART1,gelenVeri[0]); //Gelen verileri hata denetimi icin tekrar yolla
- TM_USART_Putc(USART1,gelenVeri[1]);
- }
- }
- else if(denetim==hangiMotor[4])
- {
- hizMotor_1 = (gelenVeri[1] << 8) + gelenVeri[0];
- hizMotor_2 = hizMotor_1;
- hizMotor_3 = hizMotor_1;
- hizMotor_4 = hizMotor_1;
- TM_USART_Putc(USART1,gelenVeri[0]); //Gelen verileri hata denetimi icin tekrar yolla
- TM_USART_Putc(USART1,gelenVeri[1]);
- }
- else if(denetim==hangiMotor[0])
- {
- hizMotor_1 = (gelenVeri[1] << 8) + gelenVeri[0];
- TM_USART_Putc(USART1,gelenVeri[0]); //Gelen verileri hata denetimi icin tekrar yolla
- TM_USART_Putc(USART1,gelenVeri[1]);
- }
- else if(denetim==hangiMotor[1])
- {
- hizMotor_2 = (gelenVeri[1] << 8) + gelenVeri[0];
- TM_USART_Putc(USART1,gelenVeri[0]); //Gelen verileri hata denetimi icin tekrar yolla
- TM_USART_Putc(USART1,gelenVeri[1]);
- }
- else if(denetim==hangiMotor[2])
- {
- hizMotor_3 = (gelenVeri[1] << 8) + gelenVeri[0];
- TM_USART_Putc(USART1,gelenVeri[0]); //Gelen verileri hata denetimi icin tekrar yolla
- TM_USART_Putc(USART1,gelenVeri[1]);
- }
- else if(denetim==hangiMotor[3])
- {
- hizMotor_4 = (gelenVeri[1] << 8) + gelenVeri[0];
- TM_USART_Putc(USART1,gelenVeri[0]); //Gelen verileri hata denetimi icin tekrar yolla
- TM_USART_Putc(USART1,gelenVeri[1]);
- }
- else if(denetim==hangiMotor[5])
- {
- hizKameraSagSol = (gelenVeri[1] << 8) + gelenVeri[0];
- TM_USART_Putc(USART1,gelenVeri[0]); //Gelen verileri hata denetimi icin tekrar yolla
- TM_USART_Putc(USART1,gelenVeri[1]);
- }
- else if(denetim==hangiMotor[6])
- {
- hizKameraYukariAsagi = (gelenVeri[1] << 8) + gelenVeri[0];
- TM_USART_Putc(USART1,gelenVeri[0]); //Gelen verileri hata denetimi icin tekrar yolla
- TM_USART_Putc(USART1,gelenVeri[1]);
- }
- }
- }
- }
- void TIM7_IRQHandler(void)
- {
- if (TIM_GetITStatus(TIM7, TIM_IT_Update) != RESET)
- {
- veriOkuMPU();
- pusulaVeri = getHeading();
- pusulaVeriLP = smoothSensorReadings(pusulaVeri);
- if ((roll < -90 && K_aciX > 90) || (roll > 90 && K_aciX < -90))
- {
- aciAlX(roll);
- C_aciX = roll;
- K_aciX = roll;
- gy_aciX = roll;
- }
- else
- K_aciX = KalmanX_Hesapla(roll,gyroX); // Calculate the angle using a Kalman filter
- if (K_aciX > 90 || K_aciX < -90)
- gyroY = -gyroY; // Invert rate, so it fits the restriced accelerometer reading
- K_aciY = KalmanY_Hesapla(pitch,gyroY);
- K_aciZ = KalmanZ_Hesapla(pusulaVeri,gyroZ);
- gy_aciX = roll + gyroX * dt; // Calculate gyro angle without any filter
- gy_aciY = pitch + gyroY * dt;
- gy_aciZ = pusulaVeri + gyroZ * dt;
- C_aciX = Katsayi*(C_aciX+gyroX*dt)+(1-Katsayi)*roll;
- C_aciY = Katsayi*(C_aciY+gyroY*dt)+(1-Katsayi)*pitch;
- C_aciZ = Katsayi*(C_aciZ+gyroZ*dt)+(1-Katsayi)*pusulaVeri;
- }
- }
- void Zamanlayici_Baslat(void) {
- TIM_TimeBaseInitTypeDef TIM_BaseStruct;
- NVIC_InitTypeDef NVIC_InitStructure;
- NVIC_InitStructure.NVIC_IRQChannel = TIM7_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM7, ENABLE);
- TIM_BaseStruct.TIM_Prescaler = 8399;
- TIM_BaseStruct.TIM_CounterMode = TIM_CounterMode_Up;
- TIM_BaseStruct.TIM_Period = 999; /* 100 ms */
- TIM_BaseStruct.TIM_ClockDivision = TIM_CKD_DIV1;
- TIM_BaseStruct.TIM_RepetitionCounter = 0;
- TIM_TimeBaseInit(TIM7, &TIM_BaseStruct);
- TIM_ITConfig(TIM7, TIM_IT_Update, ENABLE);
- TIM_Cmd(TIM7, ENABLE);
- }
- int main (void) {
- // TM_PWM_TIM_t TIM3_Data;
- // double dolulukOrani = 0;
- // char str[15];
- /* Servo structs */
- TM_SERVO_t Servo1;
- /* Initialize system */
- SystemInit();
- /* Initialize USART1, 9600baud, TX: PB6 */
- TM_USART_Init(USART1, TM_USART_PinsPack_2, 9600);
- /* Initialize ADC0 on channel 1, this is pin PA1 */
- TM_ADC_Init(ADC1, ADC_Channel_1);
- /* Initialize delay */
- TM_DELAY_Init();
- /* Initialize servo 1, TIM3, Channel 1, Pinspack 2 = PB4 */
- TM_SERVO_Init(&Servo1, TIM3, TM_PWM_Channel_1, TM_PWM_PinsPack_2);
- /* Set PWM to 1Hz frequency on timer TIM3 */
- TM_PWM_InitTimer(TIM4, &TIM4_Data, 1);
- /* Initialize PWM on TIM4, Channel 1 and PinsPack 2 = PD12 */
- TM_PWM_InitChannel(&TIM4_Data, TM_PWM_Channel_1, TM_PWM_PinsPack_2);
- // TM_USB_VCP_Init();
- // - TM_I2C_Pinspack_2:
- // - I2C1: SCL: PB8, SDA: PB9
- TM_I2C_Init(I2C1, TM_I2C_PinsPack_2, 400000);
- TM_MPU6050_Init(&MPU6050_Data1, TM_MPU6050_Device_1, TM_MPU6050_Accelerometer_8G, TM_MPU6050_Gyroscope_250s);
- Zamanlayici_Baslat();
- // TM_SERVO_SetDegrees(&Servo1, 200);
- // Delayms(2000);
- // TM_SERVO_SetDegrees(&Servo1, 0);
- // Delayms(2000);
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
- while (1)
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement