/***********************************************************
 * パワーパック(低速ブースト・加減速機能PWM型) / PIC16F18857
 * by Hirotsugu Kakugawa
 ***********************************************************/
#include <xc.h>
#include <stdint.h>
#include "mcr.h"
#include "mcr-motor.h"
#include "adc.h"
#include "io.h"
#include "pp.h"
#include "pp-const.h"
#include "pp-sb.h"

/*------------------------------------------------------- 
 * MAIN
 *-------------------------------------------------------*/
void main(void) 
{
  /* システム初期化 */
  System_Init();
  /* ウオッチドッグタイマ: 256 [mSec] */
  WDTCON0bits.WDTPS = 0x08; /* 0b01000 */
  CLRWDT();
  /* モータ出力初期化 */
  MOTOR_DIR_NONE();
  MOTOR_PWM_START();
  /* 低速ブースト初期化 */ 
  pp_sb_init();
  /* 割り込み許可 */ 
  GIE  = 1;
  PEIE = 1;
  /* 主ループ */
  for (;;) {
    CLRWDT();
    /* 制御器の定位置復帰を待機  */
    pp_home_position();
    /* パワーパック走行制御 */
    pp_control();
  }
}

/*--------------------------------------------*/
/* 割込ハンドラ */
void interrupt isr(void)
{
  if ((TMR1IE != 0) && (TMR1IF != 0)) {
    TMR1IF = 0;
    TMR1_isr();
  }
}
