Fraise  2.1
FRAmework for Interfacing Software and Electronics
Servo module

Automates the use of maximum 8 RC servomotors. More...

Automates the use of maximum 8 RC servomotors.

Servo module uses timer 5.

Example :

/*********************************************************************
* servo example for Versa1.0
* Output RC servo waveforms to K11 (channel 0) and K12 (channel 1).
*********************************************************************/
#define BOARD Versa1
#include <fruit.h>
#include <servo.h>
//----------- Setup ----------------
void setup(void) {
servoInit(); // init servo module
servoSelect(0,K11); // assign connector K11 to servo channel 0
servoSelect(1,K12); // assign connector K12 to servo channel 1
}
// ---------- Main loop ------------
void loop() {
fraiseService();// listen to Fraise events
servoService(); // servo management routine
}
// ---------- Interrupts ------------
{
}
// ---------- Receiving ------------
void fraiseReceive() // receive raw bytes
{
unsigned char c=fraiseGetChar();
if(c==20) servoReceive(); // if first byte is 20, then call servo receive function.
}

Initialization

void servoInit (void)
 Init the module in setup()
 
#define servoSelect(num, conn)
 Select a pin for a servo channel. More...
 

Main loop functions

void servoService (void)
 Module service routine, to be called by the main loop().
 

Utilities

void servoSet (unsigned char num, unsigned int val)
 Set position of a servomotor. More...
 

Interrupt routine

void servoHighInterrupt (void)
 Module interrupt routine, must be called by the highInterrupts() user defined function.
 

Receive function

void servoReceive ()
 Module receive function, to be called by the fraiseReceive() user defined function. More...
 
void servoSetPort (unsigned char num, unsigned char *port, unsigned char mask)
 
#define SERVO_SELECT_(num, connport, connbit)
 

Function Documentation

◆ servoSet()

void servoSet ( unsigned char  num,
unsigned int  val 
)

Set position of a servomotor.

Parameters
numServomotor channel (0 to 7)
valNew position of this servo, in 8/FOSC steps ; e.g for Versa1, FOSC=64MHz, so servo steps are 1/8 us : 8000 corresponds to 1 ms position.

◆ servoReceive()

void servoReceive ( )

Module receive function, to be called by the fraiseReceive() user defined function.

The first byte of the message represents the channel (0-7), the 2 next bytes are the 16 bit new position value. If the first byte equals to 254, then the message is for reading a channel position ; the next byte then is the actual channel, and the module sends to the master the current position of this channel.

Macro Definition Documentation

◆ servoSelect

#define servoSelect (   num,
  conn 
)

Select a pin for a servo channel.

Parameters
numServomotor channel (0 to 7)
connSymbol of the pin (example : K1 for connector 1)
servo.h
loop
void loop()
User defined forever loop.
fruitInit
void fruitInit(void)
Init fruit module at setup().
servoInit
void servoInit(void)
Init the module in setup()
highInterrupts
void highInterrupts()
Optional user defined high priority interrupt routine.
servoSelect
#define servoSelect(num, conn)
Select a pin for a servo channel.
Definition: servo.h:53
servoReceive
void servoReceive()
Module receive function, to be called by the fraiseReceive() user defined function.
servoHighInterrupt
void servoHighInterrupt(void)
Module interrupt routine, must be called by the highInterrupts() user defined function.
fruit.h
fraiseService
void fraiseService(void)
Fraise device service routine.
fraiseReceive
void fraiseReceive()
Raw message to this device.
setup
void setup()
User defined initialization.
fraiseGetChar
unsigned char fraiseGetChar()
Get next char from receive buffer.
servoService
void servoService(void)
Module service routine, to be called by the main loop().