1.這個(gè)例子是用于光學(xué)器件中,MEMS加電壓調(diào)轉(zhuǎn)鏡角度的工程例子;
2.此例中,用到的技術(shù)點(diǎn)有: STM32F103C8, 國(guó)內(nèi)先進(jìn)的調(diào)壓芯片GP8401,PWM,FLASH,USART;
3.電路圖中有使用MP2359降壓芯片(12VL轉(zhuǎn)5V),與LTC3872升壓芯片(5V轉(zhuǎn)60V),GP8401的PAC應(yīng)用;
4.供學(xué)習(xí)參考,也推薦一下,上海益客電子;
電路原理圖如下:
51hei.png (103.15 KB, 下載次數(shù): 45)
下載附件
2022-5-26 20:31 上傳
單片機(jī)源程序如下:
- /********************************* MDK-ARM Project ****************************
- * Project Name:
- * Firmware Library version: V3.5.0
- * Author:
- * Date:
- * Brief: (mcu--64kflash,20kram,72mhz,26IO)
- * 使用內(nèi)部時(shí)鐘,64M, APB1_PCLK1=32M
- ******************************************************************************/
- //----------------------project header flie ------------------------------------------
- #include "stm32f10x.h"
- #include "userconfig.h"
- //#include <string.h>
- //************************* project functions *********************************
- /*******************************************************************************
- * Function Name : Variables_Init(void)
- * Description : This function .
- * Input : None
- * Output : None
- * Return : None
- * Attention : None
- *******************************************************************************/
- static void Variables_Init(void)
- { u8 cnt=0;
-
- GPIO_InitTypeDef GPIO_InitStructure;
-
- //IO口控制MEMS切換的端口初始化
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_12;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- GPIO_ResetBits(GPIOA,GPIO_Pin_6|GPIO_Pin_12);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0| GPIO_Pin_1;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- GPIO_ResetBits(GPIOB,GPIO_Pin_0|GPIO_Pin_1);
-
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3| GPIO_Pin_4| GPIO_Pin_5| GPIO_Pin_7| GPIO_Pin_8| GPIO_Pin_11;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- GPIO_ResetBits(GPIOA,GPIO_Pin_3|GPIO_Pin_4| GPIO_Pin_5| GPIO_Pin_7| GPIO_Pin_11);
- GPIO_SetBits(GPIOA,GPIO_Pin_8);
-
-
- //變量初始化
- for(cnt=0;cnt<12;cnt++) usart1_rx_buffer[cnt]=0;
- usart1_rx_point=0;sign_rxn_cnt=0;
- usart1_rx_count=0;
- data_usart1_rx=0;
- sign_rxn_usart1=0;
- for(cnt=0;cnt<12;cnt++) usart1_tx_buffer[cnt]=0;
- usart1_tx_point=0;
- usart1_tx_count=0;
-
- sign_debug=0;
- sign_clear_all_correct_vol=0;
- sign_x_correct_vol=0;
- set_vol_XZ=0; //最高65.535V
- set_vol_XF=0;
- set_vol_YZ=0;
- set_vol_YF=0;
- current_vol_XZ=0;
- current_vol_XF=0;
- current_vol_YZ=0;
- current_vol_YF=0;
-
- current_ch=0; //開機(jī)默認(rèn)為通道0 各通道電壓為0MV
- current_xz=0;
- current_xf=0;
- current_yz=0;
- current_yf=0;
-
-
- // //每次上電將在MCU的FLASH中的各通道及電數(shù)MV讀取SRAM中,以方使快速切換通道時(shí)輸出電壓到加電端子上
- // if(read_CHx_VOLx_to_SRAMx()) ;
- // else
- // {
- // usart1_tx_buffer[0]='e';
- // usart1_tx_buffer[1]='r';
- // usart1_tx_buffer[2]='r';
- // usart1_tx_buffer[3]='o';
- // usart1_tx_buffer[4]='r';
- // usart1_tx_ptr(usart1_tx_buffer,5);//返回ERROR信息
- // }
- //
- //
- // //最大通道
- // max_ch=STMFLASH_ReadHalfWord(MAX_CH_FLASH_ADDR);
- //
-
- // //定時(shí)器PWM初始
- // TIM_SelectOCxM(TIM4, TIM_Channel_1, TIM_OCMode_PWM1); //初始中強(qiáng)置低后,要再重恢復(fù)到PWM
- // TIM_SelectOCxM(TIM4, TIM_Channel_2, TIM_OCMode_PWM1);
- // TIM_CCxCmd(TIM4, TIM_Channel_1, TIM_CCx_Enable);
- // TIM_CCxCmd(TIM4, TIM_Channel_2, TIM_CCx_Enable);
- TIM_Cmd(TIM4, ENABLE); //開啟PWM輸出波形
- flag_mems_busy=IDLE;
- }
- /*******************************************************************************
- * Function Name : int main(void)
- * Description : This function .
- * Input : None
- * Output : None
- * Return : None
- * Attention : None
- *******************************************************************************/
- int main(void)
- {
- //u8 i;
- //uint32_t n=0;
-
- MemsReset:
- NVIC_Configuration();
- RCC_Configuration();
- GPIO_Configuration();
- EXTI_Configuration();
- TIM_Configuration(); //在PB.7上有上升沿時(shí),將在PB.6上產(chǎn)生一個(gè)脈沖;
- USART_Configuration();
- USART_ClearFlag(USART1,USART_FLAG_RXNE);
- Variables_Init();//狀態(tài)初始
-
- mems_IDLE();
- TIM_OC1PreloadConfig(TIM4, TIM_OCPreload_Disable); //立即生效
- TIM_OC2PreloadConfig(TIM4, TIM_OCPreload_Disable); //立即生效
-
- while(1)
- {
- //IWDG_Feed();
- //if(mems_ALARM );
- //if(!mems_RESET()) goto MemsReset;
-
- if(sign_rxn_usart1==1) // 標(biāo)記接收到了1幀數(shù)據(jù)
- {
- receive_info();
- sign_rxn_usart1=0;
- mems_IDLE();
- }
- }
- }
- #ifdef USE_FULL_ASSERT
- /*******************************************************************************
- * Function Name : assert_failed(uint8_t* file, uint32_t line)
- * Description : This function .Reports the name of the source file and
- the source line number where the assert_param error has
- occurred
- * Input : file: pointer to the source file name
- line: assert_param error line source number
- * Output : None
- * Return : None
- * Attention : None
- *******************************************************************************/
- void assert_failed(uint8_t* file, uint32_t line)
- {
- /* User can add his own implementation to report the file name and line number,
- ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
- /* Infinite loop */
- while (1)
- {
- }
- }
- #endif
復(fù)制代碼
Keil5代碼下載(僅供參考):
代碼.7z
(369.96 KB, 下載次數(shù): 16)
2022-5-26 20:33 上傳
點(diǎn)擊文件名下載附件
代碼與原理圖 下載積分: 黑幣 -5
|