Added servo, motoreducteur and working on rtc

This commit is contained in:
Alix Chagot 2023-04-04 14:36:29 +02:00
parent 7009c70707
commit 355f050ddd
12 changed files with 363 additions and 38 deletions

View file

@ -4,6 +4,7 @@
void plantage(void) { void plantage(void) {
while(1); while(1);
} }
void (*IT_Tim1) (void) = plantage; void (*IT_Tim1) (void) = plantage;
void (*IT_Tim2) (void) = plantage; void (*IT_Tim2) (void) = plantage;
void (*IT_Tim3) (void) = plantage; void (*IT_Tim3) (void) = plantage;
@ -168,10 +169,10 @@ if(Timer == TIM1)
MyGPIO_Init(&PWM_OUT); MyGPIO_Init(&PWM_OUT);
} }
void MyTimer_DutyCycle(TIM_TypeDef * Timer, char Channel, unsigned char DutyCycle) void MyTimer_DutyCycle(TIM_TypeDef * Timer, char Channel, unsigned int DutyCycle)
{ {
unsigned int RC; unsigned int RC;
RC = ((Timer->ARR)/100)*(DutyCycle); RC = ((Timer->ARR)*(DutyCycle)/10000);
switch (Channel) { switch (Channel) {
case 1: case 1:
Timer->CCR1 = RC; Timer->CCR1 = RC;

View file

@ -11,7 +11,7 @@ typedef struct {
void MyTimer_Base_Init(MyTimer_Struct_Typedef * Timer); void MyTimer_Base_Init(MyTimer_Struct_Typedef * Timer);
void MyTimer_ActiveIT(TIM_TypeDef * Timer, char Prio, void (*IT_function) (void)); void MyTimer_ActiveIT(TIM_TypeDef * Timer, char Prio, void (*IT_function) (void));
void MyTimer_PWM(TIM_TypeDef * Timer ,char Channel); void MyTimer_PWM(TIM_TypeDef * Timer ,char Channel);
void MyTimer_DutyCycle(TIM_TypeDef * Timer, char Channel, unsigned char DutyCycle); void MyTimer_DutyCycle(TIM_TypeDef * Timer, char Channel, unsigned int DutyCycle);
#define MyTimer_Base_Start(Tim) (Tim.Timer->CR1 |= TIM_CR1_CEN) #define MyTimer_Base_Start(Tim) (Tim.Timer->CR1 |= TIM_CR1_CEN)
#define MyTimer_Base_Stop(Tim) (Tim.Timer->CR1 &= ~TIM_CR1_CEN) #define MyTimer_Base_Stop(Tim) (Tim.Timer->CR1 &= ~TIM_CR1_CEN)

View file

@ -0,0 +1,41 @@
#include "motoreducteur.h"
#include "timer.h"
#include "gpio.h"
void MyMotor_Init()
{
MyTimer_Struct_Typedef Timer;
MyGPIO_Struct_TypeDef Pin_Direction;
//F de 50kHz
Timer.Timer = TIM3;
Timer.ARR = 3599; //72Mhz / 50kHz = 1440 et 1440*1 = 1440
Timer.PSC = 0;
Pin_Direction.GPIO = GPIOB;
Pin_Direction.GPIO_Pin = 1;
Pin_Direction.GPIO_Conf = Out_PullUp;
MyTimer_Base_Init(&Timer);
MyGPIO_Init(&Pin_Direction);
//Pin Timer 3 Channel 3 PB0
MyTimer_PWM(TIM3, 3);
MyTimer_DutyCycle(TIM3, 3, 0);
MyTimer_Base_Start(Timer);
MyMotor_ChangeDirection(ANTIHOR);
}
void MyMotor_ChangeSpeed(unsigned int DC)
{
MyTimer_DutyCycle(TIM3, 3, DC);
}
void MyMotor_ChangeDirection(uint8_t Sens)
{
if (Sens == HORAIRE)
MyGPIO_Set(GPIOB, 1);
if (Sens == ANTIHOR)
MyGPIO_Reset(GPIOB, 1);
}

View file

@ -0,0 +1,12 @@
#ifndef MYMOTOR_H
#define MYMOTOR_H
#include "stm32f10x.h"
#define HORAIRE 0x1
#define ANTIHOR 0x0
void MyMotor_Init();
void MyMotor_ChangeSpeed(unsigned int DC);
void MyMotor_ChangeDirection(uint8_t Sens);
#endif

24
implementation/rtc.c Normal file
View file

@ -0,0 +1,24 @@
#include "rtc.h"
void plantage_i2C(void) {
while(1);
}
void (*IT_I2C_Err) (void) = plantage_i2C;
void MyRTC_Init()
{
MyI2C_Init(I2C1, 15, IT_I2C_Err);
}
void MyRTC_GetTime()
{
MyI2C_RecSendData_Typedef data;
char regCopy = 0;
data.SlaveAdress7bits = 0xC8;
data.Ptr_Data = &regCopy;
data.Nb_Data = 1;
MyI2C_GetString(I2C1, 0x0, &data);
}

9
implementation/rtc.h Normal file
View file

@ -0,0 +1,9 @@
#ifndef GPIODRIVER_H
#define GPIODRIVER_H
#include "stm32f10x.h"
#include "MyI2C.h"
void MyRTC_Init();
void MyRTC_GetTime();
#endif

30
implementation/servo.c Normal file
View file

@ -0,0 +1,30 @@
#include "servo.h"
#include "timer.h"
void MyServo_Init()
{
MyTimer_Struct_Typedef Timer;
//Période de 20ms -> F de 50Hz
Timer.Timer = TIM2;
Timer.ARR = 3599; //20*180 (angle) = 3600
Timer.PSC = 399; //72Mhz / 50Hz = 1.44Mhz et 3600*400 = 1.44M
MyTimer_Base_Init(&Timer);
//Pin Timer 2 Channel 1 PA0
MyTimer_PWM(TIM2, 1);
MyTimer_DutyCycle(TIM2, 1, 750);
MyTimer_Base_Start(Timer);
}
void MyServo_ChangeAngle(uint8_t Angle)
{
if (Angle > 180)
Angle = 180;
int DC = 500 + (Angle * 500 / 180);
MyTimer_DutyCycle(TIM2, 1, DC);
}

13
implementation/servo.h Normal file
View file

@ -0,0 +1,13 @@
#ifndef MYSERVO_H
#define MYSERVO_H
#include "stm32f10x.h"
/*
180 correspond à 0°
0 correspond à 90°
*/
void MyServo_Init();
void MyServo_ChangeAngle(uint8_t Angle);
#endif

View file

@ -3,7 +3,7 @@
* Auto generated Run-Time-Environment Configuration File * Auto generated Run-Time-Environment Configuration File
* *** Do not modify ! *** * *** Do not modify ! ***
* *
* Project: 'gpiodriver' * Project: 'voilier'
* Target: 'Réel' * Target: 'Réel'
*/ */

View file

@ -1,8 +1,16 @@
#include "stm32f10x.h" #include "stm32f10x.h"
#include "../../driver/MyI2C.h" #include "servo.h"
#include "../../driver/MySPI.h" #include "motoreducteur.h"
int main (void) int main (void)
{ {
while(1){}; MyServo_Init();
} MyServo_ChangeAngle(179);
MyMotor_Init();
MyMotor_ChangeSpeed(2000);
MyMotor_ChangeDirection(HORAIRE);
while(1){};
}

View file

@ -75,7 +75,7 @@
<OPTFL> <OPTFL>
<tvExp>1</tvExp> <tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<IsCurrentTarget>1</IsCurrentTarget> <IsCurrentTarget>0</IsCurrentTarget>
</OPTFL> </OPTFL>
<CpuCode>18</CpuCode> <CpuCode>18</CpuCode>
<DebugOpt> <DebugOpt>
@ -142,23 +142,23 @@
<Bp> <Bp>
<Number>0</Number> <Number>0</Number>
<Type>0</Type> <Type>0</Type>
<LineNumber>15</LineNumber> <LineNumber>13</LineNumber>
<EnabledFlag>1</EnabledFlag> <EnabledFlag>1</EnabledFlag>
<Address>134218740</Address> <Address>0</Address>
<ByteObject>0</ByteObject> <ByteObject>0</ByteObject>
<HtxType>0</HtxType> <HtxType>0</HtxType>
<ManyObjects>0</ManyObjects> <ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject> <SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess> <BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount> <BreakIfRCount>0</BreakIfRCount>
<Filename>.\Source\Principale.c</Filename> <Filename>.\Source\Principale.c</Filename>
<ExecCommand></ExecCommand> <ExecCommand></ExecCommand>
<Expression>\\cool_Simule\Source/Principale.c\15</Expression> <Expression></Expression>
</Bp> </Bp>
<Bp> <Bp>
<Number>1</Number> <Number>1</Number>
<Type>0</Type> <Type>0</Type>
<LineNumber>19</LineNumber> <LineNumber>12</LineNumber>
<EnabledFlag>1</EnabledFlag> <EnabledFlag>1</EnabledFlag>
<Address>0</Address> <Address>0</Address>
<ByteObject>0</ByteObject> <ByteObject>0</ByteObject>
@ -174,6 +174,38 @@
<Bp> <Bp>
<Number>2</Number> <Number>2</Number>
<Type>0</Type> <Type>0</Type>
<LineNumber>15</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>134218740</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>.\Source\Principale.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\cool_Simule\Source/Principale.c\15</Expression>
</Bp>
<Bp>
<Number>3</Number>
<Type>0</Type>
<LineNumber>19</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>0</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>0</BreakIfRCount>
<Filename>.\Source\Principale.c</Filename>
<ExecCommand></ExecCommand>
<Expression></Expression>
</Bp>
<Bp>
<Number>4</Number>
<Type>0</Type>
<LineNumber>7</LineNumber> <LineNumber>7</LineNumber>
<EnabledFlag>1</EnabledFlag> <EnabledFlag>1</EnabledFlag>
<Address>0</Address> <Address>0</Address>
@ -188,7 +220,7 @@
<Expression></Expression> <Expression></Expression>
</Bp> </Bp>
<Bp> <Bp>
<Number>3</Number> <Number>5</Number>
<Type>0</Type> <Type>0</Type>
<LineNumber>8</LineNumber> <LineNumber>8</LineNumber>
<EnabledFlag>1</EnabledFlag> <EnabledFlag>1</EnabledFlag>
@ -332,7 +364,7 @@
<OPTFL> <OPTFL>
<tvExp>1</tvExp> <tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<IsCurrentTarget>0</IsCurrentTarget> <IsCurrentTarget>1</IsCurrentTarget>
</OPTFL> </OPTFL>
<CpuCode>18</CpuCode> <CpuCode>18</CpuCode>
<DebugOpt> <DebugOpt>
@ -387,7 +419,7 @@
<SetRegEntry> <SetRegEntry>
<Number>0</Number> <Number>0</Number>
<Key>ST-LINKIII-KEIL_SWO</Key> <Key>ST-LINKIII-KEIL_SWO</Key>
<Name>-U066FFF504955857567155843 -O206 -SF10000 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP (ARM Core") -D00(1BA01477) -L00(0) -TO131090 -TC10000000 -TT10000000 -TP21 -TDS8000 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM)</Name> <Name>-U066AFF504955857567212155 -O206 -SF10000 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP (ARM Core") -D00(1BA01477) -L00(0) -TO131090 -TC10000000 -TT10000000 -TP21 -TDS8000 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM)</Name>
</SetRegEntry> </SetRegEntry>
<SetRegEntry> <SetRegEntry>
<Number>0</Number> <Number>0</Number>
@ -410,24 +442,7 @@
<Name>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128 -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM))</Name> <Name>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128 -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM))</Name>
</SetRegEntry> </SetRegEntry>
</TargetDriverDllRegistry> </TargetDriverDllRegistry>
<Breakpoint> <Breakpoint/>
<Bp>
<Number>0</Number>
<Type>0</Type>
<LineNumber>6</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>0</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>0</BreakIfRCount>
<Filename>.\Source\Principale.c</Filename>
<ExecCommand></ExecCommand>
<Expression></Expression>
</Bp>
</Breakpoint>
<WatchWindow1> <WatchWindow1>
<Ww> <Ww>
<count>0</count> <count>0</count>
@ -530,6 +545,98 @@
<RteFlg>0</RteFlg> <RteFlg>0</RteFlg>
<bShared>0</bShared> <bShared>0</bShared>
</File> </File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>3</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\driver\gpio.c</PathWithFileName>
<FilenameWithoutPath>gpio.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>4</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\driver\timer.c</PathWithFileName>
<FilenameWithoutPath>timer.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>5</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\driver\uart.c</PathWithFileName>
<FilenameWithoutPath>uart.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>2</GroupNumber>
<FileNumber>6</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\driver\adc.c</PathWithFileName>
<FilenameWithoutPath>adc.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
</Group>
<Group>
<GroupName>MesImplementations</GroupName>
<tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel>
<RteFlg>0</RteFlg>
<File>
<GroupNumber>3</GroupNumber>
<FileNumber>7</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\implementation\servo.c</PathWithFileName>
<FilenameWithoutPath>servo.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>3</GroupNumber>
<FileNumber>8</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\implementation\motoreducteur.c</PathWithFileName>
<FilenameWithoutPath>motoreducteur.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>3</GroupNumber>
<FileNumber>9</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\implementation\rtc.c</PathWithFileName>
<FilenameWithoutPath>rtc.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
</Group> </Group>
<Group> <Group>
@ -542,7 +649,7 @@
<Group> <Group>
<GroupName>::Device</GroupName> <GroupName>::Device</GroupName>
<tvExp>1</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel> <cbSel>0</cbSel>
<RteFlg>1</RteFlg> <RteFlg>1</RteFlg>

