PROGRAMA
FINAL
Processor
Expert
/* ###################################################################
** Filename
: ProcessorExpert.c
** Project
: ProcessorExpert
** Processor
: MKL25Z128VLK4
** Version
: Driver 01.01
** Compiler
: GNU C Compiler
** Date/Time
: 2013-11-23, 23:36, # CodeGen: 0
** Abstract
:
** Main module.
** This module contains user's
application code.
** Settings
:
** Contents
:
** No public methods
**
** ###################################################################*/
/*!
** @file ProcessorExpert.c
** @version 01.01
** @brief
** Main module.
** This module contains user's
application code.
*/
/*!
** @addtogroup ProcessorExpert_module
ProcessorExpert module documentation
** @{
*/
/* MODULE ProcessorExpert */
/* Including needed modules to
compile this module/procedure */
#include "Cpu.h"
#include "Events.h"
#include "Lectura_RPM.h"
#include "BitIoLdd1.h"
#include "TI1.h"
#include "TimerIntLdd1.h"
#include "TU1.h"
#include "LED_Lectura.h"
#include "BitIoLdd2.h"
#include "FMSTR1.h"
#include "UART0.h"
#include "PWM1.h"
#include "PwmLdd1.h"
#include "TU2.h"
#include "Cap1.h"
#include "TU3.h"
/* Including shared modules,
which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"
#include "Calculo_RPM.h"
uint16 Sp=0;
/* User includes (#include
below this line is not maintained by Processor Expert) */
/*lint -save -e970 Disable MISRA rule (6.3) checking. */
int main(void)
/*lint -restore Enable MISRA
rule (6.3) checking. */
{
/* Write your local variable definition
here */
/*** Processor Expert internal initialization.
DON'T REMOVE THIS CODE!!! ***/
PE_low_level_init();
/*** End of Processor Expert internal initialization. ***/
/* Write your code here */
Func_Inicia_RPM();
for(;;)
{
Func_RPM_iman();
Func_RPM_opto();
FMSTR1_Poll();
FMSTR1_Recorder();
PWM1_SetRatio16(Sp);
}
/*** Don't write any code pass this
line, or it will be deleted during code generation. ***/
/*** RTOS startup code. Macro
PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
#ifdef PEX_RTOS_START
PEX_RTOS_START(); /* Startup of the selected RTOS.
Macro is defined by the RTOS component. */
#endif
/*** End of RTOS startup code. ***/
/*** Processor Expert end of main
routine. DON'T MODIFY THIS CODE!!! ***/
for(;;){}
/*** Processor Expert end of main
routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
/* END ProcessorExpert */
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert
10.3 [05.08]
** for the Freescale Kinetis
series of microcontrollers.
**
**
###################################################################
*/
Events.c
/*
###################################################################
** Filename
: Events.c
** Project
: ProcessorExpert
** Processor
: MKL25Z128VLK4
** Component
: Events
** Version
: Driver 01.00
** Compiler
: GNU C Compiler
** Date/Time
: 2013-11-23, 23:36, # CodeGen: 0
** Abstract
:
** This is user's event module.
** Put your event handler code here.
** Settings
:
** Contents
:
** Cpu_OnNMIINT - void
Cpu_OnNMIINT(void);
**
**
###################################################################*/
/*!
** @file Events.c
** @version 01.00
** @brief
** This is user's event module.
** Put your event handler code here.
*/
/*!
** @addtogroup Events_module Events
module documentation
** @{
*/
/* MODULE Events */
#include "Cpu.h"
#include "Events.h"
#include "Calculo_RPM.h"
#ifdef __cplusplus
extern "C" {
#endif
/* User includes (#include
below this line is not maintained by Processor Expert) */
/*
**
===================================================================
** Event
: Cpu_OnNMIINT (module Events)
**
** Component
: Cpu [MKL25Z128LK4]
*/
/*!
** @brief
** This event is called when the Non maskable
interrupt had
** occurred. This event is automatically
enabled when the [NMI
** interrupt] property is set to
'Enabled'.
*/
/*
===================================================================*/
void Cpu_OnNMIINT(void)
{
/* Write your code here ... */
}
/*
**
===================================================================
** Event
: TI1_OnInterrupt (module Events)
**
** Component
: TI1 [TimerInt]
** Description :
** When a timer interrupt occurs this event is
called (only
** when the component is enabled -
<Enable> and the events are
** enabled - <EnableEvent>). This
event is enabled only if a
** <interrupt service/event> is
enabled.
** Parameters
: None
** Returns
: Nothing
**
===================================================================
*/
void TI1_OnInterrupt(void)
{
RPM_iman=Vueltas*120;
Vueltas=0;
}
/*
** ===================================================================
** Event
: Cap1_OnCapture (module Events)
**
** Component
: Cap1 [Capture_LDD]
*/
/*!
** @brief
** This event is called on capturing of
counter actual value.
** Component and OnCapture event must be
enabled. See
** [SetEventMask] and [GetEventMask]
methods. This event is
** available only if a [Interrupt
service/event] is enabled.
** @param
** UserDataPtr - Pointer to the user or
** RTOS specific data.
The pointer passed as
** the parameter of Init
method.
*/
/*
===================================================================*/
void Cap1_OnCapture(LDD_TUserData *UserDataPtr)
{
Bande=1;
Cap1_GetCaptureValue(Cap1_DeviceData,&Cuenta_opt_act);
if(Cuenta_opt_act>Cuenta_opt_ant)
{Periodo=Cuenta_opt_act-Cuenta_opt_ant; }
else
{Periodo=(65536-Cuenta_opt_ant)+Cuenta_opt_act; }
Cuenta_opt_ant=Cuenta_opt_act;
}
/* END Events */
#ifdef __cplusplus
} /* extern "C" */
#endif
/*!
** @}
*/
/*
**
###################################################################
**
** This file was created by Processor Expert
10.3 [05.08]
** for the Freescale Kinetis
series of microcontrollers.
**
**
###################################################################
*/
Calculo
RPM.c
Calculo RPM.h
/*
*
Calculo_RPM.c
*
*
Created on: Dec 2, 2013
*
Author: Peter
*/
#include "LED_Lectura.h"
#include "Lectura_RPM.h"
#include "Cap1.h"
#include "Calculo_RPM.h"
void Func_Control_RPM(void)
{
if(RPM_ingre>RPM_opto)
{ RPM_error=RPM_ingre-RPM_opto; }
else if(RPM_ingre<RPM_opto)
{ RPM_error=RPM_opto-RPM_ingre; }
}
void Func_RPM_iman(void)
{
Entrada=Lectura_RPM_GetVal();
if(Entrada)
{Entro=1;}
else
{Salio=1;}
if(Entro&Salio)
{
LED_Lectura_ClrVal();
Vueltas=Vueltas+1;
Entro=0;
Salio=0;
}
LED_Lectura_SetVal();
}
void Func_RPM_opto(void)
{
if(Bande)
{
vuelta_ns=5*Periodo*763;
RPM_opto=(60*1000000)/(vuelta_ns/1000);
Bande=0;
}
}
void Func_Inicia_RPM(void)
{
Vueltas=0;
RPM_iman=0;
RPM_opto=0;
Entro=0;
Salio=1;
Cuenta_opt_ant=0;
Cuenta_opt_act=0;
vuelta_ns=0;
Periodo=0;
}
Calculo RPM.h
/*
* Calculo_RPM.h
*
*
Created on: Dec 2, 2013
* Author: Peter
*/
#ifndef CALCULO_RPM_H_
#define CALCULO_RPM_H_
int Vueltas,
RPM_iman;
bool
Entrada,Entro,Salio,Bande;
uint32 Periodo,
RPM_opto, vuelta_ns, RPM_ingre, RPM_error;
Cap1_TValueType Cuenta_opt_ant, Cuenta_opt_act;
void Func_Inicia_RPM(void);
void Func_RPM_iman(void);
void Func_RPM_opto(void);
void Func_Control_RPM(void);
#endif /* CALCULO_RPM_H_ */
No hay comentarios:
Publicar un comentario