Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 2:f7adf14d2ef6, committed 2019-11-13
- Comitter:
- troshha
- Date:
- Wed Nov 13 10:29:10 2019 +0000
- Parent:
- 1:349234492517
- Commit message:
- 8
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Oct 30 11:05:17 2017 +0000
+++ b/main.cpp Wed Nov 13 10:29:10 2019 +0000
@@ -1,13 +1,14 @@
#include "mbed.h"
#include "stm32l0xx.h"
#include "stm32l0xx_hal_tim.h"
-
+
TIM_HandleTypeDef timer;
TIM_OC_InitTypeDef octim;
-int pulse = 1599;
-
+int pulse1 = 1600;
+int pulse2 = 1600;
+
DigitalOut led(LED1);
-
+
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef * handle)
{
GPIO_InitTypeDef gpio;
@@ -20,7 +21,7 @@
gpio.Alternate = GPIO_AF2_TIM2;
HAL_GPIO_Init(GPIOA, &gpio);
}
-
+
void InitTimer(void)
{
timer.Instance = TIM2;
@@ -30,50 +31,55 @@
timer.Init.Prescaler = (uint32_t)(SystemCoreClock / 3200000) - 1;
HAL_TIM_Base_Init(&timer);
HAL_TIM_PWM_Init(&timer);
-
+
octim.OCMode = TIM_OCMODE_PWM1;
octim.OCPolarity = TIM_OCPOLARITY_HIGH;
octim.OCFastMode = TIM_OCFAST_ENABLE;
- octim.Pulse = pulse;
-
+ octim.Pulse = pulse1;
+ octim.Pulse = pulse2;
+
+
HAL_TIM_PWM_ConfigChannel(&timer, &octim, TIM_CHANNEL_1);
HAL_TIM_PWM_Start(&timer, TIM_CHANNEL_1);
-
+
HAL_TIM_PWM_ConfigChannel(&timer, &octim, TIM_CHANNEL_2);
HAL_TIM_PWM_Start(&timer, TIM_CHANNEL_2);
}
-
+
int cur_pw = 500;
-
+
int main()
{
HAL_Init();
InitTimer();
int dir = 0;
- int count = 0;
-
+ int count1= 0;
+ int count2=0;
while(1) {
led = !led;
wait(0.05f);
- if (dir) {
- pulse -= 100;
- count--;
- if (count == 0) {
- dir = 0;
- }
- } else {
- pulse += 100;
- count++;
- if (count== 58) {
- dir = 1;
- }
+ if (!dir) {
+ if( pulse1<3900) {
+ pulse1+=100;
+ pulse2+=150;
+
+ }
+ if(pulse1>=3800){
+ pulse1+=100;
+ pulse2-=150;
+ }
+ if(pulse1 == 7300){
+ dir=1;
+ pulse1 = 0;
+ pulse2 = 0;
+ }
+
}
- octim.Pulse = pulse;
-
+ octim.Pulse = pulse1;
HAL_TIM_PWM_ConfigChannel(&timer, &octim, TIM_CHANNEL_1);
HAL_TIM_PWM_Start(&timer, TIM_CHANNEL_1);
-
+ octim.Pulse = pulse2;
HAL_TIM_PWM_ConfigChannel(&timer, &octim, TIM_CHANNEL_2);
HAL_TIM_PWM_Start(&timer, TIM_CHANNEL_2);
}
-}
+}
\ No newline at end of file