2708 views|8 replies

1127

Posts

17

Resources
The OP
 

[National Technology N32G457 Review] 4. PWM and breathing light test [Copy link]

 

My related posts:

[National Technology N32G457 Review] 1. Data Preparation

[National Technology N32G457 Review] 2. Unboxing + Lighting

[National Technology N32G457 Review] III. ADC and Serial Port Function Test


PWM initialization code

LED3 flashes at a frequency of 100HZ, with light and dark gradually changing to create a breathing effect.


void PwmInit(void)		//PWM定时器初始化	
{
	
	//开启T1时钟 + AFIO
    RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_TIM1|RCC_APB2_PERIPH_AFIO,ENABLE);
	
	//GPIO引脚复用
	//PA8/TIM1_CH1/LED1
    GPIO_InitType gpio;
    gpio.Pin=GPIO_PIN_8;       
    gpio.GPIO_Mode=GPIO_Mode_AF_PP;
    gpio.GPIO_Speed=GPIO_Speed_50MHz;
	GPIO_InitPeripheral(GPIOA,&gpio);
	//tim1部分引脚映射
	GPIO_ConfigPinRemap(GPIO_PART1_RMP_TIM1,ENABLE);

	
	//tim1定时器相关
	//144M/14400=10KHZ  / 10000 =1HZ
	//	/100=100hz
	TIM_TimeBaseInitType tim_base;
    tim_base.Prescaler = 14400;
    tim_base.CntMode   = TIM_CNT_MODE_UP;
    tim_base.Period    = 100;
    tim_base.ClkDiv    = 0;//TIM_CLK_DIV4;
    tim_base.RepetCnt  = 0;	
	TIM_InitTimeBase(TIM1, &tim_base);
	
	OCInitType tim;	
    tim.OcMode       = TIM_OCMODE_PWM1;
    tim.OutputState  = TIM_OUTPUT_STATE_ENABLE;
    tim.OutputNState = TIM_OUTPUT_NSTATE_ENABLE;
    tim.Pulse        = 5000;		//占空比
    tim.OcPolarity   = TIM_OC_POLARITY_LOW;
    tim.OcNPolarity  = TIM_OCN_POLARITY_HIGH;
    tim.OcIdleState  = TIM_OC_IDLE_STATE_SET;
    tim.OcNIdleState = TIM_OC_IDLE_STATE_RESET;
	
	TIM_InitOc1(TIM1,&tim);
	
	TIM_Enable(TIM1,ENABLE);
	
	TIM_EnableCtrlPwmOutputs(TIM1,ENABLE);
	
}

Main running code, calling this function once every 10ms, looping once every 1 second

void Task2(void){		//呼吸灯	10ms
	static uint16_t count=0;
	static int dir=0;
	
	TIM_SetCmp1(TIM1,count);
	if(dir==0){
		count++;
		if(count>100){
			dir=!dir;
		}
	}else{
		count--;
		if(count>65000){
			count=0;
			dir=!dir;
		}		
	}
}

Related references

#include "n32g45x.h"
#include "n32g45x_gpio.h"
#include "bsp.h"
#include <n32g45x_tim.h>

Disclaimer: All my posts are original and hand-typed by me, not something that can be done by just downloading a DEMO and running it.

Video effects:

Upload on the second floor

This post is from Domestic Chip Exchange

Latest reply

Breathing light is good I have used both op amps and 555. I think PWM might work better.   Details Published on 2022-1-27 13:54
 
 

1127

Posts

17

Resources
2
 


Operation effect

I am preparing to go back to my hometown, and will review the rest after the New Year.

This post is from Domestic Chip Exchange

Comments

Of course, you can bring it back to your hometown!  Details Published on 2022-1-25 13:31
 
 
 

6818

Posts

11

Resources
3
 
fxyc87 posted on 2022-1-25 12:16 Running effect I am preparing to go back to my hometown, and the rest will be evaluated after the new year.

Sure, you can bring it back to your hometown!

This post is from Domestic Chip Exchange
 
 
 

1412

Posts

3

Resources
4
 

It is better to test it after the New Year. Going home to spend time with your family is the right thing to do.

This post is from Domestic Chip Exchange
Personal signature

没有什么不可以,我就是我,不一样的烟火! 

 
 
 

2w

Posts

74

Resources
5
 

I appreciate the serious attitude of the host:)

This post is from Domestic Chip Exchange
Add and join groups EEWorld service account EEWorld subscription account Automotive development circle
Personal signature

加油!在电子行业默默贡献自己的力量!:)

 
 
 

2w

Posts

74

Resources
6
 

Happy New Year~~

This post is from Domestic Chip Exchange
Add and join groups EEWorld service account EEWorld subscription account Automotive development circle

Comments

Thanks.  Details Published on 2022-1-26 12:12
Personal signature

加油!在电子行业默默贡献自己的力量!:)

 
 
 

1127

Posts

17

Resources
7
 

Thanks.

This post is from Domestic Chip Exchange
 
 
 

1573

Posts

0

Resources
8
 

Breathing light is good

I have used both op amps and 555.

I think PWM might work better.

This post is from Domestic Chip Exchange

Comments

It is PWM. The PWM duty cycle is modified every 10mS.  Details Published on 2022-2-1 13:06
 
 
 

1127

Posts

17

Resources
9
 
se7ens posted on 2022-1-27 13:54 The breathing light is good. I have used op amps and 555 to adjust it. I feel that PWM may have a better effect

It is PWM. The PWM duty cycle is modified every 10mS.

This post is from Domestic Chip Exchange
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Featured Posts
Selected answers to basic FPGA questions

This post collects some representative questions raised by netizens in this forum and has been solved! Many new FPGAers ...

Does anyone know what circuit this is and what function it has?

469794 It feels like peak detection, but it doesn't... What kind of circuit is this and what function can it achieve?

【DIY Creative LED V2】Complete production steps

This post was last edited by dcexpert on 2020-10-21 15:09 The production of V2 is much simpler than V1. If everything g ...

[Runhe Neptune Review] Five PWM

PWM: Pulse Width Modulation It is to periodically control the time (duty cycle) of IO pulling high and low to control th ...

36 "Ten Thousand Miles" Raspberry Pi Car——ROS Learning (VSCode to Implement Hello World)

It is very convenient to run ROS projects in VSCode. In this section, we use ROS to write and run the "Hello world" pro ...

[RVB2601 Creative Application Development] 6. Upload environmental sensor data to Alibaba Cloud Server

This post was last edited by anni_zzg on 2022-6-2 11:14 By using the RVB2601 development board to upload the temperatur ...

40 "Millions" of Raspberry Pi Cars - ROS Learning (C Language Programming to Control the Turtle)

This post was last edited by lb8820265 on 2022-11-1 14:52 In the previous section, we introduced how to run the "tu ...

[Beineng cost-effective ATSAMD51 evaluation board] Benchmark performance test 5: coremark test

Preface According to the manual description, the coremark score is 403, so we actually test it. 661714 process Add code ...

[DIY] Logitech K260 keyboard set modified lithium battery power supply and added working instructions

This post was last edited by dcexpert on 2023-1-24 18:22 During the Chinese New Year holiday, I don't have much to do, ...

Huawei's Hongmeng will replace Apple's iOS to become the second largest smartphone operating system in the domestic market. What system are you using?

According to foreign media reports, since Huawei's self-developed operating system HarmonyOS was put into use, its user ...

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list