début pwm
This commit is contained in:
parent
cd6ee1fa99
commit
f17dd1744f
5 changed files with 69 additions and 6 deletions
|
@ -31,6 +31,12 @@ void MyTimer_ActiveIT (TIM_TypeDef * Timer, char Prio, void (*IT_function)(void)
|
|||
|
||||
#define MyTimer_Base_Start(Timer) (Timer->CR1 |= 0x01)
|
||||
#define MyTimer_Base_Stop(Timer) (Timer->CR1 &= ~0x01)
|
||||
#define PWM_output 0x00
|
||||
#define PWM_inputTI1 0x01
|
||||
#define PWM_inputTI2 0x10
|
||||
#define PWM_inputTRC 0x11
|
||||
|
||||
void MyPWM_init ( TIM_TypeDef * Timer,char Channel);
|
||||
void MyPWM_Duty (TIM_TypeDef * Timer,char Channel, unsigned short CRR );
|
||||
|
||||
#endif
|
||||
|
|
|
@ -29,6 +29,60 @@ void MyTimer_Base_Init ( MyTimer_Struct_TypeDef * Timer)
|
|||
Timer->Timer->PSC=Timer->PSC;
|
||||
}
|
||||
|
||||
void MyPWM_init ( TIM_TypeDef * Timer,char Channel)
|
||||
{
|
||||
if(Channel==1)
|
||||
{
|
||||
Timer->CCMR1&=~0x00FF;
|
||||
Timer->CCMR1|=0x11<<5;
|
||||
Timer->CCMR1&=~0x000F;
|
||||
|
||||
}
|
||||
if(Channel==2)
|
||||
{
|
||||
Timer->CCMR1&=~0xFF00;
|
||||
Timer->CCMR1|=0x11<<12;
|
||||
Timer->CCMR1&=~0x0F00;
|
||||
|
||||
}
|
||||
if(Channel==3)
|
||||
{
|
||||
Timer->CCMR2&=~0x00FF;
|
||||
Timer->CCMR2|=0x11<<5;
|
||||
Timer->CCMR2&=~0x000F;
|
||||
|
||||
}
|
||||
if(Channel==4)
|
||||
{
|
||||
Timer->CCMR2&=~0xFF00;
|
||||
Timer->CCMR2|=0x11<<12;
|
||||
Timer->CCMR2&=~0x0F00;
|
||||
|
||||
}
|
||||
}
|
||||
void MyPWM_Duty (TIM_TypeDef * Timer,char Channel, unsigned short CRR )
|
||||
{
|
||||
|
||||
|
||||
if(Channel==1)
|
||||
{
|
||||
Timer->CCR1=CRR;
|
||||
}
|
||||
if(Channel==2)
|
||||
{
|
||||
Timer->CCR2=CRR;
|
||||
}
|
||||
if(Channel==3)
|
||||
{
|
||||
Timer->CCR3=CRR;
|
||||
|
||||
}
|
||||
if(Channel==4)
|
||||
{
|
||||
Timer->CCR4=CRR;
|
||||
}
|
||||
|
||||
}
|
||||
void MyTimer_ActiveIT (TIM_TypeDef * Timer, char Prio, void (*IT_function)(void))
|
||||
{
|
||||
int num_tim;
|
||||
|
|
|
@ -23,6 +23,9 @@ int main ( void )
|
|||
MyTimer_Base_Init(&timer2);
|
||||
MyTimer_ActiveIT(timer2.Timer,1, &Mafonction_IT);
|
||||
MyTimer_Base_Start(timer2.Timer);
|
||||
MyPWM_init (TIM2,1);
|
||||
MyPWM_Duty (TIM2,1, 10000);
|
||||
|
||||
|
||||
while(1)
|
||||
{
|
||||
|
|
|
@ -103,7 +103,7 @@
|
|||
<bEvRecOn>1</bEvRecOn>
|
||||
<bSchkAxf>0</bSchkAxf>
|
||||
<bTchkAxf>0</bTchkAxf>
|
||||
<nTsel>0</nTsel>
|
||||
<nTsel>6</nTsel>
|
||||
<sDll></sDll>
|
||||
<sDllPa></sDllPa>
|
||||
<sDlgDll></sDlgDll>
|
||||
|
@ -114,7 +114,7 @@
|
|||
<tDlgDll></tDlgDll>
|
||||
<tDlgPa></tDlgPa>
|
||||
<tIfile></tIfile>
|
||||
<pMon>BIN\UL2CM3.DLL</pMon>
|
||||
<pMon>STLink\ST-LINKIII-KEIL_SWO.dll</pMon>
|
||||
</DebugOpt>
|
||||
<TargetDriverDllRegistry>
|
||||
<SetRegEntry>
|
||||
|
@ -410,7 +410,7 @@
|
|||
<GroupNumber>1</GroupNumber>
|
||||
<FileNumber>2</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\DRIVERS\Src\GPIO.c</PathWithFileName>
|
||||
|
|
|
@ -134,11 +134,11 @@
|
|||
<RunIndependent>0</RunIndependent>
|
||||
<UpdateFlashBeforeDebugging>1</UpdateFlashBeforeDebugging>
|
||||
<Capability>1</Capability>
|
||||
<DriverSelection>-1</DriverSelection>
|
||||
<DriverSelection>4096</DriverSelection>
|
||||
</Flash1>
|
||||
<bUseTDR>1</bUseTDR>
|
||||
<Flash2>BIN\UL2CM3.DLL</Flash2>
|
||||
<Flash3></Flash3>
|
||||
<Flash3>"" ()</Flash3>
|
||||
<Flash4></Flash4>
|
||||
<pFcarmOut></pFcarmOut>
|
||||
<pFcarmGrp></pFcarmGrp>
|
||||
|
@ -339,7 +339,7 @@
|
|||
<MiscControls></MiscControls>
|
||||
<Define></Define>
|
||||
<Undefine></Undefine>
|
||||
<IncludePath>.\Includes;..\Drivers\Inc</IncludePath>
|
||||
<IncludePath>..\Drivers\Inc</IncludePath>
|
||||
</VariousControls>
|
||||
</Cads>
|
||||
<Aads>
|
||||
|
|
Loading…
Reference in a new issue