read_acquisitionadc.c

来自「avr atmega frimily 使用PWM控制交流电机」· C语言 代码 · 共 35 行

C
35
字号
/**
* @file space_vector_PWM.c
*
* Copyright (c) 2004 Atmel.
*
* @brief Ce fichier permet de
*
* This file is included by all source files in order to access to system wide
* configuration.
* @version 1.0 (CVS revision : 1.2)
* @date 2006/03/08 17:03:49 (created on 06/04/2004)
* @author raubree (created by Emmanuel David)

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

#include "config.h"
#include "inavr.h"

// speed measurement thanks to the ADC
S16 read_acquisition(void)
{
    Union16     resultADC ;

    LSB(resultADC) = ADCL ;  // the ADC output has 10 bit resolution
    MSB(resultADC) = ADCH ;

    // convert from shifted code to 2's complement code
    // when the ADC output is higher than 512, the measure is positive
    // when the ADC output is lower  then 512, the measure is negative
//    if ( (resultADC.b[1] & 0x02) == 2) resultADC.b[1] &= 0x01 ;
//      else resultADC.b[1] |= 0xFE ;

    return (resultADC.w) ;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?