dsPIC33FJ128MC506的ADC中断问题

2019-03-25 18:59发布

看书上的程序,一直没有看到有ADC的中断,在AD采样程序中,有对DMA0的中断使能,但是没有对ADC的中断使能。
1、对于AD1CON2的SMPI
QQ截图20160712154411.png                                                                                          
这里的中断是什么含义呢?(个人理解,对于有DMA的单片机,是不是只有地址的递增速率这一概念而没有中断了呢?不知道这样对不对)。
2、在DMA0的中断程序执行中(应该是由HALF确定,当数据传输一半或者传输完成产生中断),ADC是否还在采样?程序上只见到ADC的使能置为1,没有看到手动程序关闭ADC,那么是不是就是ADC一直在采样?在DMA0中断程序的时候也执行?还是说DMA0中断的优先级更高,这个时候不响应ADC?
3、AD1CON1的SSRC位,设置为由定时器3比较结束采样并启动转换,这个算是中断吗?相当于定时器的中断?
4、下面的程序中,void __attribute__((__interrupt__)) _DMA0Interrupt(void)这个DMA0的中断,是执行到哪里的时候会跳到这个中断啊?
5、我现在的想法是,用定时器,设计一段时间内就是采样,然后另一端时间用来处理数据,并传输,相隔固定时间执行这一过程。参考下面的程序,貌似处理数据应该在DMA0的中断程序中执行,如果是这样,那是否需要先将AD使能关闭?能否帮忙理一下思路呢?

不知道我能否清楚表达自己的问题,本人小白,刚开始学习PIC单片机,希望大家帮帮忙~~这里附上手册上的采样示例(不同时扫描采样)。

#if defined(__dsPIC33F__)
#include "p33fxxxx.h"
#elif defined(__PIC24H__)
#include "p24hxxxx.h"
#endif
void ProcessADCSamples(unsigned int * AdcBuffer);
/*==========================================================================================
ADC Initialization for Channel Scan
===========================================================================================*/
void initAdc1(void)
{
AD1CON1bits.FORM = 3; // Data Output Format:Signed Fraction (Q15 format)
AD1CON1bits.SSRC = 2; // Sample Clock Source:GP Timer starts conversion
AD1CON1bits.ASAM = 1; // ADC Sample Control:Sampling begins immediately after conversion
AD1CON1bits.AD12B = 0; // 10-bit ADC operation
AD1CON1bits.SIMSAM = 0; // Samples multiple channels individually in sequence
AD1CON2bits.BUFM = 0;
AD1CON2bits.CSCNA = 1; // Scan Input Selections for CH0+ during Sample A bit
AD1CON2bits.CHPS = 0; // Converts CH0
AD1CON3bits.ADRC = 0; // ADC Clock is derived from Systems Clock
AD1CON3bits.ADCS = 63; // ADC Conversion Clock
//AD1CHS0:A/D Input Select Register
AD1CHS0bits.CH0SA = 0; // MUXA +ve input selection (AIN0) for CH0
AD1CHS0bits.CH0NA = 0; // MUXA -ve input selection (Vref-) for CH0

//AD1CHS123:A/D Input Select Register
AD1CHS123bits.CH123SA = 0; // MUXA +ve input selection (AIN0) for CH1
AD1CHS123bits.CH123NA = 0; // MUXA -ve input selection (Vref-) for CH1
//AD1CSSH/AD1CSSL:A/D Input Scan Selection Register
AD1CSSH = 0x0000;
AD1CSSL = 0x000F; // Scan AIN0, AIN1, AIN2, AIN3 inputs
AD1CON1bits.ADDMABM = 0; // DMA buffers are built in scatter/gather mode
AD1CON2bits.SMPI = 3; // 4 ADC buffers
AD1CON4bits.DMABL = 3; // Each buffer contains 8 words
IFS0bits.AD1IF = 0; // Clear the A/D interrupt flag bit
IEC0bits.AD1IE = 0; // Do Not Enable A/D interrupt
AD1CON1bits.ADON = 1; // Turn on the A/D converter
}
/*======================================================================================
Timer 3 is setup to time-out every 125 microseconds (8Khz Rate).As a result, the module
will stop sampling and trigger a conversion on every Timer3 time-out, i.e., Ts=125us.
=======================================================================================*/
void initTmr3()
{
TMR3 = 0x0000;
PR3 = 4999; // Trigger ADC1 every 125usec
IFS0bits.T3IF = 0; // Clear Timer 3 interrupt
IEC0bits.T3IE = 0; // Disable Timer 3 interrupt
T3CONbits.TON = 1; //Start Timer 3
}
// Linker will allocate these buffers from the bottom of DMA RAM.
struct
{
unsigned int Adc1Ch0[8];
unsigned int Adc1Ch1[8];
unsigned int Adc1Ch2[8];
unsigned int Adc1Ch3[8];
} BufferA __attribute__((space(dma)));
struct
{
unsigned int Adc1Ch0[8];
unsigned int Adc1Ch1[8];
unsigned int Adc1Ch2[8];
unsigned int Adc1Ch3[8];
} BufferB __attribute__((space(dma)));;

