IC library

From openPicus Wiki
Jump to: navigation, search

Contents

Description

The ICHelper library allows to manage the Input Capture modules. It's possible to get and to calculate the time (ticks from timer) at a specific input edge.

DOWNLOAD

Version

V.1.0
This library is going to be constantly updated according to the feedback

Content

  • ICHelper.c
  • ICHelper.h

Lastest library revision can be downloaded here


Flyport warning

This library is only made for FlyportPRO modules and doesn't work on Flyport.

Connections

Importing into OpenPicus IDE

How To import external Lib Tutorial

Commands - ICHelper

ICPin

Initializes the specified pin for Input Capture operations.

VOID ICPin(int io, BYTE ic_module)
Argument Description
int io specifies the pin

Flyport PRO WiFi and Flyport PRO GPRS:
p1, p3, p7, p8, p10, p12, p13, p14, p15, p17, p19, p20, p21, p22, p23, p24, p26, p28

Flyport PRO Ethernet:
p1, p3, p7, p8, p10, p12, p13, p14, p15, p17, p19, p20, p21, p22, p23, p24, p26, p28, p31
BYTE ic_module specifies which IC module the pin must be initialized to.
The valid parameters are the following:
  • IC1 - Input Capture 1
  • IC2 - Input Capture 2
  • IC3 - Input Capture 3
  • IC4 - Input Capture 4
  • IC5 - Input Capture 5
  • IC6 - Input Capture 6
  • IC7 - Input Capture 7
  • IC8 - Input Capture 8
  • IC9 - Input Capture 9


ICOn

Function to set up and switch on the input capture module.
return - 0 the operation was successful
return - -1 the operation was unsuccessful

int ICOn(BYTE ic_module, BYTE active_edge, BYTE num_edge, BYTE mask_edge, int doublemodule)
Argument Description
BYTE ic_module specifies the IC module.
The valid parameters are the following:
  • IC1 - Input Capture 1 -> 16 bit timer or 32 bit timer (in this case IC2 can't be used)
  • IC2 - Input Capture 2 -> 16 bit timer
  • IC3 - Input Capture 3 -> 16 bit timer or 32 bit timer (in this case IC4 can't be used)
  • IC4 - Input Capture 4 -> 16 bit timer
  • IC5 - Input Capture 5 -> 16 bit timer or 32 bit timer (in this case IC6 can't be used)
  • IC6 - Input Capture 6 -> 16 bit timer
  • IC7 - Input Capture 7 -> 16 bit timer or 32 bit timer (in this case IC8 can't be used)
  • IC8 - Input Capture 8 -> 16 bit timer
  • IC9 - Input Capture 9 -> 16 bit timer
BYTE active_edge specifies the edge that triggers the interrupt.
The valid parameters are the following:
  • RISING_EDGE
  • FALLING_EDGE
  • BOTH_EDGE
BYTE num_edge number of events you want store
BYTE mask_edge mask for interrupt events.
The valid parameters are the following:
  • EVERY_EVENT - the interrupt triggers for every event
  • EVERY_SECOND_EVENT - the interrupt triggers for every two events
  • EVERY_THIRD_EVENT - the interrupt triggers for every three events
  • EVERY_FOURTH_EVENT - the interrupt triggers for every four events
int doublemodule specifies if the module selected is provided with a 32 bit timer.
The valid parameters are the following:
  • SINGLE_MODULE - 16 bit timer -> max 4ms between two events
  • DOUBLE_MODULE - 32 bit timer -> max 268s between two events


ICOff

Switch off the input capture module.

VOID ICOff(BYTE ic_module)
Argument Description
BYTE ic_module specifies the IC module.
The valid parameters are the following:
  • IC1 - Input Capture 1
  • IC2 - Input Capture 2
  • IC3 - Input Capture 3
  • IC4 - Input Capture 4
  • IC5 - Input Capture 5
  • IC6 - Input Capture 6
  • IC7 - Input Capture 7
  • IC8 - Input Capture 8
  • IC9 - Input Capture 9


ICCounter

Function to get the counter value. It starts from num_edge (see ICOn) and arrives to 0. When it is 0, the input capture sequence is finished.
return - the counter value

BYTE ICCounter(BYTE ic_module)
Argument Description
BYTE ic_module specifies the IC module.
The valid parameters are the following:
  • IC1 - Input Capture 1
  • IC2 - Input Capture 2
  • IC3 - Input Capture 3
  • IC4 - Input Capture 4
  • IC5 - Input Capture 5
  • IC6 - Input Capture 6
  • IC7 - Input Capture 7
  • IC8 - Input Capture 8
  • IC9 - Input Capture 9


ICValue

Function to get the timer value (number of ticks, 1 tick = 0.0625us).
return - the IC event timer
return - -1 the operation was unsuccessful

unsigned long ICValue(BYTE ic_module, BYTE edge_event)
Argument Description
BYTE ic_module specifies the IC module.
The valid parameters are the following:
  • IC1 - Input Capture 1
  • IC2 - Input Capture 2
  • IC3 - Input Capture 3
  • IC4 - Input Capture 4
  • IC5 - Input Capture 5
  • IC6 - Input Capture 6
  • IC7 - Input Capture 7
  • IC8 - Input Capture 8
  • IC9 - Input Capture 9
BYTE edge_event specifies which event must return


ICEdge

Function to get the edge value.
return - 0 falling edge
return - >0 rising edge
return - -1 the operation was unsuccessful

unsigned long ICEdge(BYTE ic_module, BYTE edge_event)
Argument Description
BYTE ic_module specifies the IC module.
The valid parameters are the following:
  • IC1 - Input Capture 1
  • IC2 - Input Capture 2
  • IC3 - Input Capture 3
  • IC4 - Input Capture 4
  • IC5 - Input Capture 5
  • IC6 - Input Capture 6
  • IC7 - Input Capture 7
  • IC8 - Input Capture 8
  • IC9 - Input Capture 9
BYTE edge_event specifies which event must return


ICDecode

Function to get the difference of time between two edges/events.
return - the time in us

float ICDecode(unsigned long data1, unsigned long data2, BYTE ic_module))
Argument Description
unsigned long data1 timer value of the first edge/event
unsigned long data2 timer value of the second edge/event
BYTE ic_module specifies the IC module.
The valid parameters are the following:
  • IC1 - Input Capture 1
  • IC2 - Input Capture 2
  • IC3 - Input Capture 3
  • IC4 - Input Capture 4
  • IC5 - Input Capture 5
  • IC6 - Input Capture 6
  • IC7 - Input Capture 7
  • IC8 - Input Capture 8
  • IC9 - Input Capture 9


Note: ICValue and ICDecode

The value that returns from ICvalue and ICDecode is not a perfect number.
If you use ICDecode with two timer values (from only rising edge) to calculate the period of a signal @1000Hz, it is possible that this value is not 1000us. Sometimes it might be 999us and some other time it might be 1001us and it is impossibile to avoid.

Define - ICHelper

#define IC_SIZE

This sets up the maximum number of edges/events that a single module can report.
eg. if it is set up with "5", it's not possible to intercept 6 events but it's possible to report from 1 to 5 events.
Default:

#define IC_SIZE 5


Related Resources

Credits

Personal tools
Namespaces

Variants
Actions
START HERE
DEVELOPMENT
HARDWARE INFO
RESOURCES
PHASED OUT
Toolbox