![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
fork
Fork of LG by
MCPWM.c@214:4c70e452c491, 2017-08-16 (annotated)
- Committer:
- Kovalev_D
- Date:
- Wed Aug 16 09:00:25 2017 +0000
- Revision:
- 214:4c70e452c491
fdxcz
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kovalev_D | 214:4c70e452c491 | 1 | #include "stdlib.h" |
Kovalev_D | 214:4c70e452c491 | 2 | //#include "math.h" |
Kovalev_D | 214:4c70e452c491 | 3 | #include "LPC17xx.h" |
Kovalev_D | 214:4c70e452c491 | 4 | #include "Global.h" |
Kovalev_D | 214:4c70e452c491 | 5 | unsigned int fhz=350,T_vib=5,T_vib_1=10000,T_vib_2=100000,AmpP=3000,err; |
Kovalev_D | 214:4c70e452c491 | 6 | float T_vibP=10000, F_vib=258000; |
Kovalev_D | 214:4c70e452c491 | 7 | |
Kovalev_D | 214:4c70e452c491 | 8 | |
Kovalev_D | 214:4c70e452c491 | 9 | void InitMCPWM(void) |
Kovalev_D | 214:4c70e452c491 | 10 | { |
Kovalev_D | 214:4c70e452c491 | 11 | // Power up MCPWM |
Kovalev_D | 214:4c70e452c491 | 12 | |
Kovalev_D | 214:4c70e452c491 | 13 | LPC_SC->PCONP |= 1<<17; |
Kovalev_D | 214:4c70e452c491 | 14 | LPC_SC->PCLKSEL1 |= 1<<30; |
Kovalev_D | 214:4c70e452c491 | 15 | |
Kovalev_D | 214:4c70e452c491 | 16 | |
Kovalev_D | 214:4c70e452c491 | 17 | // Configuring P1.25 and P1.28 as MC1A and MC2A |
Kovalev_D | 214:4c70e452c491 | 18 | LPC_PINCON->PINSEL3 |= (1<<18) | (1<<24); |
Kovalev_D | 214:4c70e452c491 | 19 | LPC_MCPWM->CON_SET |= 0x40070707; |
Kovalev_D | 214:4c70e452c491 | 20 | LPC_MCPWM->CAPCON_SET |= 0x1c0000; |
Kovalev_D | 214:4c70e452c491 | 21 | |
Kovalev_D | 214:4c70e452c491 | 22 | // Start MCPWM channels 1 and 2 and POLA = 1 |
Kovalev_D | 214:4c70e452c491 | 23 | LPC_MCPWM->CON_CLR = 0xffffffff; |
Kovalev_D | 214:4c70e452c491 | 24 | LPC_MCPWM->CON_SET = (0<<10) | (1<<18) | (1<<16) | (1<<8) | (1<<9) | (1<<17); |
Kovalev_D | 214:4c70e452c491 | 25 | } |
Kovalev_D | 214:4c70e452c491 | 26 | |
Kovalev_D | 214:4c70e452c491 | 27 | void ReVib(void) |
Kovalev_D | 214:4c70e452c491 | 28 | { Gyro.AmpPer = ((Gyro.Amp*100)>>17); |
Kovalev_D | 214:4c70e452c491 | 29 | |
Kovalev_D | 214:4c70e452c491 | 30 | F_vib=(103200000<<5)/((Gyro.Frq)>>10);//периуд вибро. |
Kovalev_D | 214:4c70e452c491 | 31 | T_vibP = F_vib/10000; |
Kovalev_D | 214:4c70e452c491 | 32 | |
Kovalev_D | 214:4c70e452c491 | 33 | LPC_MCPWM->LIM1 = F_vib; |
Kovalev_D | 214:4c70e452c491 | 34 | LPC_MCPWM->LIM2 = F_vib; |
Kovalev_D | 214:4c70e452c491 | 35 | } |