查看: 3029|回复: 1

[S12] 用单片机mc9s12zvl的AD模块控制PWM调光一直不对,求各位大神...

[复制链接]

该用户从未签到

1

主题

1

帖子

0

新手上路

Rank: 1

积分
13
最后登录
2016-10-25
发表于 2016-3-4 17:02:59 | 显示全部楼层 |阅读模式
用s12zvl的AN7口做AD口,硬件接的是一个光度传感器,控制PT3脚的PWM占空比,一直没有成功。请教一下各位大神

#include <hidef.h> /* forEnableInterrupts macro */

#include "derivative.h" /* includeperipheral declarations */

typedef unsigned char bool;

#define ERR_OK           0;

#define ERR_NOTAVAIL    9U;

static volatile word RVL[1] __attribute__ ((aligned (4)));

static volatile bool OutFlg;

static word RatioStore;

char BLUE;

byte* i;



static void SetRatio(void)


{

  PWMDTY1 = (byte)(((0xFFUL * (dword)RatioStore) + 0x8000UL) >> 0x10U); /* Calculate new value according to the given ratio */

}

byte PWM_BLUE_SetRatio8(byte Ratio)

{

  RatioStore = (((word)Ratio << 8U) + 0x80U); /* Store new value of the ratio */

  SetRatio();                          /* Calculate and set up new appropriate values of theduty and period registers */

  return ERR_OK;                       /* OK */

}

void PWM_BLUE_Init(void)

{

    PWMCNT1 = 0x00;

    PWMDTY1 = 0x9F;

    PWMPER1 = 0xFF;

    PWMPRCLK = 0x00;

    PWMSCLA = 0x3B;

    PWMCLK = 0x02;

    PWME = 0x02U;

}

void ADC_Init(void)

{

    ADC0CTL=0x8800;

    ADC0TIM=0x07;

    ADC0FMT=0x00;

    ADC0CMD=0x00170000;

    ADC0STS=0X01;

    ADC0TIM=0X07;

    ADC0CONIE=0x01;

ADC0CONIF=0X01;

ADC0CROFF1=0x00;

ADC0EIF=0x06;

ADC0EIE=0xFC;

    ADC0IF=0xC0;

ADC0IE=0xC0;

}

byte ADC_GetValue8(byte *Values)

{

  if (!OutFlg){                       /* Is measured value(s) available? */

    return ERR_NOTAVAIL;               /* If no then error */

  }

    *Values = (byte)(RVL[0] >> 0x02U);   /* Storeconversion data to user buffer */

  return ERR_OK;                        /* OK */

}


void main(void) {

     PWM_BLUE_Init();

     ADC_Init();

  EnableInterrupts;

  /* includeyour code here */

//for(;;)

//{

    BLUE=ADC_GetValue8(i);


  PWM_BLUE_SetRatio8(BLUE);

//}

  for(;;) {

    __RESET_WATCHDOG();  /* feeds the dog */

   

  } /* loopforever */

  /* pleasemake sure that you never leave main */


}

我知道答案 目前已有1人回答
回复

使用道具 举报

该用户从未签到

145

主题

4926

帖子

0

金牌会员

Rank: 6Rank: 6

积分
9267
最后登录
1970-1-1
发表于 2016-3-7 10:56:23 | 显示全部楼层
非常感谢你的技术问题。非常抱歉中国没有16位单片机方面的技术专家。请您在飞思卡尔的英文论坛提交请求。网址是http://community.freescale.com/welcome 谢谢。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /3 下一条

Archiver|手机版|小黑屋|恩智浦技术社区

GMT+8, 2025-7-17 18:49 , Processed in 0.088508 second(s), 21 queries , MemCache On.

Powered by Discuz! X3.4

Copyright © 2001-2024, Tencent Cloud.

快速回复 返回顶部 返回列表