完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
我们在PIC16F507板上工作,我们使用AN4、AN5和AN6作为模拟输入输入1、输入2和输入3。根据输入的范围(输入1、输入2和输入3)定义了STATE1、SATTE2和STATE3。我们使用以下配置:模拟通道(AN4,AN5和AN6)写ADC的功能如下:我们使用定时器和中断,这里是我们要检查所有三个通道的主要部分,并且要求输入1、输入2和输入3应该被扫描,如果输入1在限制之内(限制将被指定)。d)用户应该保持在状态1。如果输入1不在范围内,则应该扫描输入2,并且它应该在STATE2中。当在Stute2中,如果输入1出现在该范围内,则它应该返回到STATE1。如果输入1和输入2不在范围内,那么输入3必须被扫描,那么它应该转到StATE3。当它在STATE3中时,应该继续扫描输入1和输入2,这样如果输入1出现在该范围内,那么它就会出现。ULD更改为STATE1,如果输入1不在该范围内,如果输入为2,则它应该到达STATE2。对于这样的情况,定时是不相关的。Ge和InPt2也不在范围内,那么从STATE1和STATE3转移的时间很长。类似于从STAE2到STATE3。但是当它在状态2和输入1是范围时,从状态3到状态1转移的时间很短。同样,从STATE2到STATE3。为什么定时是不规则的。而且当我们在做Apple PrimaMatg配置WDTE=OffopTythRePix.PSA=0;并且评论OuttTdTcButs.WDTPs= 0B1010;在主要的,然后板不工作。我们如何实现几乎相同的时间(可以是50ms),从一个状态转移到另一个状态。
以上来自于百度翻译 以下为原文 Hi, We are working on PIC16F1507 board where we are using AN4,AN5 and AN6 for thee analog inputs input1,input2 and input3. based on the ranges of inputs (input1,input2 and input3) three states are been defined state1,satte2 and state3. We are using following configurations: #pragma config FOSC = INTOSC #pragma config WDTE = ON #pragma config PWRTE = ON #pragma config MCLRE = OFF #pragma config CP = OFF #pragma config BOREN = ON #pragma config CLKOUTEN = OFF // CONFIG2 #pragma config WRT = OFF #pragma config STVREN = ON #pragma config BORV = LO #pragma config LPBOR = OFF #pragma config LVP = ON We have following port configurations for analog channels (AN4,AN5 and AN6) ANSELC = 0b00000111; TRISC = 0b00000111; LATC = 0; Written ADC functions as below: void adc_init() { ADCON0bits.ADON = 1; //ADC enabled ADCON1bits.ADFM = 1; //right justified ADCON1bits.ADCS = 6; //clock source is FOSC/64 ADCON1bits.ADPREF = 0; //VREF+ is connected internally to FVR Buffer 1 PIR1bits.ADIF = 0; //Clear interrupt Flag PIE1bits.ADIE = 0; ADCON2bits.TRIGSEL0=0; ADCON2bits.TRIGSEL1=0; ADCON2bits.TRIGSEL2=0; ADCON2bits.TRIGSEL3=0; } byte Timer_value=0; unsigned long int Value1,Value2,Value3; unsigned long int scanner(unsigned char channel) { unsigned long int result = 0; unsigned char i; ADCON0bits.ADON = 1; ADCON0bits.CHS = channel; Timer_value = 0; while(Timer_value <20); for(i=0;i<100;i++) { ADCON0bits.ADGO = 1; Timer_value = 0; while(Timer_value <5); while((ADCON0bits.ADGO)); result = result+(ADRESH<<8)+ADRESL;// PIR1bits.ADIF = 0; } result = result/100; return (unsigned long int)result; } We have used timer and interrupt as void timer_init() { OPTION_REGbits.T0CS = 0; OPTION_REGbits.T0SE = 0; OPTION_REGbits.PSA = 1; OPTION_REGbits.PS2 = 0; OPTION_REGbits.PS1 = 0; OPTION_REGbits.PS0 = 0; TMR0 = 100; } static byte count=0; void interrupt isr( void ) { if(TMR0IF) { TMR0 = 100; TMR0IF = 0; count++; Timer_value++; } here is our main where we want check all the three channels and requirement is that input1, input2 and input3 should be scanned and if input1 is within the limits(limits will be specified by the user) then it should remain in state1. if input1 is not in the range then input2 should be scanned and it should be in state2. When in state2, if input1 comes with in the range then it should come back to state1. If input1 and input2 are not in the range then input3 has to be scanned it should go to state3.when it is in state3, input1 and input2 should scanned continuously such that if input1 comes in the range, then it should change to state1, if input1 is not in the range, it should come to state2 if input2 is the range. for this we doing this: void main(void) { unsigned int i; OSCCON = 0x6b; WDTCONbits.WDTPS=0b1010; adc_init(); timer_init(); PIR1 =0x00; PIR2 =0x00; PIR3 =0x00; PIE1 =0x00; PIE2 =0x00; PIE3 =0x00; INTCON =0xE0; CLRWDT(); while(1) { LOOP: input1= scanner(4); //AN4 ADC input2= scanner(5); //AN5 ADC input3= scanner(6); //AN6 ADC if((input1>Lower_Limit)&&(input1 state1(); CLRWDT(); } else if((input2>Lower_Limit)&&(input2 state2(); CLRWDT(); } else if((input3>Lower_Limit)&&(input3 state3(); CLRWDT(); } } timing is coming is irrelevant. input1 is not in the range and input2 is the range, then it is more time to shift from state1 to state2. similarly, when input1 is not in the range and input2 is also not in the range then it is much time to shift from state1 and state3. similarly from stae2 to state3. But when it is in the state2 and input1 is the range then it is very less time to shift from state3 to state1. similarly from state2 to state3. Why timing is irregular. and also when we are making #pragma config WDTE = OFF OPTION_REGbits.PSA = 0; and commenting out WDTCONbits.WDTPS=0b1010; in the main, then board is not working. How we can achieve the timing almost same (may be 50ms) for shifting from one state to other. |
|
相关推荐
3个回答
|
|
|
一个问题是,TimeRyValm需要在主代码和中断代码之间共享,所以它是不稳定的。你使用的方法尽可能复杂。一个定时器中断(使用最坏的计时器)作为主代码中的忙等待…为什么不跳过所有这些,使用编译器延迟函数?你是如何测量你所看到的时间的?
以上来自于百度翻译 以下为原文 One problem is that Timer_value needs to be volatile since it's shared between main and interrupt code. And the approach you're using is about as convoluted as possible. A timer interrupt (using the worst possible timer) that's used as a busy-wait in the main code...why not just skip all that and use the compiler delay functions? How are you measuring the timings that you're seeing? |
|
|
|
|
|
|
|
|
|
|
|
你的触发信号是什么样的,频率是多少呢
|
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
473 浏览 0 评论
5793 浏览 9 评论
2334 浏览 8 评论
2224 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3530 浏览 3 评论
1121浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1095浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
872浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
473浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-1 20:39 , Processed in 0.801009 second(s), Total 76, Slave 59 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
1260