开发工具:
文件大小: 9mb
下载次数: 0
上传时间: 2018-06-12
详细说明: /* This file is part of AutoQuad ESC32. AutoQuad ESC32 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. AutoQuad ESC32 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public Lice nse for more details. You should have received a copy of the GNU General Public License along with AutoQuad ESC32. If not, see . Copyright © 2011, 2012 Bill Nesbitt */ /* * pwm.c文件.此文件有2个功能,2个功能分别使用,不能同时使用 * 1、pwm in输入模式,pwm输入中断里,调用runNewInput函数 * 2、one wire通讯协议,pwm输入中断里,调用owEdgeDetect函数,来输入新的数据,调用owReset函数来复位1wire通讯 * */ #include "pwm.h" #include "timer.h" #include "run.h" #include "main.h" #include "ow.h" #include "stm32f10x_gpio.h" #include "stm32f10x_tim.h" #include "misc.h" static int16_t pwmMinPeriod; //timer1 ch1 pwm 输入最小周期 static int16_t pwmMaxPeriod; //timer1 ch1 pwm 输入最大周期 int16_t pwmMinValue; //timer1 ch2 pwm 输入最小周期 static int16_t pwmMaxValue; //timer1 ch2 pwm 输入最大周期 int16_t pwmLoValue; int16_t pwmHiValue; int16_t pwmMinStart; volatile uint32_t pwmValidMicros; //关闭输入捕获比较中断 1和2 void pwmIsrAllOff(void) { PWM_TIM->DIER &= (uint16_t)~(TIM_IT_CC1 | TIM_IT_CC2);//关闭中断 } //开启输入捕获比较中断 1和2 void pwmIsrAllOn(void) { PWM_TIM->CCR1; PWM_TIM->CCR2; PWM_TIM->DIER |= (TIM_IT_CC1 | TIM_IT_CC2);//允许捕获比较 1 2中断 } //开启捕获比较2中断 void pwmIsrRunOn(void) { uint16_t dier = PWM_TIM->DIER; dier &= (uint16_t)~(TIM_IT_CC1 | TIM_IT_CC2); dier |= TIM_IT_CC2;//允许捕获/比较2中断 PWM_TIM->CCR1; PWM_TIM->CCR2; PWM_TIM->DIER = dier; } //timer 1 void pwmInit(void) { GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; TIM_ICInitTypeDef TIM_ICInitStructure; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; pwmSetConstants(); // TIM1 channel 1 pin (PA.08) configuration GPIO_InitStructure.GPIO_Pin = PWM_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(PWM_PORT, &GPIO;_InitStructure); // Enable the TIM1 global Interrupt NVIC_InitStructure.NVIC_IRQChannel = PWM_IRQ; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC;_InitStructure); TIM_TimeBaseStructInit(&TIM;_TimeBaseStructure); TIM_TimeBaseStructure.TIM_Prescaler = (PWM_CLK_DIVISOR-1); TIM_TimeBaseStructure.TIM_Period = 0xffff; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(PWM_TIM, &TIM;_TimeBaseStructure); TIM_ICInitStructure.TIM_Channel = PWM_CHANNEL; TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; TIM_ICInitStructure.TIM_ICFilter = 0x0; TIM_PWMIConfig(PWM_TIM, &TIM;_ICInitStructure); // Select the TIM Input Trigger: TI1FP1 // 滤波后的定时器输入1(TI1FP1) TIM_SelectInputTrigger(PWM_TIM, TIM_TS_TI1FP1); // Select the slave Mode: Reset Mode TIM_SelectSlaveMode(PWM_TIM, TIM_SlaveMode_Reset);//复位模式 // Enable the Master/Slave Mode TIM_SelectMasterSlaveMode(PWM_TIM, TIM_MasterSlaveMode_Enable); // TIM enable counter TIM_Cmd(PWM_TIM, ENABLE); pwmIsrAllOn(); } //timer1 TIM1_CC_IRQHandler中断 void PWM_IRQ_HANDLER(void) { uint16_t pwmValue; uint16_t periodValue; uint8_t edge; edge = !(PWM_TIM->SR & TIM_IT_CC2); periodValue = PWM_TIM->CCR1; //IO 输入PA8 周期 pwmValue = PWM_TIM->CCR2; //IO 输入(但是没有看到配置了使用哪个IO做为输入了) 脉宽长度 // look for good RC PWM input if (inputMode == ESC_INPUT_PWM && //PWM输入模式 periodValue >= pwmMinPeriod && periodValue <= pwmMaxPeriod && //pa8输入的周期范围 pwmValue >= pwmMinValue && pwmValue <= pwmMaxValue //脉宽长度 ) { if (edge == 0) { pwmValidMicros = timerMicros; runNewInput(pwmValue); //PWM正确.输入 } } } void pwmSetConstants(void) { float rpmScale = p[PWM_RPM_SCALE]; pwmMinPeriod = p[PWM_MIN_PERIOD] = (int)p[PWM_MIN_PERIOD];//PWM最小周期 timer1 ch1 pwmMaxPeriod = p[PWM_MAX_PERIOD] = (int)p[PWM_MAX_PERIOD];//PWM最大周期 timer1 ch1 pwmMinValue = p[PWM_MIN_VALUE] = (int)p[PWM_MIN_VALUE]; //PWM最小周期 timer1 ch2 pwmMaxValue = p[PWM_MAX_VALUE] = (int)p[PWM_MAX_VALUE]; //PWM最大周期 timer1 ch2 pwmLoValue = p[PWM_LO_VALUE] = (int)p[PWM_LO_VALUE]; pwmHiValue = p[PWM_HI_VALUE] = (int)p[PWM_HI_VALUE]; pwmMinStart = p[PWM_MIN_START] = (int)p[PWM_MIN_START]; if (rpmScale < PWM_RPM_SCALE_MIN) rpmScale = PWM_RPM_SCALE_MIN; else if (rpmScale > PWM_RPM_SCALE_MAX) rpmScale = PWM_RPM_SCALE_MAX; p[PWM_RPM_SCALE] = rpmScale; } ESC32开源电调 源码与原理图,此源码采用RTT操作系统,CAN PWM操作方式 ,本人已用PWM方式成功驱动起来,CAN 暂且还没做测试。 此资料是 啊嘉 开源出来的,好资料不敢独享,稍加整理放到这与大家共享。 ...展开收缩
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.