Skip to content

Commit 7c78549

Browse files
committed
Fixed timing issue & re-enabled 'setPWMFreq()'
- setPWMFreq() is used to remove the audible PWM hum
1 parent 1adeb6d commit 7c78549

2 files changed

Lines changed: 11 additions & 15 deletions

File tree

src/FingerLib.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
13
/*
24
* FingerLib.cpp
35
*
@@ -58,12 +60,8 @@ uint8_t Finger::attach(uint8_t dir0, uint8_t dir1, uint8_t sense, bool inv)
5860

5961

6062
// if using the Atmega2560, set the PWM freq to > 20kHz to prevent humming
61-
// the PWM freq on the Zero is > 20kHz by default
62-
#if defined(ARDUINO_AVR_MEGA2560)
63-
//setPWMFreq(dir0, 0x01); // set PWM frequency to max freq DISABLED DUE TO POTENTIAL CSV MODE TIMING BUG
64-
//setPWMFreq(dir1, 0x01); // set PWM frequency to max freq DISABLED DUE TO POTENTIAL CSV MODE TIMING BUG
65-
#endif
66-
63+
setPWMFreq(dir0, 0x01); // set PWM frequency to max freq
64+
setPWMFreq(dir1, 0x01); // set PWM frequency to max freq
6765

6866
// initialise the timer
6967
if(_timerSetupFlag == false)
@@ -387,9 +385,8 @@ void fingerPosCtrl(void)
387385
signed int motorSpeed = 0; // used to calculate the motor speed as a vector (±255)
388386
float m; // the proportional gradient
389387
signed int vectorise = 1; // changes the sign '±' of the value
390-
391-
int proportionalOffset = 150;
392-
signed int motorStopOffset = 20;
388+
int proportionalOffset = 150;
389+
signed int motorStopOffset = 20;
393390

394391

395392
if(_TotalFingerCount > 0) // if _fingers are attached

src/FingerLib.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@
3737

3838
#define MAX_FINGERS 6 // maximum number of _fingers
3939
#define MAX_FINGER_SPEED 255 // maximum motor speed
40-
#define MIN_FINGER_SPEED 99 // minimum motor speed
40+
#define MIN_FINGER_SPEED 99 //99 // minimum motor speed
4141
#define MAX_FINGER_POS 973 // maximum motor position
4242
#define MIN_FINGER_POS 50 // minimum motor position
43-
// #define MAX_FINGER_POS 923 // maximum motor position
44-
// #define MIN_FINGER_POS 100 // minimum motor position
43+
4544
#define POS_REACHED_TOLERANCE 50 // tolerance for posReached()
4645

46+
4747
typedef struct {
4848
uint8_t dir[2];
4949
uint8_t sns;
@@ -115,10 +115,9 @@ class Finger
115115

116116
private:
117117
uint8_t fingerIndex; // index into the channel data for this finger
118-
#if defined(ARDUINO_AVR_MEGA2560)
118+
119119
void setPWMFreq(uint8_t pin, uint8_t value);
120-
#endif
121-
120+
122121
};
123122

124123
void motorControl(int fNum, signed int motorSpeed);

0 commit comments

Comments
 (0)