Fraise  2.1
FRAmework for Interfacing Software and Electronics
Software PWM module

Implements 8channels(max) 10bits 100Hz(max) software PWM. More...

Implements 8channels(max) 10bits 100Hz(max) software PWM.

Example : main.c

/*********************************************************************
* analog example for Versa1.0
* Analog capture on connectors K1, K2, K3 and K5.
*********************************************************************/
#define BOARD Versa1
#include <fruit.h>
#include <softpwm.h>
t_delay mainDelay;
void setup(void) {
//----------- Setup ----------------
pinModeDigitalOut(LED); // set the LED pin mode to digital out
digitalClear(LED); // clear the LED
delayStart(mainDelay, 5000); // init the mainDelay to 5 ms
//----------- softpwm setup ----------------
softpwmInit(); // init softpwm module
}
// ---------- Main loop ------------
void loop() {
fraiseService(); // listen to Fraise events
}
// ---------- Interrupts ------------
{
}
{
}
// Receiving
void fraiseReceive() // receive raw bytes
{
unsigned char c=fraiseGetChar();
if(c==50) softpwmReceive(); // if first byte is 50, then call softpwm receive function.
}

config.h

#ifndef _CONFIG_H_
#define _CONFIG_H_
#define SOFTPWM0 LED
#define SOFTPWM1 K1
#define SOFTPWM2 K2
#define SOFTPWM3 K3
#define SOFTPWM4 K4
#define SOFTPWM_TICK_US 6
//#define SOFTPWM_MAX_VALUE 1023
//#define SOFTPWM_INTPRI 1
#endif // _CONFIG_H_

Settings to put in config.h

Define in config.h the wanted pins:

#define SOFTPWM0 K1 (replace K1 by the pin you want for softpwm channel 0)
#define SOFTPWM1 K2 (replace K2 by the pin you want for softpwm channel 1)
(...)

The following parameters can be overloaded:

#define SOFTPWM_TIMER
 Timer to be used by the softpwm module (only 1, 3 or 5 ; default: 5).
 
#define SOFTPWM_MAX_VALUE
 default 1023.
 
#define SOFTPWM_TICK_US
 default 5 ; PWM frequency will be 1 / (SOFTPWM_MAX_VALUE * SOFTPWM_TICK_US)
 
#define SOFTPWM_INTPRI
 default 1 (high priority).
 

Initialization

void softpwmInit ()
 Init the module in setup()
 

Utilities

void softpwmSet (unsigned char chan, unsigned int val)
 Set the value of a channel.
 
unsigned int softpwmGet (unsigned char chan)
 Get the current value of a channel.
 

Interrupt routine

void softpwmHighInterrupt (void)
 Module high interrupt routine, must be called by the highInterrupts() user defined function.
 
void softpwmLowInterrupt (void)
 Module low interrupt routine, must be called by the lowInterrupts() user defined function.
 

Receive function

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

Function Documentation

◆ softpwmReceive()

void softpwmReceive ( )

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 pwm value.

softpwm.h
loop
void loop()
User defined forever loop.
fruitInit
void fruitInit(void)
Init fruit module at setup().
highInterrupts
void highInterrupts()
Optional user defined high priority interrupt routine.
t_delay
unsigned long t_delay
Delay type.
Definition: core.h:215
digitalClear
#define digitalClear(conn)
Digital clear pin. Clear the pin output voltage.
Definition: core.h:168
fruit.h
fraiseService
void fraiseService(void)
Fraise device service routine.
fraiseReceive
void fraiseReceive()
Raw message to this device.
lowInterrupts
void lowInterrupts()
Optional user defined low priority interrupt routine.
softpwmInit
void softpwmInit()
Init the module in setup()
setup
void setup()
User defined initialization.
fraiseGetChar
unsigned char fraiseGetChar()
Get next char from receive buffer.
softpwmLowInterrupt
void softpwmLowInterrupt(void)
Module low interrupt routine, must be called by the lowInterrupts() user defined function.
pinModeDigitalOut
#define pinModeDigitalOut(conn)
Set pin mode to Digital Output.
Definition: core.h:142
softpwmHighInterrupt
void softpwmHighInterrupt(void)
Module high interrupt routine, must be called by the highInterrupts() user defined function.
softpwmReceive
void softpwmReceive()
Module receive function, to be called by the fraiseReceive() user defined function.
delayStart
#define delayStart(delay, micros)
Start delay.
Definition: core.h:220