在线时间1 小时
UID3075176
注册时间2015-12-2
NXP金币0
该用户从未签到
新手上路

- 积分
- 13
- 最后登录
- 2015-12-3
|
各位大侠:
小弟刚使用飞思卡尔单片机MK02FN64VFM10。目前使用PDB触发ADC采样,遇到了不能触发转换的问题,代码如下
ADC0_CFG1 |=0x0000000C;//16λADC
ADC0_CFG2 |=0x00000004;//¸ßËÙת»¯
ADC0_SC1A=0x00;
ADC0_SC1A |=0x00000009;//ADC9£¬µ¥¶Ëģʽ
ADC0_SC2 |=0x00000004;//Ó²¼þ´¥·¢×ª»¯
ADC0_SC3 |=0x0000000E;//Á¬Ðø×ª»»
SIM_SCGC6 |= SIM_SCGC6_PDB_MASK ; // 使能时钟
//两个ADC模块,配置他们的触发方式(软硬触发?)
SIM_SOPT7 &= ~(SIM_SOPT7_ADC1ALTTRGEN_MASK | // 由于ADC1可以硬件触发,也可以软件触发,这里选择PDB(软件)触发
SIM_SOPT7_ADC1PRETRGSEL_MASK | // 选择预触发器A
SIM_SOPT7_ADC0ALTTRGEN_MASK | // selects PDB not ALT trigger
SIM_SOPT7_ADC0ALTTRGEN_MASK) ;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SIM_SOPT7 = SIM_SOPT7_ADC0TRGSEL(0); // 选择在PDB模式下,ADC的触发的输入命令源,这里是PDB的外部管脚;103或者111
// PDB external pin input trigger for ADC
SIM_SOPT7 = SIM_SOPT7_ADC1TRGSEL(0); // same for both ADCs
// 配置频率,使能pdb,以及选择pdb的中断触发源,
PDB0_SC = PDB_SC_CONT_MASK //配置成是连续触发还是单发的
| PDB_SC_PDBEN_MASK // PDB enabled
| PDB_SC_PDBIE_MASK // PDB Interrupt Enable
| PDB_SC_PRESCALER(0x5) // 配置分频
| PDB_SC_TRGSEL(0xf) // 中断源选择,这里是软件中断,就是配置触发中断的方式
| PDB_SC_MULT(2); // Multiplication factor 20 for the prescale divider for the counter clock
// the software trigger, PDB_SC_SWTRIG_MASK is not triggered at this time.
PDB0_IDLY = 0x0000; // 软件中断发生时刻,其实也是读取转换值时刻
PDB0_MOD = 0xffff; // 总周期
// channel 0 pretrigger 0 and 1 enabled and delayed
PDB0_CH0C1 = PDB_C1_EN(0x01) //使能通道0预触发模式
| PDB_C1_TOS(0x01) //选择某一PDB通道为ADC的预触发输出
| PDB_C1_EN(0x02)
| PDB_C1_TOS(0x02) ;
PDB0_CH0DLY0 = ADC0_DLYA ; //这里配置0时刻开始,就会去做adc的通道之类的链接
PDB0_CH0DLY1 = ADC0_DLYB ; //到了1时刻就开启ADC了,完成了一次数据转换了,在中断时候提出数据
/ channel 1 pretrigger 0 and 1 enabled and delayed
PDB0_CH1C1 = PDB_C1_EN(0x01)
| PDB_C1_TOS(0x01)
| PDB_C1_EN(0x02)
| PDB_C1_TOS(0x02) ;
PDB0_CH1DLY0 = ADC1_DLYA ;
PDB0_CH1DLY1 = ADC1_DLYB ;
PDB0_SC = PDB_SC_CONT_MASK // Contintuous, rather than one-shot, mode
| PDB_SC_PDBEN_MASK // PDB enabled
| PDB_SC_PDBIE_MASK // PDB Interrupt Enable
| PDB_SC_PRESCALER(0x5) // Slow down the period of the PDB for testing
| PDB_SC_TRGSEL(0xf) // Trigger source is Software Trigger to be invoked in this file
| PDB_SC_MULT(2) // Multiplication factor 20 for the prescale divider for the counter clock
| PDB_SC_LDOK_MASK; // Need to ok the loading or it will not load certain regsiters!
不知道是什么问题,是不是配置PDB的触发不对还是ADC触发形式选择不对?
|
|