完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好,正如标题所说的,我配置了dSPIC33 FJ256GP710A的ADC1,用于同时多通道模式,但是我得到了CH0的错误值。在四个通道中,我有以下类似的输入:CH0+=AN3CH0-=VREF CH123+= AN0,AN1,AN2CH123-=VREF,现在,我做了一个残忍的事。测试:通过Pad Drand板将AN3、AN0和AN1连接到GND和AN2到+3.3V……我的测试程序通过UART将四个通道的数据发送到matlab,结果是在列上具有通道的值矩阵,并且泛型行是:[68, 1, 2,1023 ]现在,CH3有一个很好的值,同样是CH1和CH2(尽管有噪声),但是CH0有一个不可接受的值……也改变了CH0的模拟输入,我得到了类似的值,但是我从来没有得到接近零的值……有人知道我做错了什么吗?提前感谢您的帮助!下面是我的代码:全局变量
以上来自于百度翻译 以下为原文 Hi everyone, as the title says, I configured the ADC1 of the dspic33fj256gp710a for working in simultaneous multi-channel mode, but I obtain wrong values for CH0. On the four channels I have the followings analogic inputs: CH0+ = AN3 CH0- = Vref- CH123+ = AN0, AN1, AN2 CH123- = Vref- Now, I made a brutal test: through a pictail doughter board I linked AN3, AN0 and AN1 to GND and AN2 to +3.3V... My test program sends the data of the four channels to matlab through the UART, and the result is a matrix of values that has the channels on the columns, and the generic row is: [ 68, 1, 2, 1023 ] Now, CH3 has a good value, and so also CH1 and CH2 (in spite of the noise), but CH0 has an unacceptable value... Also changing the analogic input for CH0, I get similar values, but I never obtain values near to zero... Have someone idea of what I'm doing wrong? Thank you in advance for your help! In the following there is my code:
#define GLOBALS_H extern bool eventTimer2; extern bool eventTimer3; extern bool eventTimer4; extern bool eventTimer5; extern unsigned adc1SampleBufferIndex; extern unsigned short adc1SamplesBuffer[4]; extern bool adc1SampleBufferFull; #endif /* GLOBALS_H */
// Configurazione oscillatore a 40 MHz configureOscillator(); // Abilitazione led enableLed(EXP16_LED_D3); enableLed(EXP16_LED_D4); enableLed(EXP16_LED_D5); // Abilitazione pulsanti ButtonData dataS3; enableButton(&dataS3, EXP16_BUTTON_S3); ButtonData dataS6; enableButton(&dataS6, EXP16_BUTTON_S6); // Inizializzazione Uart initUart2(); // Inizializzazione ADC1 initTimer5(1875,PRESCALER_1_64); // Inizializzazione del Timer 5 (che da il trigger all'ADC) a T=3ms initADC1(); // Inizializzazione ADC1 switchLedOn(EXP16_LED_D3); // Attesa avvio da parte dell'utente while(!isButtonPressed(&dataS3)); // Avvio periferiche startTimer5(); startADC1(); switchLedOn(EXP16_LED_D4); // Ciclo infinito while (true) { while(!adc1SampleBufferFull); // Channel 1 writeWordOnUart2Channel(UART_CHANNNEL_1,adc1SamplesBuffer[0]); // Channel 2 writeWordOnUart2Channel(UART_CHANNNEL_2,adc1SamplesBuffer[1]); // Channel 3 writeWordOnUart2Channel(UART_CHANNNEL_3,adc1SamplesBuffer[2]); // Channel 4 writeWordOnUart2Channel(UART_CHANNNEL_4,adc1SamplesBuffer[3]); adc1SampleBufferFull = false; toggleLed(EXP16_LED_D5); } }
#ifndef ANALOGDIGITALCONVERTERS_H #define ANALOGDIGITALCONVERTERS_H #include #include #include #include "globals.h" #define ADC_TRIGGER_TIMER_T5_T3 0b100 //ADC1 attivato dal Timer5, ADC2 attivato dal Timer3 #define ADC_TRIGGER_TIMER_T3_T5 0b010 //ADC1 attivato dal Timer3, ADC2 attivato dal Timer5 void initADC1(void); void startADC1(void); void __attribute__((__interrupt__, __auto_psv__)) _ADC1Interrupt(void); #endif /* ANALOGDIGITALCONVERTERS_H */ .C #include "analogDigitalConverters.h" void initADC1(void) { // Configurazioni generali AD1CON1bits.AD12B = 0; // Modalità 10 bit 16.4.1 AD1CON2bits.CHPS1 = 1; // Quad channel 16.4.2 AD1CON1bits.FORM = 0; // Formato unsigned integer 16.4.5 AD1CON2bits.VCFG = 0; // Tensioni di riferimento interne 16.4.3 AD1CON1bits.SIMSAM = 1; // Campionamento simultaneo 16.3.6 AD1CON2bits.ALTS = 0; // Modalità non alternata 16.6.1 // Configurazioni relative alle tempistiche AD1CON1bits.ASAM = 1; // Il campionamento inizia automaticamente 16.3.1 AD1CON1bits.SSRC = ADC_TRIGGER_TIMER_T5_T3; // La conversione inizia col Timer 5 16.3.2 // AD1CON3bits.SAMC // Non serve poichè SSRC!=7 16.3.1 (Nota 1 pag 16-11) // Configurazioni relative al clock AD1CON3bits.ADRC = 0; // Utilizza il clock di istruzioni FCY 16.4.4 AD1CON3bits.ADCS = 2; // Settaggio divisore clock istruzioni 16.4.4 // ADC Conversion Period ==> TAD = TCY * (ADCS + 1) = (1/40M) * 3 // = 75 ns (13.3 MHz) // ADC Conversion Time for 10-bit ==> Tconv = 12 * TAD = 900 ns (1.1 MHz) // Configurazioni relative all'interrupt AD1CON2bits.SMPI = 1; // Genera un interrupt ogni conversione 16.5 // (ogni 4 essendo in modalità 4 canali simultanei) IFS0bits.AD1IF = 0; // Pulisce l'interrupt flag per l'ADC1 IEC0bits.AD1IE = 1; // Abilita l'interrupt per l'ADC1 // Configurazioni relative ai canali AD1CHS0bits.CH0SA = 3; // CH0+ = AN3 16.6.1 (Table 16-10) AD1CHS0bits.CH0NA = 0; // CH0- = Vref- " AD1CHS123bits.CH123SA = 0; // CH123+ = AN0,AN1,AN2 " AD1CHS123bits.CH123NA = 0; // CH123- = Vref- " } void startADC1(void) { AD1CON1bits.ADON = 1; // Accensione 16.4.9 } void __attribute__((__interrupt__,__auto_psv__)) _ADC1Interrupt(void) { adc1SamplesBuffer[adc1SampleBufferIndex] = ADC1BUF0; adc1SampleBufferIndex = (adc1SampleBufferIndex + 1) % 4; if (adc1SampleBufferIndex == 0) { adc1SampleBufferFull = true; } IFS0bits.AD1IF = 0; // Pulisce l'interrupt flag per l'ADC1 } |
|
相关推荐
1个回答
|
|
有人知道有什么不对吗?对不起,如果解决方案可能是微不足道的,但这是我第一次体验Microchip的DSPIC和一般的嵌入式系统的C级编程…Pink:
以上来自于百度翻译 以下为原文 Has anyone idea of what wrong is there? Sorry if perhaps the solution is trivial, but this is my first experience with microchip's dspic and generally with C level programming of embedded systems... pink: |
|
|
|
只有小组成员才能发言,加入小组>>
5162 浏览 9 评论
2000 浏览 8 评论
1928 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3172 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2226 浏览 5 评论
731浏览 1评论
613浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
503浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
629浏览 0评论
527浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-23 11:02 , Processed in 1.282748 second(s), Total 78, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号