📄 etpuc_ppa.c
字号:
| |
+--------------------------------------------------------------------------*/
if ( hsr == INIT_TCR2 ) /* Required for API*/
{
DisableMatchesInThread();
/* set up time base for TCR1*/
ActionUnitA( MatchTCR2, CaptureTCR2, GreaterEqual);
goto init;
}
/*--------------------------------------------------------------------------+
| THREAD NAME: THREAD2 |
| DESCRIPTION: Initialise channel for PPA using TCR1 as timebase. |
|Disable matches in thread in case there are any previous pending matches. |
|This could happen if the channel was running another function before this |
|one. |
|Configure channel to use TCR1. |
|Disable the output buffer as this is an input function. |
|Prevent the pin from toggling as a result of matches on ActionUnitA/B. |
|Clear latches. Set Measurement = Inactive. |
|Configure the channel mode. |
|Enable event handling. |
|Set IPACA/B dependant upon mode |
|Set LastPin dependant upon mode |
| |
+--------------------------------------------------------------------------*/
else if ( hsr == INIT_TCR1 ) /* Required for API*/
{
DisableMatchesInThread();
/* set up time base for TCR1*/
ActionUnitA( MatchTCR1, CaptureTCR1, GreaterEqual);
init:
DisableOutputBuffer(); /* required for Puma */
OnMatchA(NoChange); /* Needed so ouptut pin does not get toggled */
OnMatchB(NoChange); /* Needed so ouptut pin does not get toggled */
ClearAllLatches();
Measurement = Inactive;
SingleMatchSingleTransition(); /* Enable service request when first edge occurs */
EnableEventHandling();
if (PulseMeasurement)
{
/*--------------------------------------------------------------------------+
| STATE NAME: INIT1 |
+--------------------------------------------------------------------------*/
OnTransA(any_trans); /* Detect on any edge on both input capture registers */
OnTransB(any_trans);
CheckPin();
Assign(LastPin,SampledInputPin); /* channel struct member can't be Assigned directly with var. */
}
else /* initialize period measurement */
{
/*--------------------------------------------------------------------------+
| STATE NAME: INIT2 |
+--------------------------------------------------------------------------*/
LastPin = 0; /* Force period measurement to only use states with LastPin=0 */
OnTransB(no_detect);
OnTransA(high_low);
if (RisingEdge) OnTransA(low_high);
}
}
/*--------------------------------------------------------------------------+
| THREAD NAME: THREAD3 |
| DESCRIPTION: |
| Measurement inactive service request, LastPin high |
| If entered due to a transition; then: |
| Latch the pin state and clear transition detect latch |
| Set LastPin to the sample pin state |
| Execute state TRANS1 or TRANS2 or TRANS3 or TRANS4 dependant upon |
| PulseMeasurement/PinSampledState |
| Else must have been entered due to a match; then |
| Execute state MATCH1 |
| NB Can't be period measurement because LastPin must be 0 for Period |
| Measurement |
| |
+--------------------------------------------------------------------------*/
else if (((Measurement==Inactive) && (LastPin==High) && m1) ||
((Measurement==Inactive) && (LastPin==High) && m2))
{
if (Transition_A)
{
CheckPin(); /* Also clears transition flag */
Assign(LastPin,SampledInputPin); /* update Last_Pin state */
if (LowPulse)
{
if (SampledInputPin == 0) /* Start normal low measurement */
{
/*--------------------------------------------------------------------------+
| STATE NAME: TRANS1 |
| Conditions under which this state is executed:- |
| Measurement = Inactive |
| LastPin = High |
| Transition occurred |
| Mode is Low pulse measurement |
| Channel.PSS is 0 |
|Start normal low measurement |
|Record erta in LastTime |
|Clear match flagA |
|Schedule a match SampleTime in the future |
|Set Measurement to Active |
| |
+--------------------------------------------------------------------------*/
Read1Retrig();
Measurement = Active;
}
else /* a short negative pulse occurred */
{
/*--------------------------------------------------------------------------+
| STATE NAME: TRANS2 |
| Conditions under which this state is executed:- |
| Measurement = Inactive |
| LastPin = High |
| Transition occurred |
| Mode is Low pulse measurement |
| Channel.PSS is 1 |
|i.e. a short negative pulse occurred |
|Add short pulse width to Accum |
|Clear match flagA |
|Schedule a match SampleTime in the future |
|If sufficient LowPulses have been accumulated update Result with Accum |
| and Status takes the value of StatAcc; StatAcc get set to 0 |
|Measurement remains Inactive |
| |
+--------------------------------------------------------------------------*/
MeasGlitch(); /* read both capture registers */
CheckCount(); /* Retain inactive state */
}
}
else /* High pulse measurement */
{
if (SampledInputPin == 1) /* Glitched start of high measurement */
{
/*--------------------------------------------------------------------------+
| STATE NAME: TRANS3 |
| Conditions under which this state is executed:- |
| Measurement = Inactive |
| LastPin = High |
| Transition occurred |
| Mode is High pulse measurement |
| Channel.PSS is 1 |
|i.e. a glitch occurred at the start of a high pulse measurement |
|Record ertb in LastTime |
|Clear match flagA |
|Schedule a match SampleTime in the future |
|Set Measurement to Active |
| |
+--------------------------------------------------------------------------*/
Read2Retrig(); /* Start high measurement on second capture edge */
Measurement = Active;
}
else /* First edge goes low, so wait for next edge */
/*--------------------------------------------------------------------------+
| STATE NAME: TRANS4 |
| Conditions under which this state is executed:- |
| Measurement = Inactive |
| LastPin = High |
| Transition occurred |
| Mode is High pulse measurement |
| Channel.PSS is 0 |
|i.e. The first edge was falling |
|Do nothing; wait for next edge |
+--------------------------------------------------------------------------*/
{} /* Do_Nothing */
}
} /* end Transition_A */
else /* It's an invalid match */
{
/*--------------------------------------------------------------------------+
| STATE NAME: MATCH1 |
| Conditions under which this state is executed:- |
| Measurement = Inactive |
| LastPin = High |
| Match occurred |
|This is an invalid match condition |
|Clear match flagA |
| |
+--------------------------------------------------------------------------*/
ClearMatchALatch();
}
} /* end Measurement inactive service request, LastPin high */
/*--------------------------------------------------------------------------+
| THREAD NAME: THREAD4 |
| DESCRIPTION: |
| Measurement inactive service request, LastPin low |
| If entered due to a transition; then: |
| If doing pulse measurement |
| Latch the pin state and clear transition detect latch |
| Set LastPin to the sample pin state |
| Execute state TRANS5 or TRANS6 or TRANS7 or TRANS8 dependant upon |
| PulseMeasurement/PinSampledState |
| Else doing period measurement |
| Execute state TRANS9 |
| Else must have been entered due to a match; then |
| Execute state MATCH2 |
| |
+--------------------------------------------------------------------------*/
else if (((Measurement==Inactive) && (LastPin==Low) && m1) ||
((Measurement==Inactive) && (LastPin==Low) && m2))
{
if (Transition_A)
{
if (PulseMeasurement)
{
CheckPin(); /* Also clears transition flag */
Assign(LastPin,SampledInputPin); /* update Last_Pin state */
if (HighPulse)
{
if (SampledInputPin == 1) /* Start normal high measurement */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -