首页 > 其他分享 >泰凌微8258学习日记-5:五路PWM调光

泰凌微8258学习日记-5:五路PWM调光

时间:2024-07-24 10:58:27浏览次数:16  
标签:调光 led val light 8258 泰凌微 PWM 256 lum

        为了追求更加多样的色彩变化,由RGB三路PWM调光衍生出RGBWY五路PWM调光。与RGB一样,都是要配置相应的PWM,其实非常简单,如果你不需要用到手机APP或者tl-ble-phone-mesh来控制的话,那么你只需要配置好五个PWM,然后照着官方给的SDK代码,照葫芦画瓢地写一个light-adjust-CT函数就行了,然后在main-loop函数中调用一下,设置自己喜欢的比例和亮度,就ok了,很简单的,不过自己搞有一点点烦人,emm我直接放我的出来吧,可以抄作业。(●'◡'●)!!

//放在light.H文件
//配置自己硬件上的对应引脚
#if(PCBA_8258_SEL == PCBA_8258_DONGLE_48PIN)
#define PWM_R       GPIO_PWMXX	//red
#define PWM_G       GPIO_PWMXX	//green
#define PWM_B       GPIO_PWMXX	//blue
#define PWM_W       GPIO_PWMXX	//white
#define PWM_Y       GPIO_PWMXX	//yellow


//PWM宏定义
#define PWM_FUNC_R  AS_PWM  // AS_PWM_SECOND
#define PWM_FUNC_G  AS_PWM  // AS_PWM_SECOND
#define PWM_FUNC_B  AS_PWM  // AS_PWM_SECOND
#define PWM_FUNC_W  AS_PWM  // AS_PWM_SECOND
#define PWM_FUNC_Y  AS_PWM  // AS_PWM_SECOND

#define PWMID_R     (GET_PWMID(PWM_R, PWM_FUNC_R))
#define PWMID_G     (GET_PWMID(PWM_G, PWM_FUNC_G))
#define PWMID_B     (GET_PWMID(PWM_B, PWM_FUNC_B))
#define PWMID_W     (GET_PWMID(PWM_W, PWM_FUNC_W))
#define PWMID_Y    (GET_PWMID(PWM_WW, PWM_FUNC_WW))

#define PWM_INV_R   (GET_PWM_INVERT_VAL(PWM_R, PWM_FUNC_R))
#define PWM_INV_G   (GET_PWM_INVERT_VAL(PWM_G, PWM_FUNC_G))
#define PWM_INV_B   (GET_PWM_INVERT_VAL(PWM_B, PWM_FUNC_B))
#define PWM_INV_W   (GET_PWM_INVERT_VAL(PWM_W, PWM_FUNC_W))
#define PWM_INV_Y   (GET_PWM_INVERT_VAL(PWM_Y, PWM_FUNC_Y))


