亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? bldc.c

?? 基于ATMEGA48單片機的
?? C
字號:
 
 
#include "BLDC.h"

#include <avr/io.h>
#include <avr/signal.h>
#include <avr/interrupt.h>

/*! \brief CCW rotation patterns.
 *
 * Configuration of pin drive levels
 * and timer COM bits in different
 * phases for CounterClockWise rotation.
 */
unsigned char drvPatternsCCW[] = {//逆時針旋轉(zhuǎn)
  0,    //Stop
  // MC_PORT drive config//單片機端口驅(qū)動配置
  PDP2_CCW, //Phase2     //相序2
  PDP4_CCW, //Phase4
  PDP3_CCW, //Phase3
  PDP6_CCW, //Phase6
  PDP1_CCW, //Phase1
  PDP5_CCW, //Phase5
  // Configuration of Output Compare operation for timer 0//定時器0輸出
  COM0P2_CCW, //Phase2
  COM0P4_CCW, //Phase4
  COM0P3_CCW, //Phase3
  COM0P6_CCW, //Phase6
  COM0P1_CCW, //Phase1
  COM0P5_CCW, //Phase5
  // Configuration of Output Compare operation for timer 2
  COM2P2_CCW, //Phase2
  COM2P4_CCW, //Phase4
  COM2P3_CCW, //Phase3
  COM2P6_CCW, //Phase6
  COM2P1_CCW, //Phase1
  COM2P5_CCW  //Phase5
};



/*! \brief CW rotation patterns.
 *
 * Configuration of pin drive levels
 * and timer COM bits in different
 * phases for ClockWise rotation.
 */
unsigned char drvPatternsCW[] = {//順時針旋轉(zhuǎn)
  0,    //Stop
  // MC_PORT drive config
  PDP2_CW, //Phase2
  PDP6_CW, //Phase6
  PDP1_CW, //Phase1
  PDP4_CW, //Phase4
  PDP3_CW, //Phase3
  PDP5_CW,  //Phase5
  // Configuration of Output Compare operation for timer 0
  COM0P2_CW, //Phase2
  COM0P6_CW, //Phase6
  COM0P1_CW, //Phase1
  COM0P4_CW, //Phase4
  COM0P3_CW, //Phase3
  COM0P5_CW,  //Phase5
  // Configuration of Output Compare operation for timer 2
  COM2P2_CW, //Phase2
  COM2P6_CW, //Phase6
  COM2P1_CW, //Phase1
  COM2P4_CW, //Phase4
  COM2P3_CW, //Phase3
  COM2P5_CW  //Phase5
};



//! Stores the current motor driver pattern.存儲當前電機驅(qū)動波形
//__regvar __no_init unsigned char *pDrvPattern @14;
unsigned char *pDrvPattern;//更改
//__regvar __no_init unsigned char *pComPattern @12;



//! Used for optimized temporary varables.
//__regvar __no_init union _fastTemp{
/*
union fastTemp{//更改
  unsigned int word;
  struct{
    unsigned char LByte;
    unsigned char HByte;  //Hbyte = Zero
  };
};//fastTemp @12;//更改*/

union  temp{
     unsigned   int  word;
      struct  egal{
             unsigned   char  LByte;
         unsigned   char  HByte; 
    }egal;
  }fastTemp;
//__regvar __no_init unsigned char hallMask @11; //!< Workaround for internal compiler error
//__regvar __no_init unsigned char count @10; //!< Optimized variable decremented every pin change int.
unsigned char hallMask;//更改
unsigned char count;//更改


/*! \brief  Pin Change Interrupt Service Routine.
 *
 * Updates the PWM outputs controlling the low side of the driver and
 * the IO controlling the high side of the driver. To ensure a speed
 * optimal interrupt the variables used in the interrupt are placed
 * in reserved registers (locked for this purpose only). Further, the
 * information required to do the commutation is placed in tables that
 * are accessed very efficiently using the Hall sensor input signals
 * as offset.
 *
 *  \param void
 *
 *  \return void
 */
