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

RTOS and Interrupt Timer, CCP2

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



Joined: 21 Oct 2012
Posts: 8

View user's profile Send private message Yahoo Messenger

RTOS and Interrupt Timer, CCP2
PostPosted: Thu Sep 17, 2015 8:04 am     Reply with quote

Hi!
Can you help me?
I use RTOS and Interrupt Timer 1. When I turn off Timer 1 then ccp2 happen but when i turn on Timer 2 then Interrupt ccp2 can't do.
This is my code:
Code:

#include "E:\reading\Lab\Distant sensor\example\CCP\RTOS.h"

#define TRIGGER PIN_A3
int16 fall, rise;
int echo = 0;

#use rtos(timer = 0, minor_cycle = 10ms)

#task (rate = 1000ms, max = 10ms)
void Init_Sensor();
/*
#task (rate = 100ms, max = 10ms)
void display();
*/
void trig()
{
   output_high(TRIGGER);
   delay_us(10);
   output_low(TRIGGER);
}
/*
double dis()
{
   return (double)(fall - rise)*0.8/56;
}

void display()
{
   printf("Khoang cach = %f \n",dis() );
}
*/
void Init_Sensor()
{
   echo = 0;
   setup_ccp2(CCP_CAPTURE_RE);
   trig();
   //printf("Init \n");
}

#int_CCP2
void  CCP2_isr(void)
{
   if(echo == 0)
   {
      rise = CCP_2;
      setup_ccp2(CCP_CAPTURE_FE);
      echo = 1;
      printf("echo = 0 \n");
   }
   else
   {
      fall = CCP_2;
      printf("echo = 1 \n");
   }
}

void main()
{

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_CLOCK_DIV_2|ADC_TAD_MUL_0);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   
   enable_interrupts(INT_TIMER1);
   enable_interrupts(INT_CCP2);
   enable_interrupts(GLOBAL);
//Setup_Oscillator parameter not selected from Intr Oscillator Config tab

   // TODO: USER CODE!!
   
   rtos_run();
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Sep 18, 2015 9:46 pm     Reply with quote

Quote:
but when i turn on Timer 2 then Interrupt ccp2 can't do.

I don't see any place in your code where you turn on Timer2.
Ttelmah



Joined: 11 Mar 2010
Posts: 19549

View user's profile Send private message

PostPosted: Sat Sep 19, 2015 12:28 am     Reply with quote

There is also the old classic 'wrong line':

setup_spi(SPI_SS_DISABLED);

This _enables_ the SPI, with the slave select disabled.
The command to disable the SPI, is:

setup_spi(FALSE);

Can affect how other parts work....
lambk89



Joined: 21 Oct 2012
Posts: 8

View user's profile Send private message Yahoo Messenger

PostPosted: Sun Sep 20, 2015 7:55 am     Reply with quote

Sorry! That's timer 1 not timer 2.
lambk89



Joined: 21 Oct 2012
Posts: 8

View user's profile Send private message Yahoo Messenger

PostPosted: Sun Sep 20, 2015 7:57 am     Reply with quote

Ttelmah wrote:
There is also the old classic 'wrong line':

setup_spi(SPI_SS_DISABLED);

This _enables_ the SPI, with the slave select disabled.
The command to disable the SPI, is:

setup_spi(FALSE);

Can affect how other parts work....


I setup_spi like you but CCP2 not work.
lambk89



Joined: 21 Oct 2012
Posts: 8

View user's profile Send private message Yahoo Messenger

PostPosted: Sun Sep 20, 2015 7:58 am     Reply with quote

PCM programmer wrote:
Quote:
but when i turn on Timer 2 then Interrupt ccp2 can't do.

I don't see any place in your code where you turn on Timer2.


Sorry! I write wrong. That's timer 1
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Sep 20, 2015 10:07 am     Reply with quote

Quote:

setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
enable_interrupts(INT_TIMER1);
enable_interrupts(INT_CCP2);
enable_interrupts(GLOBAL);

The reason is because you don't have an interrupt routine for Timer1.
You have enabled INT_TIMER1 interrupts, but without an #int_timer1
routine, the Timer1 interrupt flag bit will never be cleared. So, you will
get continuous Timer1 interrupts and your program will appear to be
locked up. Your program will spend all of its time executing the CCS
global interrupt handler code.

At a minimum, you need to add the following code to your program:
Code:

#int_timer1
void timer1_isr(void)
{

}
lambk89



Joined: 21 Oct 2012
Posts: 8

View user's profile Send private message Yahoo Messenger

PostPosted: Mon Sep 21, 2015 11:26 am     Reply with quote

PCM programmer wrote:
Quote:

setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
enable_interrupts(INT_TIMER1);
enable_interrupts(INT_CCP2);
enable_interrupts(GLOBAL);

The reason is because you don't have an interrupt routine for Timer1.
You have enabled INT_TIMER1 interrupts, but without an #int_timer1
routine, the Timer1 interrupt flag bit will never be cleared. So, you will
get continuous Timer1 interrupts and your program will appear to be
locked up. Your program will spend all of its time executing the CCS
global interrupt handler code.

At a minimum, you need to add the following code to your program:
Code:

#int_timer1
void timer1_isr(void)
{

}


Thanks!
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