Reply
Posts: 49
Registered: ‎08-11-2009

C8051F500 Timer issue

Hello,

 

I am facing an issue of Timer. I configured timer 0 / timer 2 as 10ms to detect input signal (500ms on and 500ms off). It detects falling edge. The timer with 10ms is used for debouncing. but after running for several thousands, it will lost some signal detection. Do you encounter any similar issue?

 

the code structure,

 

Initialization:

OSCILLATOR_Init ();

PORT_Init (); // Initialize Crossbar and GPIO

TIMER2_Init (); // Configure Timer0 for use as SMBus clock source

PCA0_Init (); // PCA0 initialization

EA = 1; // Global interrupt enable

 

 

Timer2 (10ms) interrupt routine:

 

INTERRUPT(TIMER2_ISR, INTERRUPT_TIMER2)
{
      TMR2CN &= ~0x80;

     

     if(Pre_ASide_Open_Command_IN && !ASide_Open_Command_IN)
         ASide_OpenDoor_Request = 1;

   Pre_ASide_Open_Command_IN = ASide_Open_Command_IN;
}

 

thanks,

Jiannong

Highlighted
Posts: 8,172
Registered: ‎08-13-2003

Re: C8051F500 Timer issue

 

I am facing an issue of Timer. I configured timer 0 / timer 2 as 10ms to detect input signal

 

 

TIMER2_Init (); // Configure Timer0 for use as SMBus clock source

 

 

what do you mean by " detect input signal" sounds strange for a timer

show your initialize

 

and make what you say timer specific "timer 0 / timer 2" does not help

erik
Posts: 49
Registered: ‎08-11-2009

Re: C8051F500 Timer issue

Hi erik,

 

Thanks for your reply.

 

The timer is 10ms. In interrupt routine, it keeps to check the input signal, if there is a falling edge of the input signal,

 

if (Pre_Input_signal && !Input_signal)

' we detect a falling edge.

...

 

Pre_Input_signal = Input_signal; 

 

We use Timer 0 as general 16-bit Timer.

 

thanks,

Jiannong

Posts: 8,172
Registered: ‎08-13-2003

Re: C8051F500 Timer issue

if (Pre_Input_signal && !Input_signal)

' we detect a falling edge.

 

nobody can help you when you make comments with some variables nobody knows what is

erik
Posts: 2,380
Registered: ‎10-14-2014

Re: C8051F500 Timer issue

I guess you are trying to implement some key deboune with timer.

What do you mean by

-------------------------

it will lost some signal detection.

---------------------------

 

Do you mind upload the code how you define below variable in your code?

Pre_ASide_Open_Command_IN and ASide_Open_Command_IN;

WeiguoLu
Posts: 49
Registered: ‎08-11-2009

Re: C8051F500 Timer issue

Hi Erikm,

 

Sorry. I am busy on the issue debug. I typo for the comment of Timer2_Init(). Please ignore it and see the following code.

 

Initialization:

OSCILLATOR_Init ();

PORT_Init (); // Initialize Crossbar and GPIO

TIMER2_Init (); // Configure Timer2 as 10ms inerval Timer

PCA0_Init (); // PCA0 initialization

EA = 1; // Global interrupt enable

 

void TIMER2_Init (void)
{
U8 SFRPAGE_save = SFRPAGE;
SFRPAGE = ACTIVE_PAGE;

CKCON &= ~0x30; // Timer2 uses SYSCLK/12
TMR2CN &= ~0x01;

TMR2RL = 0xB1A8; // Reload value to be used in Timer2
TMR2 = TMR2RL; // Init the Timer2 register

TMR2CN |= 0x04; // Enable Timer2 in auto-reload mode
ET2 = 1; // Timer2 interrupt enabled

SFRPAGE = SFRPAGE_save;
}

 

 

Timer2 (10ms) interrupt routine:

 

INTERRUPT(TIMER2_ISR, INTERRUPT_TIMER2)
{
      TMR2CN &= ~0x80;

     

     if(!Pre_ASide_Open_Command_IN && ASide_Open_Command_IN)
         ASide_OpenDoor_Request = 1;

   Pre_ASide_Open_Command_IN = ASide_Open_Command_IN;
}

 

The code function:

Each timer2 tick detects input signal "ASide_Open_Command_IN". If old value is low (re_ASide_Open_Command_IN = 0) and new value is high (ASide_Open_Command_IN = 1). a rising edge is detected. 

 

My problem is that after run several hundreds or thousands rising edge detection, there is a lose of rising edge detection. Confirm that the signal is available each time (500ms on/500ms off). Set the interval to 20ms, 50ms, it's not helpful.

 

if i detect the level, it works very well. it continue to run 48 hours without any issue

if (Pre_ASide_Open_Command_IN && ASide_Open_Command_IN)

     ASide_OpenDoor_Request = 1;

 

I suspect it seems timer issue, sometimes the edge is not detected. Is it possible?

 

Please let me know if you have further questions.

 

thanks,

Jiannong

 

 

Posts: 49
Registered: ‎08-11-2009

Re: C8051F500 Timer issue

Hi Delu,

 

the variable definition:

bit Pre_ASide_Open_Command_IN;

SBIT (ASide_Open_Command_IN,SFR_P3, 7);

 

How to upload the code into here?

 

thanks,

Jiannong

 

Posts: 8,172
Registered: ‎08-13-2003

Re: C8051F500 Timer issue

you are babbling about 'rising edges' and the only thing you have is a change causing "open door"

 

AGAIN if you can't be clear you can't get help

 

I appreciate there may be a language problem. but the above is just a muddle

erik