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 CCS Technical Support

TIMER1 during SLEEP with an external oscillator

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



Joined: 24 Nov 2024
Posts: 1
Location: Ecuador

View user's profile Send private message

TIMER1 during SLEEP with an external oscillator
PostPosted: Sun Nov 24, 2024 9:26 pm     Reply with quote

Hello everyone,

I'm working on a project using a PIC16F877A, where I read data from a sensor every minute and display it on an LCD. Afterward, the PIC enters sleep mode. To wake it up, I'm using an external interrupt from RB0 and an interrupt from TMR1. According to the datasheet, in Asynchronous Counter Mode, TMR1 can still count while the PIC is in sleep mode.
For this, I followed the recommended configuration, using a 32kHz crystal with 33pF capacitors. However, the oscillator isn't functioning at all. Any insights into what might be causing the issue or alternatives to this aplication would be greatly appreciated. Thank you in advance!

Code:

#include <16f877a.h>
#device ADC=10
#fuses XT,NOWDT,NOPROTECT,PUT,NOLVP,BROWNOUT
#use delay(clock=4M)
#include <lcd.c>

int ADCV=0,ADCA=0,cont=0;
short sleep_mode;

#INT_TIMER1
void timer1_isr() {
    cont++;

    if (cont >= 19) {
        sleep_mode=FALSE;   
        cont = 0;   
    }
}


#INT_EXT
void RBO (){

static short button_pressed=FALSE;

if(!button_pressed)       
   {
      button_pressed=TRUE;   
      sleep_mode=FALSE;       
      ext_int_edge(L_TO_H);   
   }
   else                     
   {
      button_pressed=FALSE;   
      sleep_mode=TRUE;     
      ext_int_edge(H_TO_L);   
   }
   if(!input(PIN_B0))         
      button_pressed=TRUE;
   delay_ms(100);     
}


void main()

      sleep_mode=FALSE;   
      ext_int_edge(H_TO_L);     
     
      setup_timer_1(T1_EXTERNAL | T1_DIV_BY_1);
      enable_interrupts(INT_TIMER1);   
      enable_interrupts(INT_EXT);
      enable_interrupts(GLOBAL);
     
      setup_adc(ADC_CLOCK_INTERNAL);
      setup_adc_ports(AN0_AN1_AN2_AN3_AN4);
      set_adc_channel(1);
      set_tris_b(0xFF);
     
     
   while(true)
   {
         if(sleep_mode) { 
            sleep();             
         }
         
      delay_us(10);
      ADCA=read_adc();
      ADCV=(ADCA*0.488);
     
      lcd_init();
      delay_ms(10);
      lcd_gotoxy(1,1);
      printf(lcd_putc, "Temp: %u", ADCV);
      delay_ms(2000);   
      sleep_mode=TRUE;
   }
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Mon Nov 25, 2024 2:26 am     Reply with quote

T1OSCEN.

T1_EXTERNAL, says to clock timer 1 from an external clock coming in. Not
to enable the oscillator. Hence your problem. You have to turn the clock output
'on' to make the oscillator run. So:

setup_timer_1(T1_EXTERNAL | T1_DIV_BY_1 |T1_CLK_OUT);

This turns on the oscillator enable bit T1OSCEN.

Your heading for the post says 'external oscillator', but your description says
you want to use the internal T1 oscillator (with external timing components
of course).
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