Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a static refresh_flag that is set to 1 at the start of the refr… #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions VarSpeedServo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ servoSequencePoint initSeq[] = {{0,100},{45,100}};

//sequence_t sequences[MAX_SEQUENCE];

volatile int8_t VarSpeedServo::refresh_flag;

// convenience macros
#define SERVO_INDEX_TO_TIMER(_servo_nbr) ((timer16_Sequence_t)(_servo_nbr / SERVOS_PER_TIMER)) // returns the timer controlling this servo
#define SERVO_INDEX_TO_CHANNEL(_servo_nbr) (_servo_nbr % SERVOS_PER_TIMER) // returns the index of the servo on this timer
Expand All @@ -105,9 +107,10 @@ servoSequencePoint initSeq[] = {{0,100},{45,100}};

static inline void handle_interrupts(timer16_Sequence_t timer, volatile uint16_t *TCNTn, volatile uint16_t* OCRnA)
{
if( Channel[timer] < 0 )
if( Channel[timer] < 0 ) {
*TCNTn = 0; // channel set to -1 indicated that refresh interval completed so reset the timer
else{
VarSpeedServo::refresh_flag = 0;
}else{
if( SERVO_INDEX(timer,Channel[timer]) < ServoCount && SERVO(timer,Channel[timer]).Pin.isActive == true )
digitalWrite( SERVO(timer,Channel[timer]).Pin.nbr,LOW); // pulse this channel low if activated
}
Expand Down Expand Up @@ -149,6 +152,7 @@ static inline void handle_interrupts(timer16_Sequence_t timer, volatile uint16_t
else
*OCRnA = *TCNTn + 4; // at least REFRESH_INTERVAL has elapsed
Channel[timer] = -1; // this will get incremented at the end of the refresh period to start again at the first channel
VarSpeedServo::refresh_flag = 1;
}
}

Expand Down
3 changes: 2 additions & 1 deletion VarSpeedServo.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ;

#define VarSpeedServo_VERSION 2 // software version of this library

#define MIN_PULSE_WIDTH 544 // the shortest pulse sent to a servo
#define MIN_PULSE_WIDTH 444 // the shortest pulse sent to a servo
#define MAX_PULSE_WIDTH 2400 // the longest pulse sent to a servo
#define DEFAULT_PULSE_WIDTH 1500 // default pulse width when servo is attached
#define REFRESH_INTERVAL 20000 // minumim time to refresh servos in microseconds
Expand Down Expand Up @@ -147,6 +147,7 @@ typedef struct {
class VarSpeedServo
{
public:
static volatile int8_t refresh_flag;
VarSpeedServo();
uint8_t attach(int pin); // attach the given pin to the next free channel, sets pinMode, returns channel number or 0 if failure
uint8_t attach(int pin, int min, int max); // as above but also sets min and max values for writes.
Expand Down