完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
您好,当使用CrrasAM位时,在初始中断之后不能再采样重新启动。要重新启动,我清除中断标志并将ASAM位设置为1,但采样不会再次启动,中断标志在初始中断之后未被打开。有什么想法吗?
以上来自于百度翻译 以下为原文 Hello, when using the CLRASAM bit I cannot get sampling to restart again after the initial interrupt. To restart I clear the interrupt flag and set ASAM bit to 1 but sampling does not start again and the interrupt flag never is turned on after the initial interrupt. Any ideas? #define Vref (float)3.3 #pragma config PMDL1WAY = ON // Peripheral Module Disable Configuration (Allow only one reconfiguration) #pragma config IOL1WAY = ON // Peripheral Pin Select Configuration (Allow only one reconfiguration) #pragma config FUSBIDIO = ON // USB USID Selection (Controlled by the USB Module) #pragma config FVBUSONIO = ON // USB VBUS ON Selection (Controlled by USB Module) // DEVCFG2 #pragma config FPLLIDIV = DIV_12 // PLL Input Divider (12x Divider) #pragma config FPLLMUL = MUL_24 // PLL Multiplier (24x Multiplier) #pragma config UPLLIDIV = DIV_12 // USB PLL Input Divider (12x Divider) #pragma config UPLLEN = OFF // USB PLL Enable (Disabled and Bypassed) #pragma config FPLLODIV = DIV_256 // System PLL Output Clock Divider (PLL Divide by 256) // DEVCFG1 #pragma config FNOSC = FRC // Oscillator Selection Bits (Fast RC Osc (FRC)) #pragma config FSOSCEN = ON // Secondary Oscillator Enable (Enabled) #pragma config IESO = ON // Internal/External Switch Over (Enabled) #pragma config POSCMOD = OFF // Primary Oscillator Configuration (Primary osc disabled) #pragma config OSCIOFNC = OFF // CLKO Output Signal Active on the OSCO Pin (Disabled) #pragma config FPBDIV = DIV_1 // Peripheral Clock Divisor (Pb_Clk is Sys_Clk/1) #pragma config FCKSM = CSDCMD // Clock Switching and Monitor Selection (Clock Switch Disable, FSCM Disabled) #pragma config WDTPS = PS1048576 // Watchdog Timer Postscaler (1:1048576) #pragma config WINDIS = OFF // Watchdog Timer Window Enable (Watchdog Timer is in Non-Window Mode) #pragma config FWDTEN = OFF // Watchdog Timer Enable (WDT Disabled (SWDTEN Bit Controls)) #pragma config FWDTWINSZ = WINSZ_25 // Watchdog Timer Window Size (Window Size is 25%) // DEVCFG0 #pragma config JTAGEN = ON // JTAG Enable (JTAG Port Enabled) #pragma config ICESEL = ICS_PGx1 // ICE/ICD Comm Channel Select (Communicate on PGEC1/PGED1) #pragma config PWP = OFF // Program Flash Write Protect (Disable) #pragma config BWP = OFF // Boot Flash Write Protect bit (Protection Disabled) #pragma config CP = OFF // Code Protect (Protection Disabled) // #pragma config statements should precede project file includes. // Use project enums instead of #define for ON and OFF. #include #include #include /* * */ void InitializePortA(void); void InitializePortB(void); void InitializeADC(void); float convertVoltage(unsigned int ADCoutput); int main(int argc, char** argv) { float measuredVoltage; InitializePortA(); InitializePortB(); InitializeADC(); while(1) { while(IFS0bits.AD1IF == 0) { } measuredVoltage = convertVoltage(ADC1BUF0); if(measuredVoltage > 1) PORTBbits.RB14 = 1; else PORTBbits.RB14 = 0; IFS0bits.AD1IF = 0; AD1CON1bits.ASAM = 1; } return (EXIT_SUCCESS); } void InitializePortA(void) { TRISAbits.TRISA0 = 1; ANSELAbits.ANSA0 = 1; } void InitializePortB(void) { PORTBbits.RB14 = 0; TRISBbits.TRISB14 = 0; } void InitializeADC(void) { AD1CON1bits.SSRC = 0b111; // enable auto convert. AD1CON1bits.ASAM = 1; // Sampling begins immediately after last conversion AD1CON2bits.SMPI = 0b1111; // 16 samples before interrupt AD1CON3bits.ADRC = 0; // Clock derivied from PBCLK AD1CON3bits.SAMC = 1; // 1 T_AD sample time. AD1CON3bits.ADCS = 0; // T_AD = 2 T_PBCLCK AD1CON1bits.CLRASAM = 1; AD1CON1bits.ADON = 1; } float convertVoltage(unsigned int ADCoutput) { float measuredVoltage; measuredVoltage = Vref/(float)1024 * ADCoutput; return measuredVoltage; } |
|
相关推荐
6个回答
|
|
在中断标志被设置之前,您正在做16个采样和转换,但是只读取一个缓冲器。ADC中断在一些(所有?)在读取所有更新的缓冲器之后,PIC32设备只能被清除。在清除中断标志之前,要么将SMPI更改为0,要么读取所有ADC缓冲器。如果使用指针读取ADC缓冲器递增AdNoad,则需要将地址增加16字节或4个DWord。对于我来说,在非阻塞状态机任务中,采样10次锂离子电池,去除最高值和最低值,并取其余样本的平均值。用于在PIC32 MX575 F512H/Ruben显示器上更新电池棒。
以上来自于百度翻译 以下为原文 You are doing 16 samples and conversions before the interrupt flag is set but are only reading one buffer. ADC Interrupt on some (all?) PIC32 devices can only be cleared after reading all the updated buffers. Either change SMPI to 0 or read all ADC buffers before clearing the interrupt flag. If you are incrementing an address using a pointer to read the ADC buffers, you need to increment the address by 16 bytes or 4 DWORDS. This works for me in a non blocking state machine task to sample a liion battery 10 times, removing the highest and lowest value and taking the average value of the rest of the samples. Used for updating battery bars on a display for a PIC32MX575F512H. void LiIonTask(void) { LIION_STATE localState; int ledState=0; int batMaxV,batMinV; int localBatVoltage; int batVoltDiff; int i; int *p; switch (batMState){ case BAT_NO_MEASURE: if (TickGet()-tBatM>=BATMEASURE_DELAY){ BATMEASURE_On(); batMState=BAT_CAP_CHARGE; } break; case BAT_CAP_CHARGE: AD1CON1=(7<<5)/*SSRC=7*/ + (1<<4)/*CLRASAM=1*/ + (1<<2)/*ASAM=1*/; AD1CON2=(9<<2) /*SMPI=9 => 10 convertions*/; AD1CON3=(3<<8) /*SAMC=3*/ + (5) /*ADCS=5*/; AD1CHS=(7<<16) /*CHOSA=7*/; IFS1CLR=0x0002; AD1CON1SET=0x8000; // ON=1 batMState=BAT_MEASURING; break; case BAT_MEASURING: if (IFS1bits.AD1IF){ BATMEASURE_Off(); AD1CON1CLR=0x8000; batMState=BAT_NO_MEASURE; tBatM=TickGet(); /* Converter does 10 ad conversions. * Remove highest and lowest value and take mean value of the * 8 remaining conversion results. */ batMaxV=0; batMinV=10000; localBatVoltage=4; //0.5*8 p=(int *)(&ADC1BUF0); for(i=0;i<10;i++){ if (*p>batMaxV){ batMaxV=*p; } if (*p } localBatVoltage+=*p; p+=4; } localBatVoltage-=batMaxV; localBatVoltage-=batMinV; localBatVoltage/=8; batVoltDiff=localBatVoltage-batVoltage; if (batVoltDiff<0){ // voltage is decreasing if (batVoltDiff<-5000){ // First sample batVoltage=localBatVoltage; } else if (batVoltDiff<=-4){ batVoltage--; } } else { // voltage is increasing if (batVoltDiff>=2){ batVoltage++; } } LiIonBatCapLeft(); //ConsoleMsgTime("Battery: %d,%drn",batVoltage,batCapLeft); } break; default: batMState=BAT_NO_MEASURE; tBatM=TickGet()-BATMEASURE_DELAY; break; } } /Ruben |
|
|
|
你好,我知道了,另外我认为模拟器是不正常的,因为当我在设备上运行代码并使用ICD时,我得到不同的结果(正确的结果)。为什么?
以上来自于百度翻译 以下为原文 Hello, I caught that, in addition I think the simulator is dysfunctional as I get different(correct) results when I run the code on the device and use ICD. I also got different results writing to PORTBbits verses writing to LATBbits with writing to LATBbits giving the correct results, I am not sure why. |
|
|
|
读-修改-写。这就是为什么你建议永远不要写入端口*位。只使用该地址读取输入。
以上来自于百度翻译 以下为原文 Read-modify-write. That is why you are advised to NEVER write to PORT*bits. Only use that address for reading inputs. |
|
|
|
我不明白?你能再解释一下吗?我假设编译器自动保存了端口状态,修改了位然后将它写回。在数据表中,它意味着可以直接写入端口寄存器,而不是使用LAT。
以上来自于百度翻译 以下为原文 I don't understand? Could you explain more? I assumed the compiler automatically saved the ports state, modified the bit then wrote it back. In the datasheet it implies you can write to the PORTB register directly instead of using LAT. |
|
|
|
所有编译器都是访问你告诉它的寄存器。当你访问一个端口*BIT结构时,你正在访问一个比特,所以它使用BCF或BSF指令。读取整个数据表,特别是关于BCF和BSF指令。它们的工作方式是,读取整个端口,修改。一位,并写回整个端口。因此,“读/修改/写”。如果它是地址的端口*寄存器(而不是LAT*寄存器),那么它是被读取的引脚的状态,而不是驱动输出的内部锁存器的状态。引脚的状态受:TISIS *注册PoNIT电容上的电阻性负载。在引脚上的特定负载(尤其是在您将引脚从高电平改变为低电平之后,反之亦然)。相信我,在切换单个位时,访问LAT*而不是端口*会产生巨大的差异。这就是为什么LAT*寄存器在那里。
以上来自于百度翻译 以下为原文 All the compiler does is access the register you tell it to. When you access a PORT*bits structure, you are accessing a single bit, so it uses a BCF or BSF instruction. Read the whole datasheet, particularly in regard to BCF and BSF instructions. They way they work is, they read the whole port, modify one bit, and write back to the whole port. Hence "read/modify/write". If it's the PORT* register (rather than the LAT* register) that you address, then it is the state of the pins that is read, not the state of the internal latch driving the outputs. The state of the pins is affected by:
|
|
|
|
也可以写入SET、CLR和IV偏移,而不是用寄存器来写入基址寄存器中的单个位。
以上来自于百度翻译 以下为原文 Also write to the SET, CLR and INV offsets instead of writing to individual bits in the base register with REGISTER.bit= for a PIC32. /Ruben |
|
|
|
只有小组成员才能发言,加入小组>>
5234 浏览 9 评论
2026 浏览 8 评论
1950 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3201 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2253 浏览 5 评论
771浏览 1评论
659浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
588浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
670浏览 0评论
571浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-20 12:03 , Processed in 2.384011 second(s), Total 89, Slave 71 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号