@Elco , my doubt is related how to implement control action translating PID control action to analogWrite value (duty cycle). Seems logic that duty cycle is proportional to error between setpoint and PV, but how to translate it, linearly? Linearly considering what limits (upper and lower)? How is implemented the logic to translate PID control action to 0-255 argument in analogWrite to change the duty cycle?
Thanks,
Fabiano da Mata
Elco
April 6, 2017, 11:30am
32
This has been implemented in the BrewPi Spark. Not with analogwrite, because that PWM cycle is too fast to work well with a 50Hz AC signal. We wrote our custom, much more advanced PWM algorithm that can take into account time limits and mutual exclusivity of actuators.
We have not build this for Arduino and never will. If you want to do it yourself, that’s fine, but we have abandoned Arduino as a platform.
Ok @Elco . The Spark PWM code is available? Could you tell me where can I find it? The Spark PID is a PID tradictional, or is it modified also?
Thanks,
Fabiano da Mata
Elco
April 6, 2017, 12:32pm
34
The PID is new and the PWM class depends on multiple other classes that are new in the Spark firmware.
/*
* Copyright 2015 BrewPi / Elco Jacobs
*
* This file is part of BrewPi.
*
* BrewPi 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.
*
* BrewPi 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 BrewPi. If not, see <http://www.gnu.org/licenses/>.
*/
This file has been truncated. show original
/*
* Copyright 2015 BrewPi / Elco Jacobs
*
* This file is part of BrewPi.
*
* BrewPi 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.
*
* BrewPi 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 BrewPi. If not, see <http://www.gnu.org/licenses/>.
*/
This file has been truncated. show original
/*
* Copyright 2015 BrewPi/Elco Jacobs.
* Copyright 2015 Matthew McGowan
*
* This file is part of BrewPi.
*
* BrewPi 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.
*
* BrewPi 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 BrewPi. If not, see <http://www.gnu.org/licenses/>.
*/
This file has been truncated. show original
#include <stdint.h>
#include "ActuatorInterfaces.h"
#include "ActuatorPwm.h"
#include "Ticks.h"
#include "ActuatorMutexDriver.h"
ActuatorPwm::ActuatorPwm(ActuatorDigital & _target, uint16_t _period) :
target(_target),
dutySetting(0.0),
dutyLate(0),
periodLate(0),
minVal(0.0),
maxVal(100.0)
{
target.setActive(false);
setPeriod(_period); // sets period_ms
periodStartTime = ticks.millis();
// at init, pretend last high period was tiny spike in the past
lowToHighTime = periodStartTime - period_ms;
highToLowTime = lowToHighTime + 2;
This file has been truncated. show original
This will be hard to migrate to the Arduino.