- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
我正在學習如何用DMA,過程中遇到了問題。
我的電路圖跟ADC配置:
我用兩個方法來讀取ADC的count值:
1.用普通的方法讀取如下圖(結果如右圖所示)
2.透過DMA方式將count值放到buffer裡再讀取,如下圖(結果如右圖所示)
發現用普通的方法讀取的結果沒有dc offset,用DMA的就有,照理來說我的dc offset應該會被消除才對,有誰可以告訴我這是為什麼?
Solved! Go to Solution.
- Labels:
-
PSoC 5LP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
int16 V_ADC_GetResult16( void )
{
uint16 res;
res = CY_GET_REG16(V_ADC_SAR_WRK_PTR);
return( (int16)res - V_ADC_shift );
}
DMA中读取的是CY_GET_REG16(V_ADC_SAR_WRK_PTR); 但是直接读的API是要offset V_ADC_shift。
所以两个结果不同。
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
int16 V_ADC_GetResult16( void )
{
uint16 res;
res = CY_GET_REG16(V_ADC_SAR_WRK_PTR);
return( (int16)res - V_ADC_shift );
}
DMA中读取的是CY_GET_REG16(V_ADC_SAR_WRK_PTR); 但是直接读的API是要offset V_ADC_shift。
所以两个结果不同。
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
謝謝你的回覆。我還有些問題想請教
1.竟然兩個結果不一樣,那哪個結果是對的?如果普通的方法讀取是對的,那用DMA方式讀取是不是要再減掉offset?如果是的話那offset值是多少,要怎麼決定?
2.我的ADC是用differential mode,如果+input輸入電壓為0V,-input輸入電壓為1.024V,差分結果(Vdiff)=(+input)-(-input)=-1.024V,ADC count=(Vdiff/Vref)*2^11= (-1.024/1.024)*2048=-2048,根據公式,只要我的+input小於-input,count值就要是負的才對。我的問題是差分結果(Vdiff)竟然是負的,為何還要透過軟體的方式減掉offset來取得負值?(若以DMA方式讀取)
3.我用ADC DelSig 元件來測試,不管是一般方式讀取或是DMA方式讀取,為何結果都一樣?
(以上問題請根據新傳的project)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
你说的这两种ADC的采样方式不同,SAR的这种方式会减去一个偏移量,其实是为了求补码。
具体这个值等于多少,你需要看你ADC配置成多少位的,还要看-Vinput是设置成什么。
你可以看这个函数:
static void V_ADC_CalcGain( uint8 resolution )static void V_ADC_CalcGain( uint8 resolution )
其实有个变量是 diff_zero。
这个函数的函数体解释了这个偏移值会是多少。