Instant SoC Class Library  3.1
FC_IO_PWM Class Reference

Pulse Width Modulation output. More...

Inheritance diagram for FC_IO_PWM:
FC_Base

Public Member Functions

 FC_IO_PWM (int width, int pol_on=1)
 
void Setup (U16 period, TimeUnits tu=TU_clk)
 
void SetOnOff (U16 on, U16 off, U32 channel)
 

Detailed Description

Pulse Width Modulation output.

Adds to interface:
if width = 1 then
<name> : out std_logic
if width > 1 then
<name> : out std_logic_vector(width-1 downto 0)
where <name> is c++ object name.
Any number of instances are allowed.

// This example show how to use the FC_IO_PWM and FC_System_Timer classes.
// Two PWM objects are created. One with 4 outputs and one with one output.
// Every 1000 us one of the PWMs dutycycle is updated.
#include "fc_io.h"
#include "fc_system.h"
int main()
{
//% hw_begin
FC_IO_Clk clk(100);
FC_IO_PWM pwm_1(4);
FC_IO_PWM pwm_2(1);
//% hw_end
int on = 100;
pwm_1.Setup(1000, TU_us);
pwm_1.SetOnOff(0,on,0);
pwm_1.SetOnOff(0,400,1);
pwm_1.SetOnOff(400,0,2);
pwm_1.SetOnOff(300,450,3);
pwm_2.Setup(200, TU_us);
pwm_2.SetOnOff(0,50,0);
timer.Start(1000,TU_us);
for (;;)
{
timer.WaitTimer();
on += 100;
if( on >= 1000 )
on = 100;
pwm_1.SetOnOff(0,on,0);
}
}

This example will give the following result:

FC_IO_Clk
System clock input.
Definition: fc_io.h:55
FC_System_Timer
Timer.
Definition: fc_system.h:78
FC_IO_PWM
Pulse Width Modulation output.
Definition: fc_io.h:238