//放在main_light.c文件
//这里用来设置最大占空比,如果你的板子开了五路PWM导致功率过大可以改动一下
///没有就不用理会///
//#if 0
//const u16 rgb_lumen_map[101] = {
//  0,2*256+128,2*256+192,3*256,3*256+128,4*256,4*256+128,5*256,5*256+128,6*256,  7*256,
//      8*256,  9*256, 10*256, 11*256, 12*256, 13*256, 14*256, 15*256, 16*256, 17*256,
//    18*256, 19*256, 20*256, 21*256, 22*256, 24*256, 25*256, 26*256, 27*256, 28*256,
//     29*256, 30*256, 31*256, 32*256, 33*256, 34*256, 35*256, 36*256, 37*256, 38*256,
//   39*256, 40*256, 41*256, 42*256, 43*256, 44*256, 45*256, 46*256, 47*256, 48*256,
//    49*256, 50*256, 51*256, 52*256, 53*256, 54*256, 55*256, 56*256,57*256,58*256,
//    59*256,60*256,61*256,62*256,63*256,64*256,65*256,66*256,67*256,68*256,
//    69*256,70*256,71*256,72*256,73*256,74*256,75*256,76*256,78*256,80*256,
//    82*256,84*256,86*256,88*256,90*256,92*256,94*256,96*256,98*256,100*256,
//   102*256,104*256,106*256,108*256,110*256,112*256,114*256,116*256,118*256,120*256,// must less or equal than (255*256)
//};
//    const u16 cct_lumen_map[101] = {
//      0,2*256+128,2*256+192,3*256,3*256+128,4*256,4*256+128,5*256,5*256+128,6*256,  7*256,
//      8*256,  9*256, 10*256, 11*256, 12*256, 13*256, 14*256, 15*256, 16*256, 17*256,
//     18*256, 19*256, 20*256, 21*256, 22*256, 24*256, 25*256, 26*256, 27*256, 28*256,
//     29*256, 30*256, 31*256, 32*256, 33*256, 34*256, 35*256, 36*256, 37*256, 38*256,
//     39*256, 40*256, 41*256, 42*256, 43*256, 44*256, 45*256, 46*256, 47*256, 48*256,
//     49*256, 50*256, 51*256, 52*256, 53*256, 54*256, 55*256, 56*256,57*256,58*256,
//    59*256,60*256,61*256,62*256,63*256,64*256,65*256,66*256,67*256,68*256,
//    69*256,70*256,71*256,72*256,73*256,74*256,75*256,76*256,78*256,80*256,
//    82*256,84*256,86*256,88*256,90*256,92*256,94*256,96*256,98*256,100*256,
//    102*256,104*256,106*256,108*256,110*256,112*256,114*256,116*256,118*256,120*256,// must less or equal than (255*256)
//};
//#else
// 0-100%  (pwm's value index: this is pwm compare value, and the pwm cycle is 255*256)
//	const u16 rgb_lumen_map[101] = {//********************************************************************************************************//
//	0,		5,	   50,	  130,	1*256,	2*256,	3*256,	4*256,	5*256,	6*256,	7*256,
//		8*256,	9*256, 10*256, 11*256, 12*256, 13*256, 14*256, 15*256, 16*256, 17*256,
//	   18*256, 19*256, 21*256, 23*256, 25*256, 27*256, 29*256, 31*256, 33*256, 35*256,
//	   37*256, 39*256, 41*256, 43*256, 45*256, 47*256, 49*256, 51*256, 53*256, 55*256,
//	   57*256, 59*256, 61*256, 63*256, 65*256, 67*256, 69*256, 71*256, 73*256, 75*256,
//	   78*256, 81*256, 84*256, 87*256, 90*256, 93*256, 96*256, 99*256,102*256,105*256,
//	  108*256,111*256,114*256,117*256,120*256,123*256,126*256,129*256,132*256,135*256,
//	  138*256,141*256,144*256,147*256,150*256,154*256,158*256,162*256,166*256,170*256,
//	  174*256,178*256,182*256,186*256,190*256,194*256,198*256,202*256,206*256,210*256,
//	  214*256,218*256,222*256,226*256,230*256,235*256,240*256,245*256,250*256,255*256,// must less or equal than (255*256)
//
//	};
//const u16 cct_lumen_map[101] = {
//  0,      5,     50,    130,  1*256,  2*256,  3*256,  4*256,  5*256,  6*256,  7*256,
//      8*256,  9*256, 10*256, 11*256, 12*256, 13*256, 14*256, 15*256, 16*256, 17*256,
//     18*256, 19*256, 21*256, 23*256, 25*256, 27*256, 29*256, 31*256, 33*256, 35*256,
//     37*256, 39*256, 41*256, 43*256, 45*256, 47*256, 49*256, 51*256, 53*256, 55*256,
//     57*256, 59*256, 61*256, 63*256, 65*256, 67*256, 69*256, 71*256, 73*256, 75*256,
//    78*256, 81*256, 84*256, 87*256, 90*256, 93*256, 96*256, 99*256,102*256,105*256,
//    108*256,111*256,114*256,117*256,120*256,123*256,126*256,129*256,132*256,135*256,
//    138*256,141*256,144*256,147*256,150*256,154*256,158*256,162*256,166*256,170*256,
//    174*256,178*256,182*256,186*256,190*256,194*256,198*256,202*256,206*256,210*256,
//    214*256,218*256,222*256,226*256,230*256,235*256,240*256,245*256,250*256,255*256,// must less or equal than (255*256)
//};
设置RGBWY各个通道///
void light_adjust_R(u8 val, u8 lum){
    pwm_set_lum (PWMID_R, get_pwm_cmp(val, lum), PWM_INV_R);
}

