10 Star 17 Fork 10

GrayPillow / Ananas

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
Da.cpp 2.72 KB
Copy Edit Raw Blame History
GrayPillow authored 2016-06-02 23:20 . test Ananans0.9.2
/*
****************************************************************************
* 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
C++
1
https://gitee.com/GaryPillow/Ananas.git
git@gitee.com:GaryPillow/Ananas.git
GaryPillow
Ananas
Ananas
PID

Search