Hi Folks,
I am using a PIC 12F683 microcontroller to generate periods of 32µs and 6µs on PINs 6 and 5, respectively. I am using an external 10MHz crystal oscillator for the clock source. I have already written the code and flashed it to the chip. However, when verifying the output with an oscilloscope, I am not getting the expected period signals. Instead, I am seeing 240µs signals with varying duty cycles. I programmed the code to achieve a 50% duty cycle.
Here are some additional details:
I am using a PIC 12F683 microcontroller to generate periods of 32µs and 6µs on PINs 6 and 5, respectively. I am using an external 10MHz crystal oscillator for the clock source. I have already written the code and flashed it to the chip. However, when verifying the output with an oscilloscope, I am not getting the expected period signals. Instead, I am seeing 240µs signals with varying duty cycles. I programmed the code to achieve a 50% duty cycle.
Here are some additional details:
- Microcontroller: PIC 12F683
- Clock Source: 10MHz external crystal oscillator
- Expected Output: 32µs and 6µs periods on PINs 6 and 5 with 50% duty cycle
- Observed Output: 240µs signals with different duty cycles
- Software MPLAB X IDE v6.20
Code:
#include <xc.h>
#define _XTAL_FREQ 10000000 // 10 MHz crystal
void delay_us(unsigned int us) {
while(us--) {
__delay_us(1);
}
}
void main(void) {
#pragma config FOSC = XT // Select external XT oscillator
#pragma config WDTE = OFF // Disable watchdog timer
#pragma config PWRTE = OFF // Power-up timer disabled
#pragma config MCLRE = ON // GP3/MCLR pin function is MCLR
// Set up the oscillator to use the external 10 MHz crystal
OSCCON = 0x00; // External oscillator selected (no internal oscillator used)
// Set all pins as digital I/O
ANSEL = 0x00;
ADCON0 = 0x00;
// Set pin directions
TRISIO = 0b11111001; // GP1 and GP2 as output, others as input (GP0, GP3-GP5 are input)
// Main loop
while(1) {
// Generate 32 µs pulse on GP1 (pin 6) with 50% duty cycle
GPIO |= 0b00000010; // Set GP1 high
delay_us(16);
GPIO &= ~0b00000010; // Set GP1 low
delay_us(16);
// Generate 6 µs pulse on GP2 (pin 5) with 50% duty cycle
GPIO |= 0b00000100; // Set GP2 high
delay_us(3);
GPIO &= ~0b00000100; // Set GP2 low
delay_us(3);
}
}