Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem with PIC 16F877A: related to timer1

Status
Not open for further replies.

aamiralikhoja

Member level 5
Joined
Aug 11, 2004
Messages
90
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
708
to Pic masters

hello

I have strange problem regarding pic16f877A .I want To use Pic timer1 as

event Counter .Clock Is attached to T1CLK .and I want to count 8 clocks


and then toggle port B bit .Programm is well running in proteus .But at treal

hardware programm is not running . I am using css c compiler .


source code is as follow:


#int_TIMER1
TIMER1_isr() {
set_timer1(0xfff9);
output_bit(PIN_B0,1);
}



void main() {

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_2);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_counters(RTCC_INTERNAL,WDT_18MS);
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);
setup_timer_2(T2_DISABLED,0,1);

/************* PORT INIT *************/
Set_Tris_B(0x00);
Set_Tris_D(0xff);
enable_interrupts(INT_TIMER1);
enable_interrupts(global);
set_timer1(0xfff9);
do
{
output_bit(PIN_B0,0);
}while(1);

}

Please note that I have tested some simple programms except timer1 on same

hardware they are running quite well but timer1 is not running .Schematic of

hardware is attached.
 

Re: to Pic masters

humm...

I hope I don't miss something obvious, but here's what I think is the problem :

do
{
output_bit(PIN_B0,0);
}while(1);

You force the pin to 0 in your main loop. You will set the pin to 1 when your timer event occurs, but it will go back to 0 as soon as the execution returns to the main program.

Consider using a xor or the bit toggle instruction to toggle your output, and don't change it in the main loop!

Hope it helps,

cyberblak
 

Re: to Pic masters

Hi!
First of all set the pin getting the timer clock pulse to input i.e set the corresponding TRIS bit to 1.
Also it has been mentioned in the data sheet

" When Timer1 is being incremented via an external
source, increments occur on a rising edge. After Timer1
is enabled in Counter mode, the module must first have
a falling edge before the counter begins to increment."

I hope that will solve your problem.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top