//#pragma vector = PCINT0_vect
//#pragma vector = PCINT0_ISR//更改
//!
//__interrupt void PCINT0_ISR( void )//更改

SIGNAL (SIG_OVERFLOW0)
{
  //unsigned char fastTemp.word;
  unsigned char *pTemp;
  fastTemp.word = ((PIN_HALL & hallMask)>>1);  // Read Hall, Mask Pins, shift to use as pointer offset
//  Line below is desirable performance wise, but causes an internal error in compiler
//  fastTemp.LByte = (PIN_HALL & HALL_MASK)>>1;   // Read Hall, Mask Pins, shift to use as pointer offset

  pTemp = pDrvPattern + fastTemp.word;
//  TCCR0A = fastTemp.HByte; //Disable PWM outputs (and thereby close low side FET)
//  TCCR2A = fastTemp.HByte; //Disable PWM output (and thereby close low side FET)

  PORT_MC = *(pTemp);    //Change drive levels on high side

  TCCR0A = *(pTemp + PATTERN_COM0_OFFSET);    // Reconfigure output compare operation for T0
  TCCR2A = *(pTemp + PATTERN_COM2_OFFSET);    // Reconfigure output compare operation for T2
  count--;
}



/*! \brief  Initialize pin change interrupts for PORTB pin 1, 2 and 3.
 *
 * Sets up the pins used to sense the Hall sensor signals to generate
 * interrupt if the pin level changes (both rising and falling edge).
 *
 *  \param void
 *
 *  \return void
 */
static void Init_MC_pin_change_interrupt( void )
{
  PCMSK0 = (1<<PCINT1)|(1<<PCINT2)|(1<<PCINT3); //Enable pin change interrupt on PB1:3
  PCICR = 1<<PCIE0;    // Enable pin change interrupt0 (PORTB)
}



/*! \brief  Start an AD convertion and return result.
 *
 * Starts an AD conversion on the specified ADC channel and returns
 * the result when the conversin is completed. Uses polling to wait for
 * the AD conversion to complete.
 *
 *  \param channel Specify the ADMUX register settings to access the correct channel.
 *
 *  \return adcResult 8-bit result (high byte of AD convertion).
 */
unsigned char Get_ADC8(unsigned char muxSetting)
{
    ADMUX = muxSetting;
    // Start AD conversion.
    ADCSRA |= (1 << ADSC);
    // Wait for ADC conversion to complete.
    while ( ADCSRA & (1 << ADSC) );
    return ADCH;
}


//!
/*! \brief  Initialize motor control timers.
 *
 * Initialize the Timer 1 and timer 2 to run in phase and frequency correct
 * PWM mode (symmetric PWM). The base frequency is set to 32kHz (can be
 * reduced at the expense of lower resolution on the speed control). The
 * functions also ensures that the timers are counting in synch.
 *
 *  \param void
 *
 *  \return void
 */
static void Init_MC_timers( void )
{
  //Timer Counter 0. OCRA and OCRB used for motor
  TCCR0A = (1<<COM0A1)|(0<<COM0A0)|        // Clear OCRA on compare match
           (1<<COM0B1)|(0<<COM0B0)|        // Clear OCRB on compare match
           (1<<WGM01)|(1<<WGM00);         // Fast PWM mode
  TCCR0B = (0<<FOC0A)|(0<<FOC0B)|
           (0<<WGM02)|                     // Fast PWM mode
           (0<<CS02)|(0<<CS01)|(1<<CS00); // Prescaler = CLK/1

  //Timer Counter 2. OCRA and OCRB used for motor
  TCCR2A = (0<<COM2A1)|(0<<COM2A0)|        // OCRA not connected
           (1<<COM2B1)|(0<<COM2B0)|        // Clear OCRB on compare match
           (1<<WGM01)|(1<<WGM00);         // Fast PWM mode
  TCCR2B = (0<<FOC2A)|(0<<FOC2B)|
           (0<<WGM22)|                     // Fast PWM mode
           (0<<CS22)|(0<<CS21)|(1<<CS20); // Prescaler = CLK/1

  // Synchronize timers
  TCNT0 = 0;
  TCNT2 = 3;

  TIFR0 = TIFR0;    // Clear TC0 interrupt flags
  TIFR1 = TIFR1;    // Clear TC2 interrupt flags
}



