Вы находитесь на странице: 1из 2

/****************************************************************************

Module
Knob.c
Revision
1.0.1
Description
This is the module for initializing and reading Knob (analog input)

Notes
History
When Who
-------------- ---
****************************************************************************/
/*----------------------------- Include Files -----------------------------*/
/* include header files for this state machine as well as any machines at the
next lower level in the hierarchy that are sub-machines to this machine
*/
#include "ES_Configure.h"
#include "ES_Framework.h"
#include "ES_Port.h"
#include "ES_Events.h"
#include "ES_Timers.h"
#include "termio.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "inc/hw_sysctl.h"
#include "driverlib/sysctl.h"
#include "driverlib/pin_map.h" // Define PART_TM4C123GH6PM in project
#include "driverlib/gpio.h"
#include "Knob.h"
#include "ADMulti.h"

/*---------------------------- Module Variables ---------------------------*/


// with the introduction of Gen2, we need a module level Priority variable
static uint32_t results[1];
/*------------------------------ Module Code ------------------------------*/
/****************************************************************************
Function
InitKnob
Parameters: none
Returns: none
Description : Init PE0 to be analog input channel
****************************************************************************/
void InitKnob (void){
//Init PE0 to be analog input channel on TIVA using ADMulti library
ADC_MultiInit(1);
}

/****************************************************************************
Function
GetKnobValue
Parameters: None
Returns: a float variable which indicates the scaled knob value
****************************************************************************/
float GetKnobValue(void){
//read analog input channel
ADC_MultiRead(results);
//save the A/D result in KnobValue (uint32_t)
uint32_t KnobValue = results[0];
//convert KnobValue to a ratio between 0 and 1, the range of KnobValue is 0-4095
float KnobRatio = KnobValue/4095.0;
//properly normalize the fraction, save it in KnobRatioNormalized
float KnobRatioNormalized = ((KnobRatio-0.65)/(1.0-0.65))*0.35; //the range of
KnobRaio is between 0.65 and 1
//return KnobRatioNormalized
return KnobRatioNormalized;
}

/*------------------------------- Footnotes -------------------------------*/


/*------------------------------ End of file ------------------------------*/

Вам также может понравиться