/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
* File Name          : MC_stm8s_ACIM_param.h
* Author             : IMS Systems Lab 
* Date First Issued  : mm/dd/yyy
* Description        : 
********************************************************************************
* History:
* mm/dd/yyyy ver. x.y.z
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* THIS SOURCE CODE IS PROTECTED BY A LICENSE.
* FOR MORE INFORMATION PLEASE CAREFULLY READ THE LICENSE AGREEMENT FILE LOCATED
* IN THE ROOT DIRECTORY OF THIS FIRMWARE PACKAGE.
*******************************************************************************/

#ifndef __MC_STM8S_ACIM_PARAM_H
#define __MC_STM8S_ACIM_PARAM_H

#define BUS_ADC_CHANNEL ADC2_CHANNEL_3
#define BUS_ADC_PORT GPIOB
#define BUS_ADC_PIN GPIO_PIN_3

#define HEATSINK_ADC_CHANNEL ADC2_CHANNEL_8
#define HEATSINK_ADC_PORT GPIOE
#define HEATSINK_ADC_PIN GPIO_PIN_7

#define USER1_ADC_CHANNEL ADC2_CHANNEL_9
#define USER1_ADC_PORT GPIOE
#define USER1_ADC_PIN GPIO_PIN_6

const u8 SINE3RDHARM[256] = {
  0,5,11,16,21,27,32,37,42,47,52,57,
  61,66,70,75,79,83,86,90,93,97,100,103,
  105,108,110,113,115,116,118,120,121,122,123,124,
  125,126,126,126,127,127,127,127,127,127,127,126,
  126,126,126,125,125,125,124,124,124,123,123,123,
  123,122,122,122,122,122,122,122,123,123,123,123,
  124,124,124,125,125,125,126,126,126,126,127,127,
  127,127,127,127,127,126,126,126,125,124,123,122,
  121,120,118,116,115,113,110,108,105,103,100,97,
  93,90,86,83,79,75,70,66,61,57,52,47,
  42,37,32,27,21,16,11,5,
  
  0,5,11,16,21,27,32,37,42,47,52,57,
  61,66,70,75,79,83,86,90,93,97,100,103,
  105,108,110,113,115,116,118,120,121,122,123,124,
  125,126,126,126,127,127,127,127,127,127,127,126,
  126,126,126,125,125,125,124,124,124,123,123,123,
  123,122,122,122,122,122,122,122,123,123,123,123,
  124,124,124,125,125,125,126,126,126,126,127,127,
  127,127,127,127,127,126,126,126,125,124,123,122,
  121,120,118,116,115,113,110,108,105,103,100,97,
  93,90,86,83,79,75,70,66,61,57,52,47,
  42,37,32,27,21,16,11,5	
};

#define BUSVOLT_BUFFER_SIZE (u8)16//number of averaged acquisitions@BUS_SAMPLING_FREQ
#define HEATSINK_SAMPLING_FREQ 50 //Hertz
#define USERADC_SAMPLING_FREQ 50 //Hertz
#define STARTUP_ANGLE 16384 //0-2pi -> 0-65535

//parameters below not to be modified
#if (PWM_U_HIGH_SIDE_POLARITY==ACTIVE_HIGH)
#define DEV_PWM_U_HIGH_SIDE_POLARITY   TIM1_OCPOLARITY_HIGH
#else
#define DEV_PWM_U_HIGH_SIDE_POLARITY   TIM1_OCPOLARITY_LOW
#endif
#if (PWM_V_HIGH_SIDE_POLARITY==ACTIVE_HIGH)
#define DEV_PWM_V_HIGH_SIDE_POLARITY   TIM1_OCPOLARITY_HIGH
#else
#define DEV_PWM_V_HIGH_SIDE_POLARITY   TIM1_OCPOLARITY_LOW
#endif
#if (PWM_W_HIGH_SIDE_POLARITY==ACTIVE_HIGH)
#define DEV_PWM_W_HIGH_SIDE_POLARITY   TIM1_OCPOLARITY_HIGH
#else
#define DEV_PWM_W_HIGH_SIDE_POLARITY   TIM1_OCPOLARITY_LOW
#endif

