Line 1... |
Line 1... |
// ===================================================================
|
// ===================================================================
|
// This is a library of counters
|
// This is a library of counter templates
|
|
// ===================================================================
|
|
// Template parameter:
|
|
// - TYPE determines the type of the counter
|
|
// Ex: TYPE = ubyte creates an 8 bits unsigned counter
|
|
//
|
// ===================================================================
|
// ===================================================================
|
// Each counter supports:
|
// Each counter supports:
|
// - Resetting
|
// - Resetting
|
// - Counting up
|
// - Counting up
|
// - Counting down
|
// - Counting down
|
// - Loading a value from the input iLoadValue
|
// - Loading a value from the input iLoadValue
|
//
|
//
|
// The code is straightforward, so you can easily create your own counter
|
// The code is straightforward, so you can easily create your own counter
|
// by changing the counter type or the operations. In fact you can
|
// by changing the operations. In fact you can create any functions
|
// create any functions like a shift register or even an
|
// like a shift register or even an ALU (Arithmetic and Logic Unit)
|
// ALU (Arithmetic and Logic Unit) or a calculator.
|
// or a calculator.
|
//
|
//
|
// The output always generates an event.
|
// The output always generates an event.
|
// If you don't want the event, remove the colon ':' in the assignment.
|
// If you don't want the event, remove the colon ':' in the assignment.
|
// Ex: change oValue := 0; to oValue = 0;
|
// Ex: change oValue := 0; to oValue = 0;
|
//
|
//
|
// ===================================================================
|
// ===================================================================
|
// There are four counters in the library.
|
// There are four counter templates in the library.
|
//
|
//
|
// The first two executes the operation on input events:
|
// The first two executes the operation on input events:
|
// - CCounterEvent: operations depends on inputs: iReset, iUp, iDown, iLoad
|
// - CCounterEvent_T: operations depends on inputs: iReset, iUp, iDown, iLoad
|
// - CCounterOprEvent: operations depends on a single input: iOpr
|
// - CCounterOprEvent_T: operations depends on a single input: iOpr
|
//
|
//
|
// The last two executes the operation at each step i.e. FPGA clock:
|
// The last two executes the operation at each step i.e. FPGA clock:
|
// - CCounterLevel: operations depends on inputs: iReset, iUp, iDown, iLoad
|
// - CCounterLevel_T: operations depends on inputs: iReset, iUp, iDown, iLoad
|
// - CCounterOprLevel: operations depends on a single input: iOpr
|
// - CCounterOprLevel_T: operations depends on a single input: iOpr
|
//
|
//
|
// ===================================================================
|
// ===================================================================
|
// TEST BENCHES:
|
// TEST BENCHES:
|
//
|
//
|
// - CCounterEvent: Manual test with control panel
|
// - CCounterEvent_T: Manual test with control panel
|
// Project in "TestCounterEvent" folder
|
// Project in "TestCounterEvent" folder
|
//
|
//
|
// - CCounterOprEvent: Simulated DE1SoC board, you need the BSP
|
// - CCounterOprEvent_T: Simulated DE1SoC board, you need the BSP
|
// Real DE1SoC board, you need the real board
|
// Real DE1SoC board, you need the real board
|
// Project in "TestCounterOprEventBoard" folder
|
// Project in "TestCounterOprEventBoard" folder
|
// Performed by a C++ program
|
// Performed by a C++ program
|
// Project in "TestCounterOprEventAPI" folder
|
// Project in "TestCounterOprEventAPI" folder
|
// << This project requires a paid license >>
|
// << This project requires a paid license >>
|
//
|
//
|
// - CCounterLevel: Using signal editor and viewer
|
// - CCounterLevel_T: Using signal editor and viewer
|
// Project in "TestCounterLevel" folder
|
// Project in "TestCounterLevel" folder
|
//
|
//
|
// - CCounterOprLevel: Using signal editor and viewer
|
// - CCounterOprLevel_T: Using signal editor and viewer
|
// Project in "TestCounterOprLevel" folder
|
// Project in "TestCounterOprLevel" folder
|
// ===================================================================
|
// ===================================================================
|
|
|
library CounterLib
|
library CounterLib
|
{
|
{
|
Line 53... |
Line 58... |
// This counter executes the operation on input events
|
// This counter executes the operation on input events
|
// There is a priority assigned to each function, in parenthesis
|
// There is a priority assigned to each function, in parenthesis
|
// 0 indicates highest priority
|
// 0 indicates highest priority
|
// and priority decreases with increasing value
|
// and priority decreases with increasing value
|
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
component CCounterEvent (in active bit iReset,
|
template
|
|
component CCounterEvent_T (in active bit iReset,
|
in active bit iUp,
|
in active bit iUp,
|
in active bit iDown,
|
in active bit iDown,
|
in active bit iLoad,
|
in active bit iLoad,
|
in passive ubyte iLoadValue,
|
in passive TYPE iLoadValue,
|
out active ubyte oValue)
|
out active TYPE oValue)
|
{
|
{
|
DoReset(0) on iReset
|
DoReset(0) on iReset
|
{
|
{
|
oValue := 0ub;
|
oValue := (TYPE)0;
|
}
|
}
|
|
|
CountUp(1) on iUp
|
CountUp(1) on iUp
|
{
|
{
|
oValue:++;
|
oValue:++;
|
Line 85... |
Line 91... |
|
|
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
// This counter executes the operation at each step or FPGA clock cycle
|
// This counter executes the operation at each step or FPGA clock cycle
|
// The priority is implemented with if and else instructions
|
// The priority is implemented with if and else instructions
|
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
component CCounterLevel (in passive bit iReset,
|
template
|
in passive bit iUp,
|
component CCounterLevel_T (in active bit iReset,
|
in passive bit iDown,
|
in active bit iUp,
|
in passive bit iLoad,
|
in active bit iDown,
|
in passive ubyte iLoadValue,
|
in active bit iLoad,
|
out active ubyte oValue)
|
in passive TYPE iLoadValue,
|
|
out active TYPE oValue)
|
{
|
{
|
always()
|
always()
|
{
|
{
|
if(iReset)
|
if(iReset)
|
{
|
{
|
oValue := 0ub;
|
oValue := (TYPE)0;
|
}
|
}
|
|
|
else if(iUp)
|
else if(iUp)
|
{
|
{
|
oValue:++;
|
oValue:++;
|
Line 128... |
Line 135... |
// The input iOpr has the type Opr_t and determines the operation.
|
// The input iOpr has the type Opr_t and determines the operation.
|
// There is no priority on the operation.
|
// There is no priority on the operation.
|
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
// The switch statement has no break, only one case is executed
|
// The switch statement has no break, only one case is executed
|
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
component CCounterOprEvent (in active Opr_t iOpr,
|
template
|
in passive ubyte iLoadValue,
|
component CCounterOprEvent_T (in active Opr_t iOpr,
|
out active ubyte oValue)
|
in passive TYPE iLoadValue,
|
|
out active TYPE oValue)
|
{
|
{
|
ExecuteOpr(0) on iOpr
|
ExecuteOpr(0) on iOpr
|
{
|
{
|
// The switch statement has no break, only one case is executed
|
// The switch statement has no break, only one case is executed
|
switch(iOpr)
|
switch(iOpr)
|
{
|
{
|
case cOprReset: oValue:= 0ub;
|
case cOprReset: oValue:= (TYPE)0;
|
case cOprUp: oValue:++;
|
case cOprUp: oValue:++;
|
case cOprDown: oValue:--;
|
case cOprDown: oValue:--;
|
case cOprLoad: oValue := iLoadValue;
|
case cOprLoad: oValue := iLoadValue;
|
}
|
}
|
}
|
}
|
Line 150... |
Line 158... |
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
// This counter executes the operation at each step or FPGA clock cycle
|
// This counter executes the operation at each step or FPGA clock cycle
|
// The input iOpr has the type Opr_t and determines the operation
|
// The input iOpr has the type Opr_t and determines the operation
|
// There is no priority on the operations
|
// There is no priority on the operations
|
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
component CCounterOprLevel (in active Opr_t iOpr,
|
template
|
in passive ubyte iLoadValue,
|
component CCounterOprLevel_T (in active Opr_t iOpr,
|
out active ubyte oValue)
|
in passive TYPE iLoadValue,
|
|
out active TYPE oValue)
|
{
|
{
|
always()
|
always()
|
{
|
{
|
// Send the event
|
// Send the event
|
oValue:;
|
oValue:;
|
|
|
// Assign the value
|
// Assign the value
|
// The switch instruction returns a value
|
// The switch instruction returns a value
|
oValue = switch(iOpr)
|
oValue = switch(iOpr)
|
{
|
{
|
case cOprReset: 0ub;
|
case cOprReset: (TYPE)0;
|
case cOprUp: oValue + 1ub;
|
case cOprUp: oValue + 1ub;
|
case cOprDown: oValue - 1ub;
|
case cOprDown: oValue - 1ub;
|
case cOprLoad: iLoadValue;
|
case cOprLoad: iLoadValue;
|
};
|
};
|
}
|
}
|