|
|
View previous topic :: View next topic |
Author |
Message |
Andmo
Joined: 04 May 2015 Posts: 14
|
PIC18F67J94 + sleep |
Posted: Fri Sep 29, 2017 3:23 am |
|
|
Hello
I have a problem with the PIC18F67J94. If i want to go to sleep the PIC need 5mA during the sleep mode.
In the schematic i have only a PIC with 32kHz at the sosc for RTCC and an internal Clock with USB and some other stuff. But at the moment its only the PIC on the board.
main.h
Code: |
#include <18F67J94.h>
#device ADC=16
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOBROWNOUT //No brownout reset
#FUSES SOSC_LOW //Low-power SOSC circuit is selected
#FUSES NOCLOCKOUT //I/O function on OSC2
#FUSES VBATBOR //VBAT BOR Enabled
#FUSES PR
#FUSES SOSC
#FUSES FRC
#FUSES CKSFSM //Clock Switching is enabled, fail Safe clock monitor is enabled
#FUSES VREGSLEEP_SW //Ultra low-power regulator is enabled
#FUSES DSWDTOSC_SOSC //DSWDT uses SOSC as reference clock
#use delay(clock=64MHZ)
//#use delay(internal=8MHz,USB_FULL,ACT=USB)
//*****************************************************************************
#DEFINE SPI_MODE_3 (SPI_H_TO_L | SPI_XMIT_L_TO_H)
#pin_select SCK1=PIN_E7
#pin_select SDI1=PIN_E4
#pin_select SDO1=PIN_E3
#define o_adisRST PIN_E5
#define USB_CONFIG_VID 0x2405
#define USB_CONFIG_PID 0x000B
#define USB_STRINGS_OVERWRITTEN
char USB_STRING_DESC_OFFSET[]={0,4,24}; |
main.c
Code: |
void main()
{
init_ext_eeprom();
enable_interrupts(INT_RTC); //enable RTC interrupts
enable_interrupts(GLOBAL); //enable interrupts
setup_wdt( WDT_OFF );
setup_oscillator( OSC_INTRC );
setup_adc( ADC_CLOCK_INTERNAL );
setup_adc_ports(sAN1|VSS_VDD);
setup_lcd(LCD_DISABLED);
//setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
//RTCC
SETUP_CCP1(CCP_OFF );
setup_rtc(RTC_ENABLE | RTC_CLOCK_SOSC, 0);
//setup_rtc(RTC_ENABLE,0);
datetime.tm_year = 17;
datetime.tm_mon = 9;
datetime.tm_mday = 27;
datetime.tm_wday = 3;
datetime.tm_hour = 10;
datetime.tm_min = 37;
datetime.tm_sec = 0;
//rtc_write(&datetime);
setup_rtc_alarm(RTC_ALARM_ENABLE, RTC_ALARM_MINUTE, 0);
datetime.tm_year = 0x00;
datetime.tm_mon = 1;
datetime.tm_mday = 1;
datetime.tm_wday = 1;
datetime.tm_hour = 0;
datetime.tm_min = 0;
datetime.tm_sec = 0;
rtc_alarm_write(&datetime);
init_ext_eeprom();
usb_init();
fprintf(debug,"\033c");
fprintf(debug,"*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-\r\n");
VARIABLE_INIT();
F_MESS_NOW=0;
fprintf(debug,"Initialisiert\r\n");
output_float(o_adisRST);
//adis_rst();
while(TRUE)
{
//output_toggle(PIN_G0);
/* output_low(PIN_E5);
delay_ms(100);
output_float(PIN_E5);
delay_ms(100);*/
//delay_ms(3000);
//set_adc_channel(1);
//value = read_adc();
//fprintf(debug,"A/D value = %4X\n\r", value);
//rtc_read(&datetime);
//fprintf(debug,"\r\nDate/Time: %u.%u.%u %u:%u:%u",datetime.tm_mday,datetime.tm_mon,datetime.tm_year,datetime.tm_hour,datetime.tm_min,datetime.tm_sec);
//TODO: User Code
if(F_MESS_NOW&&!F_USB)
{
//messung_now();
F_MESS_NOW=0;
}
if(F_USB)
{
fprintf(debug,"\fUSB-Modus");
USB_MODUS();
}
fprintf(debug,"Sleep Mode\r\n");
sleep(SLEEP_FULL||WAKE_FROM_RTCC);
delay_cycles(1);
}
}
|
Thanks for your reply.
Andi
Last edited by Andmo on Fri Sep 29, 2017 3:25 am; edited 1 time in total |
|
|
Andmo
Joined: 04 May 2015 Posts: 14
|
|
Posted: Fri Sep 29, 2017 3:24 am |
|
|
Compiler Version 5.074 |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Fri Sep 29, 2017 5:27 am |
|
|
To test the PIC for power during sleep, create a new program and get rid of all code for peripherals like LCD, serial,USB, etc. As well, disable all internal peripherals like ADC, COMP, USB, etc. Then, set every I/O pin high. There may be a couple other 'things to do' but this setup should allow you to measure the PIC's power consumption BEFORE adding peripherals.
Post your new 'sleep test' code so we can see if you've got everything correct.
Jay |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Sep 29, 2017 7:01 am |
|
|
Your program doesn't compile. It's missing some lines for #include files.
Please add them and whatever else is needed to make it compile.
Also, do you have a voltage regulator on the board ? If so, please post
the part number. |
|
|
Andmo
Joined: 04 May 2015 Posts: 14
|
|
Posted: Tue Nov 07, 2017 12:22 am |
|
|
So now it works.
main.h
Code: |
#include <18F67J94.h>
//#include <18F67J50.h>
#device ADC=16
#FUSES NOWDT //No Watch Dog Timer
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES BROWNOUT_SW //Brownout controlled by configuration bit in special file register
#FUSES BORV18 //Brownout reset at 1.8V
#FUSES NOPROTECT //Code not protected from reading
#FUSES SOSC_LOW //Low-power SOSC circuit is selected
#FUSES NOCLOCKOUT //I/O function on OSC2
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES NOPLL //HW PLL disabled
#FUSES CKSFSM //Clock Switching is enabled, fail Safe clock monitor is enabled
#FUSES WPFP //Write/Erase Protect Page Start/End Location, set to last page or use WPFP=x to set page
#FUSES WPDIS //All Flash memory may be erased or written
#FUSES WPEND //Flash pages WPFP to Configuration Words page are write/erase protected
#FUSES NOWPCFG //Configuration Words page is not erase/write-protected
#FUSES T5G_IS_T5G //Timer 5 Gate is driven by the T5G input
#FUSES CINA_DEFAULT //C1INA and C3INA are on their default pin locations
#FUSES IOL1WAY //Allows only one reconfiguration of peripheral pins
#FUSES MSSP2MSK7 //MSSP2 uses 7 bit Masking mode
#FUSES MSSPMSK7 //MSSP uses 7 bit Masking mode
#FUSES WDTWIN_25% //Watchdog Window is 25% of WDT period
#FUSES WDTCLK_FRC //WDT uses FRC as clock source
#FUSES WINDIS //Watch Dog Timer in non-Window mode
#FUSES VREGSLEEP_SW //Ultra low-power regulator is enabled
#FUSES VBATBOR //VBAT BOR Enabled
#FUSES DSBOR //BOR enabled in Deep Sleep
#FUSES DS_SW //Deep Sleep is controlled by the register bit DSEN
#FUSES DSWDT //Deep Sleep Watchdog Timer enabled
#FUSES DSWDTOSC_SOSC //DSWDT uses SOSC as reference clock
//#fuses CKSNOFSM //Clock Switching is enabled, fail Safe clock monitor is disabled
//#fuses CKSFSM //Clock Switching is enabled, fail Safe clock monitor is enabled
//#fuses NOCKSNOFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
//#use delay(internal=8MHz,USB_FULL,ACT=USB)
#use delay(internal=8MHz)
#use rs232(baud=9600,parity=N,xmit=PIN_C7,rcv=PIN_C6,bits=8,stream=Debug)
|
init_sleep function:
Code: | void init_sleep(void){
#use delay(internal=8MHz)
fprintf(debug,"\r\nSleep Mode\r\n");
set_tris_a(0x00); //Ausgang
set_tris_b(0x00);
set_tris_c(0x00);
set_tris_d(0x00);
set_tris_e(0x00);
set_tris_f(0x80);
set_tris_g(0x00);
#use delay(internal=32KHz)
delay_ms(1000);
setup_spi(SPI_DISABLED);
output_low(led);
output_low(adisonoff); //
output_high(SDA1);
output_high(SCL1);
output_high(PIN_E7);
output_high(PIN_E4);
output_high(PIN_E3);
output_high(PIN_E2);
output_high(o_adisRST);
output_low(PIN_F3);
output_high(PIN_F4);
//output_low(PIN_F7);
output_low(PIN_C6); //rS232
output_low(PIN_C7);//RS232
//setup_spi(SPI_DISABLED);
output_low(PIN_A1);
} |
main:
Code: |
void main()
{
global_init();
BaumINIT();
while(TRUE)
{
//*************************************************************
//usb
if(F_USB)
{
fprintf(debug,"\r\nUSB-Modus");
//PLLEN=1;
USB_MODUS();
}
//*************************************************************
//Sleep
init_sleep();
sleep(SLEEP_FULL||WAKE_FROM_RTCC);
delay_cycles(1);
}
} |
Now it needs abaut 58uA at Sleep-Mode with all peripherals.
Thanks |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Nov 07, 2017 1:08 am |
|
|
Quote: | sleep(SLEEP_FULL || WAKE_FROM_RTCC); |
This won't be correct, with the logical OR.
Since both those constants are non-zero values, the expression will
evaluate to "TRUE", which is equal to 1. So that line is equivalent to this:
The 18F67J94.h file has these values in the Sleep section:
Code: | // Constants for calls to sleep() are:
#define SLEEP_FULL 0 // Default
#define SLEEP_IDLE 1 // Clock and peripherals don't stop
|
So your line at the top is doing the same thing as this:
|
|
|
Andmo
Joined: 04 May 2015 Posts: 14
|
|
Posted: Tue Nov 07, 2017 1:26 am |
|
|
Thanks i changed it. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|