完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我正在尝试为电池操作的设备建立电源控制器。我选择PIC12F675。这个想法是将PIC置于睡眠模式。用秒表计时每秒唤醒它。检查引脚状态,决定是否接通或断开。决策代码工作正常。但是PIC不睡觉。它看起来像PIC跳过睡眠()宏。在问这个问题之前,我做了一个深入的研究并测试了我发现的所有东西。下面是配置:所有引脚都是IO。无外部晶体,无复位。没有浮针。我没有观察到任何睡眠情况,也重置条件。问题是我做错了什么PIC12F675没有睡觉?编程平台:MPLABX+XC8(最新版本免费)+PICIT3[&字体]配置。
以上来自于百度翻译 以下为原文 I'm trying to build a power controller for a battery operated device. I choose PIC12F675. The idea is putting pic in sleep mode. Wake it up with Watchdod timer approx each second. Check pin states, decide whether to switch on or off. The decision code is working as expected. But PIC does not sleep. It looks like PIC skips SLEEP() macro. Before asking this question i've made a deep research and tested everything I found. So here are the configuration: ---------- Vdd |1 8| GND/VSS Dock test pin(out) GP5 |2 7| GP0 (in) Batt Measure Power Fet Drive(out)GP4 |3 6| GP1 (in) Batt Measure reference voltage Charge Status (in) GP3 |4 5| GP2 (in) Dock sense ---------- All pins are io. No external crystal, no reset. No floating pin. I do not observe any sleep condition, also reset condition. The question is what am i doing wrong that the PIC12F675 is not sleeping? Programing platform: MPLABX + XC8 (Latest version-Free) + pickit3 [Config.h #pragma config FOSC = INTRCIO // Oscillator Selection bits (INTOSC oscillator: I/O function on GP4/OSC2/CLKOUT pin, I/O function on GP5/OSC1/CLKIN) #pragma config WDTE = ON // Watchdog Timer Enable bit (WDT enabled) #pragma config PWRTE = ON // Power-Up Timer Enable bit (PWRT enabled) #pragma config MCLRE = OFF // GP3/MCLR pin function select (GP3/MCLR pin function is digital I/O, MCLR internally tied to VDD) #pragma config BOREN = ON // Brown-out Detect Enable bit (BOD enabled) #pragma config CP = OFF // Code Protection bit (Program Memory code protection is disabled) #pragma config CPD = OFF // Data Code Protection bit (Data memory code protection is disabled) #define _XTAL_FREQ 4000000 // this is used by the __delay_ms(xx) and __delay_us(xx) functions[main.c unsigned int Read_ADC_Value(void) { unsigned int ADCValue; ADCON0bits.GO = 1; // start conversion while (ADCON0bits.GO); // wait for conversion to finish ADCValue = ADRESH << 8; // get the 2 m***s of the result and rotate 8 bits to the left ADCValue = ADCValue + ADRESL; // now add the low 8 bits of the resut into our return variable return (ADCValue); // return the 10bit result in a single variable } unsigned int Check_Dock() { GPIO5 = HIGH; __delay_ms(5); unsigned int result = GPIO2; GPIO5 = LOW; return result; } unsigned int Read_Batt(){ unsigned int adc=Read_ADC_Value(); float voltage = ADCSTEP * adc * 200.0; return (unsigned int)(voltage); } void main(void) { //Configure Watchdog to approx 1 sec CLRWDT(); OPTION_REGbits.PSA = 1; //postscaler is for wdt OPTION_REGbits.PS = 0x110; //postscaler 1:64 OPTION_REGbits.nGPPU = 0; //pullups enabled WPU = 0xff; //enable pullups TRISIObits.TRISIO0 = INPUT; //AN0-GPIO0 - input - analog okuma için pil değeri. TRISIObits.TRISIO1 = INPUT; //AN1 -Vref ANS2=0; TRISIObits.TRISIO2 = INPUT; //GP2 <- Dock sense low=docked high=undocked ANS3=0; TRISIObits.TRISIO3 = INPUT; //Charge Status -> GP3 TRISIObits.TRISIO4 = INPUT; TRISIObits.TRISIO5 = OUTPUT; //Dock test pin <- GP5 GPIO5 = LOW; //do not output anything //Setup analog ANSELbits.ANS0 = INPUT; //analog input 0 is used ADCON0bits.ADON = 1; //adc is on ADCON0bits.CHS = 0x00; //an0 is tied to the sampler ADCON0bits.VCFG = 1; //1=>use vRref pin as voltage reference, 0=> use vdd ADCON0bits.ADFM = 0x01; //ADC results are right-justifed ANSELbits.ADCS = 0x011; //Conversion clock = FRC internal: measurement can take till 6usec INTCON = 0; //disable every interrupt PIE1=0; PIR1=0; INTCONbits.GIE = 0; //Program Loop while (1) { SLEEP(); NOP(); INTCONbits.GPIF=0; unsigned char sta = 0; if(Read_Batt() <= BATTLOWTHRESHOLD){ //Batt low turn everything off sta++; } unsigned int isCharging = GPIO3; //0:not charging; 1: charging; sta+=isCharging; unsigned int isnotDocked = Check_Dock(); if(isnotDocked) { //0:docked; 1:flying NOP(); }else{ sta++; } if(sta) { //disable fet TRISIObits.TRISIO4 = INPUT; WPU4=1; //enable port pullup } else { TRISIObits.TRISIO4 = OUTPUT; GPIO4 = LOW; //enable fet } }//End of: Main loop } |
|
相关推荐
1个回答
|
|
我在Meal.C文件上做了排版错误。其实PIC睡觉,但我不能意识到它正在睡觉。因为它的睡眠时间是18Ms,这条线应该是:
以上来自于百度翻译 以下为原文 I made a typographic error on main.c file. Actually pic sleeps but I cannot realize that it was sleeping. Because it was sleeping for 18ms. This line: OPTION_REGbits.PS = 0x110; //postscaler 1:64 ^ Should be: OPTION_REGbits.PS = 0b110; //postscaler 1:64 ^ |
|
|
|
只有小组成员才能发言,加入小组>>
5248 浏览 9 评论
2036 浏览 8 评论
1956 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3218 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2264 浏览 5 评论
787浏览 1评论
678浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
604浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
685浏览 0评论
582浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-27 13:43 , Processed in 1.257049 second(s), Total 76, Slave 60 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号