Angry Badger
Member
Hi,
Can anyone give me some guidance on how to 'do' pfm i.e. pulse frequency modualtion in MCC18
I've built a little stepper driver board around a L297. Using an 18f2420 I want to provide a variable clock signal so as to vary the speed of the stepper. Can do this at the moment but the the outputted clock signal ain't linear.
Thanks in advance for any help.
**broken link removed**
**broken link removed**


**broken link removed**
Can anyone give me some guidance on how to 'do' pfm i.e. pulse frequency modualtion in MCC18
I've built a little stepper driver board around a L297. Using an 18f2420 I want to provide a variable clock signal so as to vary the speed of the stepper. Can do this at the moment but the the outputted clock signal ain't linear.
Thanks in advance for any help.
Code:
// Read adc value and output value as a frequency to clk L297
#include <p18f2420.h>
#include <adc.h> //the code for the adc routine is in here
#include <stdlib.h>
#include <delays.h> //the code for the delay routines is in here
#pragma config OSC = INTIO7 //Internal oscillator with Fosc/4 on RA6, I/O on RA7
#pragma config WDT = OFF
int result; //put this here to clr the 'out of scope' msg in watch window
#define clk PORTAbits.RA5 //pin 7
void clksig (void) //clk signal to L297 stepper controller inversely proportional to ADRESH
{
clk = 1;
Delay1KTCYx(result); //delay = 1000 x instruction cylce time x ADRESH
clk = 0;
Delay1KTCYx(result);
}
void main (void)
{
OSCCON = 0b01100010; //set Fosc = 4Mhz
TRISA = 0x1;
TRISAbits.TRISA0=1; // ADC input on pin 2
OpenADC(ADC_FOSC_RC &
ADC_LEFT_JUST &
ADC_0_TAD, ADC_CH0 &
ADC_INT_OFF &
ADC_VREFPLUS_VDD &
ADC_VREFMINUS_VSS, 0 );
while (1)
{
ConvertADC(); // Start conversion
while(BusyADC()); // Wait for completion
result = 256 - ADRESH; //result = ADRES high byte (i.e. left justified)
clksig();
}
}
**broken link removed**





**broken link removed**