View file

@ -339,7 +339,7 @@
<MiscControls></MiscControls> <MiscControls></MiscControls>
<Define></Define> <Define></Define>
<Undefine></Undefine> <Undefine></Undefine>
<IncludePath>.\Include</IncludePath> <IncludePath>.\Include;..\driver;..\implementation</IncludePath>
</VariousControls> </VariousControls>
</Cads> </Cads>
<Aads> <Aads>
@ -398,6 +398,46 @@
<FileType>4</FileType> <FileType>4</FileType>
<FilePath>..\driver\Lib_Com_Periph_2022.lib</FilePath> <FilePath>..\driver\Lib_Com_Periph_2022.lib</FilePath>
</File> </File>
<File>
<FileName>gpio.c</FileName>
<FileType>1</FileType>
<FilePath>..\driver\gpio.c</FilePath>
</File>
<File>
<FileName>timer.c</FileName>
<FileType>1</FileType>
<FilePath>..\driver\timer.c</FilePath>
</File>
<File>
<FileName>uart.c</FileName>
<FileType>1</FileType>
<FilePath>..\driver\uart.c</FilePath>
</File>
<File>
<FileName>adc.c</FileName>
<FileType>1</FileType>
<FilePath>..\driver\adc.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>MesImplementations</GroupName>
<Files>
<File>
<FileName>servo.c</FileName>
<FileType>1</FileType>
<FilePath>..\implementation\servo.c</FilePath>
</File>
<File>
<FileName>motoreducteur.c</FileName>
<FileType>1</FileType>
<FilePath>..\implementation\motoreducteur.c</FilePath>
</File>
<File>
<FileName>rtc.c</FileName>
<FileType>1</FileType>
<FilePath>..\implementation\rtc.c</FilePath>
</File>
</Files> </Files>
</Group> </Group>
<Group> <Group>
@ -741,7 +781,7 @@
<MiscControls></MiscControls> <MiscControls></MiscControls>
<Define></Define> <Define></Define>
<Undefine></Undefine> <Undefine></Undefine>
<IncludePath>.\Include</IncludePath> <IncludePath>.\Include;..\driver;..\implementation</IncludePath>
</VariousControls> </VariousControls>
</Cads> </Cads>
<Aads> <Aads>
@ -800,6 +840,46 @@
<FileType>4</FileType> <FileType>4</FileType>
<FilePath>..\driver\Lib_Com_Periph_2022.lib</FilePath> <FilePath>..\driver\Lib_Com_Periph_2022.lib</FilePath>
</File> </File>
<File>
<FileName>gpio.c</FileName>
<FileType>1</FileType>
<FilePath>..\driver\gpio.c</FilePath>
</File>
<File>
<FileName>timer.c</FileName>
<FileType>1</FileType>
<FilePath>..\driver\timer.c</FilePath>
</File>
<File>
<FileName>uart.c</FileName>
<FileType>1</FileType>
<FilePath>..\driver\uart.c</FilePath>
</File>
<File>
<FileName>adc.c</FileName>
<FileType>1</FileType>
<FilePath>..\driver\adc.c</FilePath>
</File>
</Files>
</Group>
<Group>
<GroupName>MesImplementations</GroupName>
<Files>
<File>
<FileName>servo.c</FileName>
<FileType>1</FileType>
<FilePath>..\implementation\servo.c</FilePath>
</File>
<File>
<FileName>motoreducteur.c</FileName>
<FileType>1</FileType>
<FilePath>..\implementation\motoreducteur.c</FilePath>
</File>
<File>
<FileName>rtc.c</FileName>
<FileType>1</FileType>
<FilePath>..\implementation\rtc.c</FilePath>
</File>
</Files> </Files>
</Group> </Group>
<Group> <Group>