本帖最后由 mars4zhu 于 2014-11-6 09:08 编辑
1.1. 智能感应调光LED的原理系统利用光敏电阻组成光线强度床安琪,光线照射在光敏电阻上,则呈现的电阻跟光线基本呈正相关,光线越强则电阻较低。而如果光线越暗,则光敏电阻增大。对应的ADC采样值随之变化,此时设置PWM控制的LED的占空比跟随ADC的采样值变化,则实现LED的自动调光。
2 硬件结构根据前面所述的系统设计原理和功能要求,设计硬件连接:
模拟量输入,用ADC采集。光敏电阻上的电压,检测激光光照与否
PWM输出,通过一个功放驱动板,驱动输出LED。这里采用ULN2003A的驱动板。
- int main(void)
- {
- /*!< At this stage the microcontroller clock setting is already configured,
- this is done through SystemInit() function which is called from startup
- file (startup_stm32l0xx.s) before to branch to application main.
- To reconfigure the default setting of SystemInit() function, refer to
- system_stm32l0xx.c file
- */
- SysTick_Config(2000); /* 1ms config */
- SystemClock_Config();
- ConfigureGPIO();
- if (error != 0)
- {
- while(1) /* endless loop */
- {
- }
- }
- SysTick->CTRL = 0; /* Disable SysTick */
- ConfigureExternalIT();
- ConfigureGPIOforADC();
- SetClockForADC();
- ConfigureADC();
- CalibrateADC();
- EnableADC();
- CurrentChannel = 0; /* Initializes the CurrentChannel */
-
- ADC_array[2] = 4096;
-
- ADC1->CR |= ADC_CR_ADSTART; /* start the ADC conversions */
-
-
- ConfigureTIMxAsPWM_EdgeAligned();
-
- while (error == 0) /* loop till no unrecoverable error, should never be exited */
- {
- if (ADC_array[2] > 2000) {
- GPIOA->BSRR = (1<<5); /* Switch on red led to report a resume of the conversion */
- }
- else {
- GPIOA->BRR = (1<<5); /* Switch off red led to stop reporting the resume */
- }
-
- TIMx->CCR1 = 4096 - ADC_array[2];
- }
- DisableADC();
- SysTick_Config(16000); /* 1ms config */
- while (1) /* Infinite loop */
- {
- }
- }
复制代码
main.rar
(6.58 KB, 下载次数: 19)