/*! \brief Initialize ADC module.
 *
 * Sets up the ADC with prescaler value 4, which means a maximum sample speed
 * of CPU frequency divided by 52 (13*4). With the ADC measuring the speed set
 * point and shunt voltage, this gives a reaction time of two samples for
 * detecting over-current.
 *
 *  \param void
 *
 *  \return void
 */
static void Init_ADC( void )
{
  ADCSRA = (1 << ADEN) | (1 << ADPS1); // Enable ADC, clock prescaler = 4
}



/*! \brief Set motor speed.
 *
 * Updates the output compare registers of the timer 0 and timer 2 which
 * control the duty cycle of the PWM output and thereby the speed of the
 * motor. The method used ensures that that all PWM channels are behaving
 * same duty cycle.
 *
 *  \param speed Compare match value that defines PWM duty cycle.
 *
 *  \return void
 */
static void Set_Speed(unsigned char speed)
{
  TIFR0 = TIFR0;    // Clear TC0 interrupt flags//         清除TC0中斷標志
  while( !(TIFR0 & (1<<TOV0)));  // Wait for TOV to ensure that all registers are
                            //  updated in the same timer cycle
  //__disable_interrupt();
  //disable_interrupt();//更改
  sei();
  OCR0A = speed;        // Change the duty cycle//改變占空比系數(shù)
  OCR0B = speed;
  OCR2B = speed;
  //__enable_interrupt();
  //enable_interrupt();//更改
  cli();
}



/*! \brief Set motor direction, CW og CCW.
 *
 * Set the commutation table pointer up to point at either the clockwise
 * or counter clockwise direction table. Note that it is not recommended
 * to change direction without first reducing the speed of the motor,
 * preferably stopping it fully.
 *
 *  \param direction Direction is given as Clockwise or Counter Clockwise.
 *
 *  \return void
 */
static void Set_Direction(unsigned char direction)
{
  if(direction == CLOCKWISE)
  {
    //__disable_interrupt();        //Variable also used in interrupt and access most be protected
//    disable_interrupt();//更改
	sei();
	pDrvPattern = drvPatternsCW;   // Set dir to CW, by pointing to CW pattern
    //__enable_interrupt();
//	enable_interrupt();//更改
    cli();
  }
  else
  {
    //__disable_interrupt();        //Variable also used in interrupt and access most be protected
//    disable_interrupt();//更改
	sei();
	pDrvPattern = drvPatternsCCW;   // Set dir to CCW, by pointing to CCW pattern
    //__enable_interrupt();
	//enable_interrupt();//更改
	cli();
  }
}


/*! \brief Main function for motor control example.
 *
 * Initialize speed variables to zero speed, and enabled operation in clockwise
 * direction. Hence a speed reference input is read from ADC_MUX_SPEED_REF. If
 * Current exeeds the MAX_CURRENT_ADC limit the speed (PWM duty cycle) is reduced.
 *
 *  \param void
 *
 *  \return void
 */
