wuiven64
Newbie
Hi. I'm using PIC16F877A with 20 MHz crystal and PICkit 2 programmer to generate a 180 kHz square wave using TIMER1. However, the waveform that I obtained from Tektronix TPS2014 oscilloscope s not the desired waveform. Besides that, the measured frequency from the oscilloscope is far from the desired frequency. I have attached the code and waveform that capture from the oscilloscope. Kindly give some advice. Thanks.
Code to generate 180 kHz square wave using TIMER1. The compiler is CCS C compiler Ver. 5 demo:
Code to generate 180 kHz square wave using TIMER1. The compiler is CCS C compiler Ver. 5 demo:
Code:
#include <TIMER1.h>
#INT_TIMER1
void timer1_isr(void)
{
output_toggle(PIN_B0);
clear_interrupt(INT_TIMER1);
set_timer1(65508);
}
void main()
{
setup_timer_1 ( T1_INTERNAL | T1_DIV_BY_1 ); // Internal clock and prescaler 1
set_timer1(65508); // Preload value
clear_interrupt(INT_TIMER1); // Clear Timer1 interrupt flag bit
enable_interrupts(INT_TIMER1); // Enable Timer1 interrupt
enable_interrupts(GLOBAL); // Enable global interrupts
output_low(PIN_B0);
while(TRUE) ; // Endless loop
}
Attachments
Last edited by a moderator: