Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Spindle.cpp « src - github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7c4f531bdc04a6caa26cb927849ae7d6b04d6d72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
 * Spindle.cpp
 *
 *  Created on: Mar 21, 2018
 *      Author: Christian
 */

#include "Spindle.h"

bool Spindle::SetPins(LogicalPin lpf, LogicalPin lpr, bool invert)
{
	const bool ok1 = spindleForwardPort.Set(lpf, PinAccess::pwm, invert);
	if (lpr == NoLogicalPin)
	{
		spindleReversePort.Clear();
		return ok1;
	}
	const bool ok2 = spindleReversePort.Set(lpr, PinAccess::pwm, invert);
	return ok1 && ok2;
}

void Spindle::GetPins(LogicalPin& lpf, LogicalPin& lpr, bool& invert) const
{
	lpf = spindleForwardPort.GetLogicalPin(invert);
	lpr = spindleReversePort.GetLogicalPin();
}

void Spindle::SetPwmFrequency(float freq)
{
	spindleReversePort.SetFrequency(freq);
	spindleForwardPort.SetFrequency(freq);
}

void Spindle::SetRpm(float rpm)
{
	const float pwm = abs(rpm / maxRpm);
	if (rpm >= 0.0)
	{
		spindleReversePort.WriteAnalog(0.0);
		spindleForwardPort.WriteAnalog(pwm);
	}
	else
	{
		spindleReversePort.WriteAnalog(pwm);
		spindleForwardPort.WriteAnalog(0.0);
	}
	currentRpm = configuredRpm = rpm;
}

void Spindle::TurnOff()
{
	spindleReversePort.WriteAnalog(0.0);
	spindleForwardPort.WriteAnalog(0.0);
	currentRpm = 0.0;
}

// End