Home Article 12路pwm+13路ADC采集

12路pwm+13路ADC采集

Release time:2021-04-02 21:17:03 Author:一蓑烟雨 Reading volume:259
绝对够用了,用的是f103zet6工程文件下载

#include "led.h"
#include "delay.h"
#include "key.h"
#include "sys.h"
#include "usart.h"
#include "pwm.h"
#include "adc.h"
 
/**

adcx[0]  PA0   adc1_ch0
adcx[1]  PA1   adc1_ch1
adcx[2]  PF6   adc3_ch4
adcx[3]  PF7   adc3_ch5
adcx[4]  PF8   adc3_ch6
adcx[5]  PF9   adc3_ch7
adcx[6]  PF10   adc3_ch8
adcx[7]  PC0   adc1_ch10
adcx[8]  PC1   adc1_ch11
adcx[9]  PC2   adc1_ch12
adcx[10]  PC3   adc1_ch13
adcx[11]  PC4   adc1_ch14
adcx[12]  PC5   adc1_ch15

**/

u16 adcx[14] = {0};


 int main(void)
 {		
	 
	delay_init();	    	 //延时函数初始化	  
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); 	 //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
	uart_init(115200);	 //串口初始化为115200
  Adc_Init();			 
	 //LED端口初始化
	 
	  /*
	 pwm1:  PB8   tim1-ch1
	 pwm2:  PB11  tim1-ch4
	 pwm3:  PA6		tim3-ch1
	 pwm4:  PA7		tim3-ch2
	 pwm5:  PB0		tim3-ch3
	 pwm6:  PB1		tim3-ch4
	 pwm7:  PB6   tim4-ch1
	 pwm8:  PB7   tim4-ch2
	 pwm9:  PC5   tim8-ch1
	 pwm10: PC6		tim8-ch2
	 pwm11: PC7		tim8-ch3
	 pwm12: PC8 	tim8-ch4
	 
	 */
	TIM1_PWM_Init(899,0);
 	TIM3_PWM_Init1(899,0);	 //不分频。PWM频率=72000000/900=80Khz
	TIM4_PWM_Init(899,0);
	TIM8_PWM_Init(1799,0);
	
	 
	
	 TIM_SetCompare1(TIM1,200);
	 TIM_SetCompare4(TIM1,600);
	 TIM_SetCompare1(TIM3,300);
	 TIM_SetCompare2(TIM3,300);
	 TIM_SetCompare3(TIM3,300);
	 TIM_SetCompare4(TIM3,300);
	 TIM_SetCompare1(TIM4,300);
	 TIM_SetCompare2(TIM4,300);
	 TIM_SetCompare1(TIM8,300);
	 TIM_SetCompare2(TIM8,300);
	 TIM_SetCompare3(TIM8,300);
	 TIM_SetCompare4(TIM8,300);
	 
	 
   	while(1)
	{
		adcx[0]=Get_Adc_Average(ADC1,ADC_Channel_0,10);
		adcx[1]=Get_Adc_Average(ADC1,ADC_Channel_1,10);
		adcx[2]=Get_Adc_Average(ADC3,ADC_Channel_4,10);
		adcx[3]=Get_Adc_Average(ADC3,ADC_Channel_5,10);
		adcx[4]=Get_Adc_Average(ADC3,ADC_Channel_6,10);
		adcx[5]=Get_Adc_Average(ADC3,ADC_Channel_7,10);
		adcx[6]=Get_Adc_Average(ADC3,ADC_Channel_8,10);
		adcx[7]=Get_Adc_Average(ADC1,ADC_Channel_10,10);
		adcx[8]=Get_Adc_Average(ADC1,ADC_Channel_11,10);
		adcx[9]=Get_Adc_Average(ADC1,ADC_Channel_12,10);
		adcx[10]=Get_Adc_Average(ADC1,ADC_Channel_13,10);
		adcx[11]=Get_Adc_Average(ADC1,ADC_Channel_14,10);
		adcx[12]=Get_Adc_Average(ADC1,ADC_Channel_15,10);
		
		//adcx[7]=Get_Adc_Average(ADC1,ADC_Channel_1,10);
		
		printf("adc0:%d adc1:%d adc2:%d adc3:%d adc4:%d adc5:%d adc6:%d
 adc7:%d adc8:%d adc9:%d adc10:%d adc11:%d adc12:%d
",adcx[0],adcx[1],adcx[2],adcx[3],adcx[4],adcx[5],adcx[6],adcx[7],adcx[8],adcx[9],adcx[10],adcx[11],adcx[12]);
 		delay_ms(1000);	 
		
								 
				   
	}	 
 }

  
I want to comment

Search

classification

Leave a message
http://blog.rjxj513.com/index.php/
User login
You have not written any reviews yet!
You have commented!
Can only praise once!
You have a collection!