ADC begin
This commit is contained in:
parent
541f57dbef
commit
6d91d3c4ae
6 changed files with 29 additions and 76 deletions
|
@ -14,5 +14,7 @@ typedef struct
|
|||
void MyTimer_Base_Init(MyTimer_Struct_TypeDef * Timer);
|
||||
void MyTimer_Base_Start(TIM_TypeDef * Timer);
|
||||
void MyTimer_Base_Stop(TIM_TypeDef * Timer);
|
||||
void MyTimer_PWM( MyTimer_Struct_TypeDef * Timer, uint16_t cycle);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -4,11 +4,15 @@ void MyADC_Base_Init(MyADC_Struct_TypeDef * ADC){
|
|||
RCC->CFGR |= RCC_CFGR_ADCPRE_DIV6; //Division par 6 de la clock (72MHz) pour l'ADC (14MHz max)
|
||||
if(ADC->ADC == ADC1){
|
||||
RCC->APB2ENR |= RCC_APB2ENR_ADC1EN; //Enable Clock ADC1
|
||||
ADC1->CR2= ADC_CR2_ADON; //Enable ADC1
|
||||
ADC1->CR2 |= ADC_CR2_ADON; //Enable ADC1
|
||||
ADC1->SQR1&= ADC_SQR1_L;
|
||||
ADC1->SQR3|= 8;
|
||||
|
||||
}else{
|
||||
}else if(ADC->ADC == ADC2){
|
||||
RCC->APB2ENR |= RCC_APB2ENR_ADC2EN; //Enable Clock ADC1
|
||||
ADC1->CR2 |= ADC_CR2_ADON; //Enable ADC1
|
||||
ADC1->SQR1&= ADC_SQR1_L;
|
||||
ADC1->SQR3|= 8;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,3 +36,11 @@ void MyTimer_Base_Stop(TIM_TypeDef * Timer){
|
|||
}
|
||||
|
||||
|
||||
//------------------------PWM----------------------//
|
||||
void MyTimer_PWM( MyTimer_Struct_TypeDef * Timer, uint16_t cycle){
|
||||
Timer->Timer->CCMR1 &= ~TIM_CCMR1_OC1M_0; //Configuration du canal CH1
|
||||
Timer->Timer->CCMR1 |= TIM_CCMR1_OC1M_1| TIM_CCMR1_OC1M_2; // Ajouter 110 aux bits OC1M (registre CCMR1)
|
||||
|
||||
Timer->Timer->CCER |= TIM_CCER_CC1E; // Canal CH1 validé par bit CC1E (registre CCER)
|
||||
Timer->Timer->CCR1 = (cycle * Timer->ARR) / 100; // Fixer la durée à 20%
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@
|
|||
<OPTFL>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<IsCurrentTarget>1</IsCurrentTarget>
|
||||
<IsCurrentTarget>0</IsCurrentTarget>
|
||||
</OPTFL>
|
||||
<CpuCode>18</CpuCode>
|
||||
<DebugOpt>
|
||||
|
@ -125,7 +125,7 @@
|
|||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
<Key>DLGDARM</Key>
|
||||
<Name>(1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=297,604,718,1031,0)(121=-1,-1,-1,-1,0)(122=546,289,967,716,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=-1,-1,-1,-1,0)(131=997,343,1591,1094,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(234=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0)</Name>
|
||||
<Name>(1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=297,604,718,1031,0)(121=-1,-1,-1,-1,0)(122=546,289,967,716,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=-1,-1,-1,-1,0)(131=708,449,1302,1200,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(234=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0)</Name>
|
||||
</SetRegEntry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
|
@ -164,7 +164,7 @@
|
|||
<AscS3>0</AscS3>
|
||||
<aSer3>0</aSer3>
|
||||
<eProf>0</eProf>
|
||||
<aLa>1</aLa>
|
||||
<aLa>0</aLa>
|
||||
<aPa1>0</aPa1>
|
||||
<AscS4>0</AscS4>
|
||||
<aSer4>0</aSer4>
|
||||
|
@ -263,7 +263,7 @@
|
|||
<OPTFL>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<IsCurrentTarget>0</IsCurrentTarget>
|
||||
<IsCurrentTarget>1</IsCurrentTarget>
|
||||
</OPTFL>
|
||||
<CpuCode>18</CpuCode>
|
||||
<DebugOpt>
|
||||
|
@ -422,42 +422,6 @@
|
|||
<File>
|
||||
<GroupNumber>1</GroupNumber>
|
||||
<FileNumber>3</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\Drivers\Include\Driver_GPIO.h</PathWithFileName>
|
||||
<FilenameWithoutPath>Driver_GPIO.h</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>1</GroupNumber>
|
||||
<FileNumber>4</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\Drivers\Include\Driver_Timer.h</PathWithFileName>
|
||||
<FilenameWithoutPath>Driver_Timer.h</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>1</GroupNumber>
|
||||
<FileNumber>5</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\Drivers\Include\Driver_ADC.h</PathWithFileName>
|
||||
<FilenameWithoutPath>Driver_ADC.h</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>1</GroupNumber>
|
||||
<FileNumber>6</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -477,9 +441,9 @@
|
|||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>7</FileNumber>
|
||||
<FileNumber>4</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>.\Sources\Main.c</PathWithFileName>
|
||||
|
|
|
@ -393,21 +393,6 @@
|
|||
<FileType>1</FileType>
|
||||
<FilePath>..\Drivers\Sources\Driver_Timer.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>Driver_GPIO.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\Drivers\Include\Driver_GPIO.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>Driver_Timer.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\Drivers\Include\Driver_Timer.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>Driver_ADC.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\Drivers\Include\Driver_ADC.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>Driver_ADC.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
|
@ -820,21 +805,6 @@
|
|||
<FileType>1</FileType>
|
||||
<FilePath>..\Drivers\Sources\Driver_Timer.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>Driver_GPIO.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\Drivers\Include\Driver_GPIO.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>Driver_Timer.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\Drivers\Include\Driver_Timer.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>Driver_ADC.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\Drivers\Include\Driver_ADC.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>Driver_ADC.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
|
|
|
@ -6,8 +6,8 @@ int main (void){
|
|||
MyTimer_Struct_TypeDef TIM500ms;
|
||||
//Init Timer 2 et Test
|
||||
TIM500ms.Timer = TIM2;
|
||||
TIM500ms.PSC = 0xD2F0; // =0.5ms(calculé à partir de la fréquence du micro)
|
||||
TIM500ms.ARR = 1000;
|
||||
TIM500ms.PSC = 7200; // =0.5ms(calculé à partir de la fréquence du micro)
|
||||
TIM500ms.ARR = 5000;
|
||||
MyTimer_Base_Init(&TIM500ms);
|
||||
|
||||
TIM2->DIER |= 1<< 0 ; //INTERRUPTION PERIPH
|
||||
|
@ -16,7 +16,12 @@ int main (void){
|
|||
NVIC->IP[TIM2_IRQn] = 2<< 4 ;
|
||||
|
||||
MyTimer_Base_Start(TIM500ms.Timer);
|
||||
|
||||
MyTimer_PWM(&TIM500ms, 50);
|
||||
|
||||
|
||||
//Boucle infinie de la réponse de la LED à l'état BP
|
||||
|
||||
while(1){
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue