1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/GaryPillow-Ananas

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
Da.cpp 2.7 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
Dark-Guan Отправлено 02.06.2016 18:20 f2ab379
/*
****************************************************************************
* Copyright (c) 2015 Dark Guan <tickel.guan@gmail.com> *
* This file is part of Ananas. *
* *
* Ananas 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. *
* *
* Ananas 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 License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with Ananas. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************
*/
/*
* Da.cpp
*
* Created on: 2015年12月14日
* Author: Dark
*/
#include "Da.h"
/*
*initial the DA,and set a initial voltage
*avoid the driver shake
*/
#if DEVICE == DIY_TEST
#include "TLC5615.h"
TLC5615 DA(DA_DIN, DA_SCLK, DA_CS);
uint16_t maxvol;
uint16_t minvol;
uint16_t volfactor;
uint8_t errorallow;
uint16_t volstate;
void initial_DA() {
DA.InitTLC5615();
//TODO 这里要加上从EEPROM里面来获取匹配电机信息的步骤
//匹配最大电压和最小电压
//这里要限制最小电压,要不然驱动器会抖
maxvol = MAX_DA;
minvol = DA_initial;
errorallow = MAXERROR*5;
volfactor = (maxvol - minvol) / errorallow;
//
delay(10);
//initial DA
DA_SET_V(minvol); //initial value of votage
}
/*
* set the voltage
*/
void DA_SET_V(unsigned int Vol) {
//the voltage is limited
//the voltage large then
if (Vol > maxvol) {
DA.DAConvert(maxvol);
volstate = maxvol;
} else if (Vol < minvol) {
DA.DAConvert(minvol);
volstate = minvol;
} else {
DA.DAConvert(Vol);
volstate = Vol; //store state
}
}
/*
* adjust the voltage
*/
void managerVoltage(int error) {
//change the voltage base on the difference between the pulse and the encoder count
//max error
int temp = error - MAXERROR;
if (temp >= errorallow) {
DA_SET_V(maxvol);
} else {
DA_SET_V(minvol + temp * volfactor);
}
}
uint16_t getvol() {
return volstate;
}
#endif

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/GaryPillow-Ananas.git
git@api.gitlife.ru:oschina-mirror/GaryPillow-Ananas.git
oschina-mirror
GaryPillow-Ananas
GaryPillow-Ananas
PID