//void main( void )
int main( void )
{
  unsigned char speed = 100;
  unsigned char setspeed = 100;
  signed int current;
  MCUCR |= (1<<PUD);  // Disable all pull-ups
  hallMask = HALL_MASK; // Initialize hallMask variable
  //Set initial direction.
  Set_Direction( CLOCKWISE );

  Init_MC_timers();
  Init_MC_pin_change_interrupt();
  Init_ADC();

  DDR_HALL |= HALL_MASK;    //Lock HALL sensor by driving Hall lines
  PORT_HALL |= HALL_MASK;
  PORT_HALL &= ~HALL_MASK;  //Release HALL sensor lines and trigger PC interrupt
  DDR_HALL &= ~HALL_MASK;
  //__enable_interrupt();//更改
//  enable_interrupt();
  cli();
  Set_Speed(speed);
  DDR_MC = MC_MASK;        // Enable outputs

  DDRC |= (1<<PC1);
  for(;;) {
    // Get shunt voltage (current measurement)
    current = Get_ADC8(ADC_MUX_SHUNT_H);
    // If current consumption is too high, limit current
    if (current > MAX_CURRENT_ADC )
    {
      PORTC &= ~(1<<OVERCURRENT_PIN);   //Turn on over-current LED (active low)
      if( speed >= 2 )
      {
        speed -= 2; // Slow down if too fast.
      }
    }
    else
    {
      PORTC |= (1<<OVERCURRENT_PIN); // Turn off over-current LED (active low)
      // Get speed reference voltage (Assumes 2.5V to be maximum analog input,
      // multiplied by 2 to convert to PWM range).
      setspeed = Get_ADC8(ADC_MUX_SPEED_REF)*2;
      // Approach speed set point.
      if( setspeed > speed )
      {
        ++speed;
      }
      else
      {
        if( setspeed < speed )
        {
          --speed;
        }
      }
    }

    Set_Speed(speed);
  }
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲成国产人片在线观看| 欧美一区二区啪啪| 国产揄拍国内精品对白| 亚洲超碰精品一区二区| 亚洲午夜免费视频| 亚洲一区精品在线| 亚洲综合丝袜美腿| 亚洲一级电影视频| 亚洲电影在线免费观看| 日韩高清电影一区| 秋霞影院一区二区| 久久成人麻豆午夜电影| 久久精品国产999大香线蕉| 久久精品99国产精品日本| 精品中文字幕一区二区小辣椒| 久久精品久久久精品美女| 久久精品国产网站| 国产一区二区三区在线观看精品 | 欧美极品xxx| 国产精品视频你懂的| 国产精品久久久久久久久免费相片 | jlzzjlzz欧美大全| 日本aⅴ亚洲精品中文乱码| 亚洲国产精品欧美一二99| 亚洲黄色av一区| 亚洲丶国产丶欧美一区二区三区| 亚洲一区二区三区在线播放| 亚洲成人黄色小说| 韩国欧美国产1区| eeuss鲁片一区二区三区| 91极品视觉盛宴| 欧美一区二区三区男人的天堂| 久久夜色精品国产欧美乱极品| 中文久久乱码一区二区| 亚洲国产精品天堂| 国产原创一区二区三区| 色88888久久久久久影院按摩| 日韩一二三区视频| 中文字幕永久在线不卡| 免费xxxx性欧美18vr| 丁香激情综合国产| 制服.丝袜.亚洲.中文.综合| 亚洲国产成人一区二区三区| 亚洲成人精品一区| 成人免费va视频| 日韩一区二区不卡| 亚洲激情图片qvod| 国产精品亚洲综合一区在线观看| 欧美性视频一区二区三区| 久久久久久夜精品精品免费| 亚洲一区在线观看免费观看电影高清 | 亚洲国产欧美在线人成| 国产精品亚洲人在线观看| 欧美中文字幕亚洲一区二区va在线| 成人听书哪个软件好| 日韩一区二区在线免费观看| 一区二区三区 在线观看视频| 国产精品一区二区久激情瑜伽| 欧美精品九九99久久| 一区二区三区四区激情 | 中文字幕一区二区三区不卡| 蜜桃视频一区二区三区| 欧美亚洲免费在线一区| 欧美国产欧美亚州国产日韩mv天天看完整 | 国产欧美日韩另类视频免费观看| 亚洲午夜久久久久久久久电影院| 国产不卡在线播放| 国产夜色精品一区二区av| 理论电影国产精品| 欧美久久久久久久久中文字幕| 亚洲免费在线电影| 91一区二区三区在线播放| 国产欧美日韩亚州综合| 国产传媒日韩欧美成人| 精品国产1区二区| 麻豆精品视频在线| 日韩一级在线观看| 蜜桃免费网站一区二区三区| 欧美综合亚洲图片综合区| 国产精品久久久久一区二区三区| 成人免费毛片嘿嘿连载视频| 国产欧美一区二区三区在线看蜜臀| 国产精品一色哟哟哟| 国产欧美一区视频| 91亚洲国产成人精品一区二三| 亚洲欧美影音先锋| 色域天天综合网| 亚洲一区二区中文在线| 欧美日韩中文字幕精品| 日韩不卡一区二区三区| 在线观看免费视频综合| 亚洲成年人影院| 欧美va亚洲va在线观看蝴蝶网| 精品一区二区在线视频| 久久久久久久久久久99999| 国产一区二区三区四| 国产日韩欧美a| 懂色av一区二区三区免费观看| 中文字幕亚洲综合久久菠萝蜜| 国产欧美一二三区| 亚洲福利视频三区| 欧美大尺度电影在线| 婷婷开心激情综合| 欧美日韩综合在线免费观看| 亚洲国产日韩在线一区模特 | 亚洲欧洲美洲综合色网| 亚洲六月丁香色婷婷综合久久| 美女mm1313爽爽久久久蜜臀| 九九视频精品免费| 高清在线不卡av| 日本一区二区电影| 成人蜜臀av电影| 亚洲免费色视频| 91女厕偷拍女厕偷拍高清| 亚洲色图一区二区| 99久久伊人网影院| 亚洲欧美偷拍三级| 色狠狠一区二区| 亚洲一区二区在线免费看| 在线视频综合导航| 亚洲成人自拍网| 日韩欧美一级在线播放| 国产丶欧美丶日本不卡视频| 中文字幕精品一区| 色综合久久中文综合久久97| 亚洲一区在线观看免费| 欧美一区午夜精品| 国产精品18久久久久久vr| 日韩欧美电影一区| 国产一区二区三区香蕉| 国产精品网曝门| 日韩视频一区二区| 欧美中文字幕一区二区三区亚洲| 麻豆精品一二三| 中文字幕成人av| 欧美性生活大片视频| 欧美bbbbb| 中文字幕字幕中文在线中不卡视频| 95精品视频在线| 美女尤物国产一区| 中文字幕av一区二区三区| 成+人+亚洲+综合天堂| 亚洲无人区一区| 久久久久9999亚洲精品| 首页国产欧美久久| 精品欧美一区二区在线观看| 中文字幕亚洲欧美在线不卡| 亚洲午夜久久久久| 日韩午夜激情电影| 99久久精品国产观看| 理论片日本一区| 一区二区三区在线免费观看| 国产精品99久久久久久似苏梦涵| 亚洲免费av高清| 久久精品欧美一区二区三区不卡 | 五月天激情小说综合| 欧美成人三级电影在线| 99re成人在线| 激情文学综合丁香| 亚洲国产精品尤物yw在线观看| 中文字幕久久午夜不卡| 国产精品盗摄一区二区三区| 日韩一区二区免费电影| 欧美视频精品在线观看| 成人h动漫精品一区二区| 国产资源精品在线观看| 五月天视频一区| 亚洲午夜久久久久久久久电影网| 欧美精品18+| 色妞www精品视频| 粉嫩av一区二区三区在线播放| 国产人成亚洲第一网站在线播放| 国产.精品.日韩.另类.中文.在线.播放 | 国产一区二区三区香蕉| 日韩中文字幕av电影| 亚洲综合成人在线| 一区二区三区蜜桃| 亚洲天堂中文字幕| 欧美视频自拍偷拍| 久久精品国产一区二区| 亚洲777理论| 天使萌一区二区三区免费观看| 亚洲精品ww久久久久久p站| 亚洲青青青在线视频| 国产精品视频一二三区| 中文字幕一区二区不卡| 亚洲欧美综合另类在线卡通| 中文字幕中文字幕在线一区| 国产精品你懂的| 亚洲视频 欧洲视频| 久久精品二区亚洲w码| 一本到高清视频免费精品| 色综合久久久久综合| 91福利在线免费观看| 欧美亚洲国产一区二区三区va| 欧美日韩国产美| 欧美一卡二卡三卡四卡| 精品国免费一区二区三区| www激情久久| 欧美国产一区二区|