/******************************************************************************
*
* @file    chipTemperature.c
* @author  ECS, Joseph Zimmer
* @version V1.0.0
* @date    24-04-2019
* @brief       
*
******************************************************************************/

//	--- INCLUDES -----------------------------------------------------------------
#include <stdio.h>
#include "sysdata.h"
#include "shunt_voltage.h"
#include "adc.h"
//	--- EXTERNE VARIABLEN -------------------------------------------------------- 

//	--- LOKALE DEFINES - bitte hier dokumentieren --------------------------------

#define SHUNT_VOLTAGE_DIVIDER       6
//	--- LOKALE TYPE DEFS - bitte hier dokumentieren-------------------------------

//	--- DEFINITIONEN GLOBALER VARIABLEN - Bitte in Header dokumentieren ----------

//	--- LOKALE VARIABLEN - bitte hier dokumentieren ------------------------------

//	--- LOKALE FUNKTIONS PROTOTYPEN ---------------------------------------------- 

//	--- LOKALE FUNKTIONEN - bitte hier dokumentieren -----------------------------

/*
* @brief
* @param	kein
* @retval	kein
*/

//	--- GLOBALE FUNKTIONEN - bitte in Header dokumentieren------------------------



//#define SHUNT_FILTER            128


void SHUNT_VOLTAGE_Exec(int32_t newval)
{
   static unsigned long avgsum = 0;
   uint32_t avgval;
   // Filterlängen in 2er-Potenzen --> Compiler optimiert 
   //avgsum -= avgsum/SHUNT_FILTER;
   //avgsum += newval;
   //avgval = avgsum / SHUNT_FILTER;

   sys_data.s.values.shuntVoltage =  (newval * (uint64_t)sys_data.s.values.realVdd * SHUNT_VOLTAGE_DIVIDER ) / 65536;

}



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