// DMA0 configuration
// Direction:Read from peripheral address 0-x300 (ADC1BUF0) and write to DMA RAM
// AMODE:Peripheral Indirect Addressing Mode
// MODE:Continuous, Ping-Pong Mode
// IRQ:ADC Interrupt

void initDma0(void)
{
DMA0CONbits.AMODE = 2; // Configure DMA for Peripheral indirect mode
DMA0CONbits.MODE = 2; // Configure DMA for Continuous Ping-Pong mode
DMA0PAD = 0x0300; // Point DMA to ADC1BUF0
DMA0CNT = 31; // 32 DMA request (4 buffers, each with 8 words)
DMA0REQ = 13; // Select ADC1 as DMA Request source
DMA0STA = __builtin_dmaoffset(&BufferA);
DMA0STB = __builtin_dmaoffset(&BufferB);
IFS0bits.DMA0IF = 0; //Clear the DMA interrupt flag bit
IEC0bits.DMA0IE = 1; //Set the DMA interrupt enable bit
DMA0CONbits.CHEN=1; // Enable DMA
}
/*========================================================================================
_DMA0Interrupt():ISR name is chosen from the device linker script.
========================================================================================*/
unsigned int DmaBuffer = 0;
void __attribute__((__interrupt__)) _DMA0Interrupt(void)
{
if(DmaBuffer == 0)
{
ProcessADCSamples(BufferA.Adc1Ch0);
ProcessADCSamples(BufferA.Adc1Ch1);
ProcessADCSamples(BufferA.Adc1Ch2);
ProcessADCSamples(BufferA.Adc1Ch3);
}
else
{
ProcessADCSamples(BufferB.Adc1Ch0);
ProcessADCSamples(BufferB.Adc1Ch1);
ProcessADCSamples(BufferB.Adc1Ch2);
ProcessADCSamples(BufferB.Adc1Ch3);
}
DmaBuffer ^= 1;
IFS0bits.DMA0IF = 0; //Clear the DMA0 Interrupt Flag
}
void ProcessADCSamples(unsigned int * AdcBuffer)
{
/* Do something with ADC Samples */
}
此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
3条回答
dingzy_2002
1楼-- · 2019-03-26 05:27
本帖最后由 dingzy_2002 于 2016-7-13 10:54 编辑

由于很少用到PIC33,仅对你给的问题及其它厂产品的经验,作出解释:
1.ADC与DMA模块应该是独立的,可以单独使用ADC,查了下数据手册,ADC是有独立中断的
1.png
2.另外,PIC的数据手册一般要通读,尤其是对每个模块介绍的寄存器多看下.3.对于DMA的中断读取问题:一般是ADC转换与DMA互不干涉的(如果ADC设置自动转换,那么这个模块将一直在转换直至ADC BUFER数据溢出).
4.ADC模块有开启转换位,要在自动转换状态下停止ADC转换,则一般是关闭ADC模块即可,不是自动转换时,也可以通过关闭ADC模块或者等待其转换完成,其自动停止转换
5.定时器3的触发ADC功能,可以是直接触发,而不经过定时器的中断(只要你配置好条件即可)
lene
2楼-- · 2019-03-26 05:55
dingzy_2002 发表于 2016-7-13 10:47
由于很少用到PIC33,仅对你给的问题及其它厂产品的经验,作出解释:
1.ADC与DMA模块应该是独立的,可以单独使 ...

1、在有DMA模块的单片机中,一个ADC模块只有一个ADC1BUF0,所以不用DMA的话,只能采一个值,转换一个值后就读取ADC1BUF0中的值。ADC中断是有,我是不太明白如何产生中断,是转换一一次采样结果完成就触发中断(IFS0的AD1IF=1)吗?还是当SMPI=5时,就是转换6次采样结果就产生中断?
2、ADC控制寄存器1中只有采样自动开始位,没看到有自动转换的设置?
3、DMA0在什么情况下跳进DMA0中断程序中啊?
michael88888888
3楼-- · 2019-03-26 08:32
PIC的可以提供咨询  

一周热门 更多>