void light_adjust_G(u8 val, u8 lum){
    pwm_set_lum (PWMID_G, get_pwm_cmp(val, lum), PWM_INV_G);
}

void light_adjust_B(u8 val, u8 lum){
    pwm_set_lum (PWMID_B, get_pwm_cmp(val, lum), PWM_INV_B);
}

void light_adjust_W(u8 val, u8 lum){
    pwm_set_lum (PWMID_W, get_pwm_cmp(val, lum), PWM_INV_W);
}

void light_adjust_Y(u8 val, u8 lum){
    pwm_set_lum (PWMID_Y, get_pwm_cmp(val, lum), PWM_INV_Y);
}
定义RGB调光函数
void light_adjust_RGB_hw(u8 val_R, u8 val_G, u8 val_B, u8 lum){
	light_adjust_R(val_R, lum);
	light_adjust_G(val_G, lum);
	light_adjust_B(val_B, lum);
}

void light_adjust_RGB(u8 val_R, u8 val_G, u8 val_B, u8 lum){
    #if LIGHT_ADJUST_STEP_EN
    light_onoff_step_init();
    #endif

	light_adjust_RGB_hw(val_R, val_G, val_B, lum);
}
/定义CT调光函数/这样写的原因主要是用来方便tl-ble-phone-mesh的调试
void light_adjust_CT( u8 val_W, u8 val_Y,u8 lum){

	light_adjust_W(val_W, lum);
	light_adjust_Y(val_Y, lum);
}
///或者可以这样写,这样可以一个函数全部设置到
//void light_adjust_CT_hw(u8 val_R, u8 val_G, u8 val_B,  u8 val_W, u8 val_Y,u8 lum){
//	light_adjust_R(val_R, lum);
//	light_adjust_G(val_G, lum);
//	light_adjust_B(val_B, lum);
//	light_adjust_W(val_W, lum);
//	light_adjust_Y(val_Y, lum);
//}

//void light_adjust_CT(u8 val_R, u8 val_G, u8 val_B, u8 val_W, u8 val_Y,u8 lum){
//    #if LIGHT_ADJUST_STEP_EN
//   light_onoff_step_init();
//    #endif
//
//    light_adjust_CT_hw(val_R, val_G, val_B, val_W, val_Y, lum);
//}
//设置引脚功能///
void	pwm_led_en (int id, int en)
{
	if (id == 0)
	{
		gpio_set_func (PWM_G, en ? PWM_FUNC_G : AS_GPIO);
	}
	else if (id == 1)
	{
		gpio_set_func (PWM_B, en ? PWM_FUNC_B : AS_GPIO);
	}
	else if (id == 2)
	{
		gpio_set_func (PWM_R, en ? PWM_FUNC_R : AS_GPIO);
	}
	else if (id == 3)
		{
			gpio_set_func (PWM_W, en ? PWM_FUNC_W : AS_GPIO);
		}
	else if (id == 4)
		{
			gpio_set_func (PWM_Y, en ? PWM_FUNC_Y : AS_GPIO);
		}
}


/这段我也不知道要不要改//
if( led_off || led_on  ){
                if (led_sel & BIT(0))
                {
                    light_adjust_G (LED_INDICATE_VAL * led_on, 100);
                }
                if (led_sel & BIT(1))
                {
                    light_adjust_B (LED_INDICATE_VAL * led_on, 100);
                }
                if (led_sel & BIT(2))
                {
                    light_adjust_R (LED_INDICATE_VAL * led_on, 100);
                }
                if (led_sel & BIT(3))
                {
                     light_adjust_W (LED_INDICATE_VAL * led_on, 100);
                }
                if (led_sel & BIT(4))
                {
                	light_adjust_Y (LED_INDICATE_VAL * led_on, 100);
                }
                if (led_sel & BIT(5))
                {
                }
            }
