asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
fix mystery glitches in CCS NCO functions for 16f1509 |
Posted: Fri Jul 11, 2014 9:25 am |
|
|
I found that when jamming new frequencies into the NCO using the CCS function that there was frequent glitching of my pulse train.
This is a function that appears to correct the problem.
( NCO used for stepper motor pacing - and the problem
could be HEARD before it was seen )
Code: |
void setNCOfreq(unsigned int16 pfreq){
// bank nine page 31 of data sheet
STATIC int Psetupok;
#WORD ncoinc=0x49B
// detect STOP CMD
if (!PFreq) {
setup_nco(NCO_DISABLED|NCO_FIXED_DUTY_MODE|NCO_CLOCK_FOSC,0);
Psetupok=0;
}
else {
if(0==psetupok){
setup_nco(NCO_ENABLED|NCO_OUTPUT|NCO_FIXED_DUTY_MODE|NCO_CLOCK_FOSC,pfreq);
Psetupok=1;
} // avoid glitches induced when NCO is already generating
else ncoinc=pfreq;
}
}
|
|
|