CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

problem with wake up, after sleep()

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
niktab



Joined: 20 Jul 2010
Posts: 2

View user's profile Send private message

problem with wake up, after sleep()
PostPosted: Mon Oct 04, 2010 4:48 am     Reply with quote

Hi, everybody. My problem is, my pic can not wake up properly after sleep. The pins int0, int1 and int2 has pull up resistors to vcc and buttons to ground. So, when I press some button, code works fine (togglepin switches to the opposite level), but this happens just in case, if i disable sleep(). If sleep() is enabled, pic sometimes wakes up, sometimes not. Why my pic does not wakes up EVERY time (when sleeps)? Why this code works with different result, according the pic sleeps or not? I work with CCS 4.084.

Thanks in advance.
Code:

#include "18F97J60.h"

#Fuses NOWDT                  // Watchdog timer disabled
#Fuses STVREN                  // Stack full/underflow will cause reset
#Fuses NOXINST               // Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#Fuses NoDEBUG                  // Debug mode for use with ICD (disabled)
#Fuses PROTECT               // Code protected from reads
#Fuses HS                        // High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#Fuses PRIMARY               // Primary clock is system clock when scs=00
#Fuses FCMEN                  // Fail-safe clock monitor enabled
#Fuses NOIESO                  // Internal External Switch Over mode disabled
#Fuses WDT128                  // Watch Dog Timer uses 1:128 Postscale
#Fuses NOEASHFT               // Address shifting disabled
#Fuses MCU                     // Microcontroller Mode
#Fuses BW8                     // 8-bit external bus mode
#Fuses NOWAIT                  // Wait selections unavailable for Table Reads or Table Writes
#Fuses CCP2C1                  // CCP2 input/output multiplexed with RC1
#Fuses ECCPH                  // Enhanced CCP PWM outpts multiplexed with RH7 thorugh RH4
#Fuses ETHLED                  // Ethernet LED enabled

#Use Delay (Clock=25,000,000)

#Use Fast_IO(A)
#Use Fast_IO(B)
#Use Fast_IO(C)
#Use Fast_IO(D)
#Use Fast_IO(E)
#Use Fast_IO(F)
#Use Fast_IO(G)
#Use Fast_IO(H)
#Use Fast_IO(J)

#Byte PortF=0xF85
#Byte TrisF=0xF97

#Bit TogglePin=PortF.0

// Interrupt Service Routines
#Int_Ext
void Int_Ext_isr(void)
{
   TogglePin=!TogglePin;
}

#Int_Ext1
void Int_Ext1_isr(void)
{
   TogglePin=!TogglePin;
}

#Int_Ext2
void Int_Ext2_isr(void)
{
   TogglePin=!TogglePin;
}

#Zero_RAM
void Main(void)
{
    TrisF=0;
    Setup_ADC_Ports(No_Analogs);
    Ext_Int_Edge(0,H_To_L);
    Ext_Int_Edge(1,H_To_L);
    Ext_Int_Edge(2,H_To_L);
    Enable_Interrupts(Int_Ext);
    Enable_Interrupts(Int_Ext1);
    Enable_Interrupts(Int_Ext2);
    Enable_Interrupts(Global);
    do {
        sleep();
        //Delay_us(100);
        //TogglePin=!TogglePin;
        }
    while(1);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 04, 2010 1:33 pm     Reply with quote

My suggestion is, change your code so you don't write directly to Port
registers. Use the CCS i/o functions, which write to the Latch registers.
This is much more reliable. It prevents Read-Modify-Write problems.
Also, get rid of all #use fast_io() and TRIS code. Let the compiler set the TRIS.


Code:

#define LED_PIN  PIN_F0

#Int_Ext
void Int_Ext_isr(void)
{
output_toggle(LED_PIN);
}

// Do the same thing for other #int_ext routines.


void main()
{
output_low(LED_PIN);  // Initially set LED to be Off

.
.
.

Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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