//这里主要是用来设置手机蓝牙APP或者电脑tl-ble-phone-mesh软件控制的//
//还有开启,关闭,设置亮度这些大家可以自己去看看//
if(params[0] == 1){		        //R
        		    led_val[0] = params[1];
        		    led_val[3] =0;
        		    led_val[4]=0;
        		    light_adjust_CT( led_val[3] ,led_val[4],led_lum);
                    light_adjust_R (led_val[0], led_lum);
        		}else if(params[0] == 2){		//G
        		    led_val[1] = params[1];
        		    led_val[3] =0;
        		    led_val[4]=0;
        		    light_adjust_CT( led_val[3] ,led_val[4],led_lum);
                    light_adjust_G (led_val[1], led_lum);
        		}else if(params[0] == 3){		//B
        		    led_val[2] = params[1];
        		    led_val[3] =0;
        		    led_val[4]=0;
        		    light_adjust_CT( led_val[3] ,led_val[4],led_lum);
                    light_adjust_B (led_val[2], led_lum);
        		}else if(params[0] == 4){		//RGB
        		    led_val[0] = params[1];
        		    led_val[1] = params[2];
        		    led_val[2] = params[3];
        		    led_val[3] =0;
        		    led_val[4]=0;
        		    light_adjust_CT( led_val[3] ,led_val[4],led_lum);
        		    light_adjust_RGB(led_val[0], led_val[1], led_val[2], led_lum);
}else if(params[0] == 5){		//CT
        			led_val[0] = 0;
                    		led_val[1] = 0;
                    		led_val[2] = 0;
                   		led_val[3] = params[4];
                    		led_val[4] = params[5];
        			light_adjust_CT(led_val[3], led_val[4], led_lum);
                  		light_adjust_RGB(led_val[0], led_val[1], led_val[2], led_lum);
//PWM口初始化/
void user_init_pwm(int retention_flag)
{
    pwm_set (PWMID_R, PMW_MAX_TICK, PWM_INV_R ? 0 : PMW_MAX_TICK);
    pwm_set (PWMID_G, PMW_MAX_TICK, PWM_INV_G ? 0 : PMW_MAX_TICK);
    pwm_set (PWMID_B, PMW_MAX_TICK, PWM_INV_B ? 0 : PMW_MAX_TICK);
    pwm_set (PWMID_W, PMW_MAX_TICK, PWM_INV_W ? 0 : PMW_MAX_TICK);
    pwm_set (PWMID_Y, PMW_MAX_TICK, PWM_INV_Y ? 0 : PMW_MAX_TICK);

    if(retention_flag){
        light_onoff(!light_off);
    }else{
		//retrieve lumen value
		light_lum_retrieve();
    }

    pwm_start (PWMID_R);
    pwm_start (PWMID_G);
    pwm_start (PWMID_B);
    pwm_start (PWMID_W);
    pwm_start (PWMID_Y);

    gpio_set_func (PWM_R, PWM_FUNC_R);
    gpio_set_func (PWM_G, PWM_FUNC_G);
    gpio_set_func (PWM_B, PWM_FUNC_B);
    gpio_set_func (PWM_W, PWM_FUNC_W);
    gpio_set_func (PWM_Y, PWM_FUNC_Y);

    pwm_io_input_disable();
}





        最后你只需要在main-loop中调用就行了。

gpio_write(LED_ON_OFF_Pin,1);
light_adjust_RGB(100,100,30,30);
light_adjust_CT(100,100,30);

好了,五路PWM调光就完成了!下期再见,ヾ(•ω•`)o88!

标签:调光,led,val,light,8258,泰凌微,PWM,256,lum
From: https://blog.csdn.net/weixin_52932392/article/details/140656793

相关文章

  • 【升压恒流FP7208应用热门市场摄影灯-LED车灯-太阳能方案】如何实现升压恒流一切五调
    方案一:【RGBWY单IC五路调光方案】远翔FP7208满足锂电池1-4串供电、PD电压5-20V供电升压恒流一切五调光调色方案,PWM内部转模拟调光,无频闪顾虑低亮无抖动无频闪RGBWY五路调光芯片FP7208,适用PD+电池供电近年来随着技术的不断进步,越来越多的产品需要适应小型化和便携......
  • 【PWM太阳能控制器调光方案】5V升24V 6A大电流无频闪PWM调光升压恒流LED驱动芯片FP720
    目前led灯带产品应用越来越广泛,在节能环保的社会快速发展驱动下,太阳能照明产品越来越多。但是现有技术中,有些空间狭小,又长又窄的环境空间不适用于现有的太阳能灯使用,现有技术中的太阳能灯照明效果不佳且不能够实现智能化照明;因此迫切地需要重新设计一款新的太阳能led灯带以......
  • 21-162、基于51单片机电子调光台灯可控硅PWM设计-CSDN
    21-162、基于51单片机电子调光台灯可控硅PWM设计-CSDN(1)通过电子调光台灯上的按键开关,实现电子调光台灯的开启与关闭操作;(2)通过电子调光台灯上的亮度增减按键,实现其8个档位的亮度切换控制(包含全亮和熄灭);(3)按下电子调光台灯的自动调光控制按键后,可根据环境光强度自动调节灯光亮度,......
  • 【80W大功率夜钓灯驱动芯片方案】12V电池供电,输出6V降压恒流驱动IC芯片FP7195 ,PWM内部
    【80W大功率夜钓灯驱动方案】12V降6V驱动芯片7195方案背景目前夜钓正在逐渐变得时尚起来,随着夜钓群体的年轻化,人们对于夜钓灯的审美要求也越来越高。夜钓灯作为夜间钓鱼的重点装备,不仅仅需要高质量的光源照亮水面浮漂,同时还需要融合一些其他功能,尽可能让夜钓者轻装上......
  • LED车灯150v降压恒流驱动芯片AP5191pwm精确调光过温保护
    产品描述AP5191是一款PWM工作模式,高效率、外围简单、内置功率MOS管,适用于4.5-150V输入的高精度降压LED恒流驱动芯片。输出最大功率150W,最大电流6A。AP5191可实现线性调光和PWM调光,线性调光脚有效电压范围0.55-2.6V.AP5191工作频率可以通过RT外部电阻编程来设定,同时内置抖频......
  • 【舞台灯方案】LED驱动恒流芯片pwm深度调光APS54085降压IC
    产品描述APS54085是一款PWM工作模式,高效率、外围简单、内置功率MOS管,适用于5-100V输入的高精度降压LED恒流驱动芯片。最大电流2.0A。APS54085可实现线性调光和PWM调光,线性调光有效电压范围0.52-2.55V.PWM调光频率范围100HZ-30KHZ。APS54085工作频率可以通过R......
  • 电动车摩托车灯DC-DC降压恒流芯片AP5170支持线性调光95%高效率IC
    产品描述AP5170是一款效率高,稳定可靠的LED灯恒流驱动控制芯片,内置高精度比较器,固定关断时间控制电路,恒流驱动电路等,特别适合大功率LED恒流驱动。AP5170采用ESOP8封装,散热片内置接SW脚,通过调节外置电流检测的电阻值来设置流过LED灯的电流,支持外加电压线性调光,最大电......
  • LED车灯驱动DC-DC降压恒流芯片AP5174高效率线性调光IC摩托车电动车手电筒
    5174产品描述AP5174是一款效率高,稳定可靠的LED灯恒流驱动控制芯片,内置高精度比较器,固定关断时间控制电路,恒流驱动电路等,特别适合大功率LED恒流驱动。AP5174采用ESOP8封装,散热片内置接SW脚,通过调节外置电流检测的电阻值来设置流过LED灯的电流,支持外加电压线性调光,最......
  • AP5199S LED平均电流型恒流驱动IC 0.01调光 景观舞台汽车灯驱动照明
    说明AP5199S是一款外围电路简单的多功能平均电流型LED恒流驱动器,适用于宽电压范围的非隔离式大功率恒流LED驱动领域。芯片PWM端口支持超小占空比的PWM调光,可响应60ns脉宽。为客户提供解决方案,限度地发挥灯具优势,以实现景观舞台灯高辉的调光效果,高辉调光。PWM端口为高......
  • APS54085 高辉度调光降压恒流芯片 PWM 线性调光 车灯IC
    产品描述 APS54085是一款PWM工作模式,简单、内置功率MOS管,适用于5-100V输入的高精度降压LED恒流驱动芯片。电流2.0A。APS54085可实现线性调光和PWM调光,线性调光有效电压范围0.52-2.55V.PWM调光频率范围100HZ-30KHZ。APS54085工作频率可以通过RT外部电阻编程来......