#if (PWM_U_LOW_SIDE_POLARITY==ACTIVE_HIGH)
#define DEV_PWM_U_LOW_SIDE_POLARITY   TIM1_OCNPOLARITY_HIGH
#else
#define DEV_PWM_U_LOW_SIDE_POLARITY   TIM1_OCNPOLARITY_LOW
#endif
#if (PWM_V_LOW_SIDE_POLARITY==ACTIVE_HIGH)
#define DEV_PWM_V_LOW_SIDE_POLARITY   TIM1_OCNPOLARITY_HIGH
#else
#define DEV_PWM_V_LOW_SIDE_POLARITY   TIM1_OCNPOLARITY_LOW
#endif
#if (PWM_W_LOW_SIDE_POLARITY==ACTIVE_HIGH)
#define DEV_PWM_W_LOW_SIDE_POLARITY   TIM1_OCNPOLARITY_HIGH
#else
#define DEV_PWM_W_LOW_SIDE_POLARITY   TIM1_OCNPOLARITY_LOW
#endif

#if (PWM_U_HIGH_SIDE_IDLE_STATE==INACTIVE)
#define DEV_PWM_U_HIGH_SIDE_IDLE_STATE TIM1_OCIDLESTATE_RESET
#else
#define DEV_PWM_U_HIGH_SIDE_IDLE_STATE TIM1_OCIDLESTATE_SET
#endif
#if (PWM_V_HIGH_SIDE_IDLE_STATE==INACTIVE)
#define DEV_PWM_V_HIGH_SIDE_IDLE_STATE TIM1_OCIDLESTATE_RESET
#else
#define DEV_PWM_V_HIGH_SIDE_IDLE_STATE TIM1_OCIDLESTATE_SET
#endif
#if (PWM_W_HIGH_SIDE_IDLE_STATE==INACTIVE)
#define DEV_PWM_W_HIGH_SIDE_IDLE_STATE TIM1_OCIDLESTATE_RESET
#else
#define DEV_PWM_W_HIGH_SIDE_IDLE_STATE TIM1_OCIDLESTATE_SET
#endif

#if (PWM_U_LOW_SIDE_IDLE_STATE==INACTIVE)
#define DEV_PWM_U_LOW_SIDE_IDLE_STATE  TIM1_OCNIDLESTATE_RESET
#else
#define DEV_PWM_U_LOW_SIDE_IDLE_STATE  TIM1_OCNIDLESTATE_SET
#endif
#if (PWM_V_LOW_SIDE_IDLE_STATE==INACTIVE)
#define DEV_PWM_V_LOW_SIDE_IDLE_STATE  TIM1_OCNIDLESTATE_RESET
#else
#define DEV_PWM_V_LOW_SIDE_IDLE_STATE  TIM1_OCNIDLESTATE_SET
#endif
#if (PWM_W_LOW_SIDE_IDLE_STATE==INACTIVE)
#define DEV_PWM_W_LOW_SIDE_IDLE_STATE  TIM1_OCNIDLESTATE_RESET
#else
#define DEV_PWM_W_LOW_SIDE_IDLE_STATE  TIM1_OCNIDLESTATE_SET
#endif

#ifdef BKIN
#define TIM1_BREAK_STATUS TIM1_BREAK_ENABLE 
#else
#define TIM1_BREAK_STATUS TIM1_BREAK_DISABLE
#endif

#if (BKIN_POLARITY == ACTIVE_LOW)
#define DEV_BKIN_POLARITY TIM1_BREAKPOLARITY_LOW 
#else
#define DEV_BKIN_POLARITY TIM1_BREAKPOLARITY_HIGH
#endif

#ifdef PWM_LOWSIDE_OUTPUT_ENABLE
#define DEV_OUTPUTNSTATE TIM1_OUTPUTNSTATE_ENABLE
#else
#define DEV_OUTPUTNSTATE TIM1_OUTPUTNSTATE_DISABLE
#endif

#endif /* __MC_STM8S_ACIM_PARAM_H */
 // (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE***
