I am currently using your product which is SK40C plugged with PIC18F4550 for my project. For coding I am using MPLab IDE and PICKit 2 Programmer.
Initially, to confirm all the connection , the build and upload process into the PIC worked successfully, I have done a simple blink LED project and it worked well.
But when I tried to execute my other project , which is the about generating the frequency using interrupt and external clock, it does not seems to display the desired frequency output. What shown on the oscilloscope is only a high 5V signal without any visible waveform.
Is there any additional configurations needed since I am using external clock and using interrupt, either in MPLab or PICKit?
Here's the source file:
- CODE: SELECT_ALL_CODE
#include <p18f4550.h>
#define HZ 8000000 // 16MHz HS xtal = 16000000
#define TOGGLE (HZ * 125)
// RAM vars
volatile unsigned long accum;
volatile unsigned long freqHz;
//=============================================================================
// INTERRUPT
//=============================================================================
void interrupt(void)
{
//-------------------------------------------------------
// This is the TMR2 interrupt, set to 100 timer ticks.
// Frequency generation is done by a combination of DDS accumulator
// and a decimal bresenham subtraction that makes the value
// in actual decimal fractions of Hz.
//-------------------------------------------------------
PIR1bits.TMR2IF = 0; // clear TMR2 roll flag
accum += freqHz; // decimal DDS addition into accumulator
if(accum >= TOGGLE)
{
PORTB = (PORTB ^ 0x01); // toggle output pin to make frequency
accum -= TOGGLE; // decimal bresenham subtraction, keep remainder
}
}
//-----------------------------------------------------------------------------
//=============================================================================
// MAIN
//=============================================================================
void main(void)
{
//-------------------------------------------------------
// setup PIC 16F628A
CMCON = 0x07; // comparators OFF
PORTA = 0b00000000; // PORTA all outputs
TRISA = 0b00000000;
PORTB = 0b00000000; // RB0 is freq output, rest of PORTB also outputs
TRISB = 0b00000000;
// setup TMR2 to roll every 200 ticks
T2CON = 0b00000100; // TMR2 ON, 1:1 prescale
PR2 = (100-1); // TMR2 int occurs every 100 ticks
// enable interrupt here (and just leave TNR2 int running in this example)
INTCON = 0b11000000; // GIE = ON, PEIE = ON
PIE1bits.TMR2IE = 1; // TMR2 interrupt ON
// To set the frequency just set the freqHz variable.
// If working with low frequencies it may be good to
// clear the accumulator. Also, start the interrupt if needed.
// Note! This variable is in Hz*100000, so 23Hz = 2300000
freqHz = 2312345; // 23.12345 Hz
accum = 0;
//-------------------------------------------------------
// This is the main running loop/
// To turn the output freq ON, enable TMR2 interrupt; (PIE1.TMR2IE = 1;)
// To turn the output freq OFF, disable TMR2 interrupt; (PIE1.TMR2IE = 0;)
while(1)
{
//---------------------------------------------
// your code goes here!
PIE1bits.TMR2IE = 1;
}
}
//-----------------------------------------------------------------------------
Looking forward for your kind assistance.