CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

NCO operation with PIC10LF322

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
starfire151



Joined: 01 Apr 2007
Posts: 195

View user's profile Send private message

NCO operation with PIC10LF322
PostPosted: Sat Jun 20, 2015 2:50 pm     Reply with quote

Hi All -

I'm trying a simple test to get the NCO module in a PIC10LF322 to output a square wave at ~250Hz when using the HFINTOSC selection (the internal 16MHz oscillator). My code is as follows:
Code:

#include <10LF322.h>
#device ADC=16
#define CLK_FREQ 16000000
#use delay(internal = CLK_FREQ)

// ---- NCO module registers ----
#byte NCO1ACCL = getenv("SFR:NCO1ACCL")
#byte NCO1ACCH = getenv("SFR:NCO1ACCH")
#byte NCO1ACCU = getenv("SFR:NCO1ACCU")
#byte NCO1INCL = getenv("SFR:NCO1INCL")
#byte NCO1INCH = getenv("SFR:NCO1INCH")
#byte NCO1CON = getenv("SFR:NCO1CON")
#byte NCO1CLK = getenv("SFR:NCO1CLK")
#bit N1EN = NCO1CON.7

// ---- reference clock register ----
#byte CLKRCON = getenv("SFR:CLKRCON")
#bit CLKROE = CLKRCON.6

#use fixed_io(a_outputs=PIN_A2)

void main()
{
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);

   set_tris_a(0x0b); // only pin A2 is an output
   
   CLKROE = 0;       // disable reference clock when using NCO
   
   N1EN = 0;         // disable NCO while initializing values

   NCO1CON = 0x50;   // N1EN=0; N1OE=1; N1POL=1; N1PFM=0
   NCO1CLK = 0x00;   // N1CKS[1:0]=00 => HFINTOSC clk src (16MHz)
   
   NCO1ACCL = 0x00;  // clear accumulator
   NCO1ACCH = 0x00;
   NCO1ACCU = 0x00;
   
   NCO1INCL = 16;    // set increment value for ~250Hz output
   NCO1INCH = 0;
   
   N1EN = 1;         // enable NCO now
   
   while(TRUE)
   {

   }
}


I checked the note in the errata sheet stating to clear the CLKROE bit when using the NCO. I did this at the beginning of the program.

I tried several variations but nothing seems to work.

Is there something fundamental I'm overlooking?

Thanks for any help.
starfire151



Joined: 01 Apr 2007
Posts: 195

View user's profile Send private message

PostPosted: Sat Jun 20, 2015 2:53 pm     Reply with quote

If forgot to mention my specifics:
Compiler: PCWHD V5.044
Computer: Win 7 32-bit
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jun 20, 2015 6:32 pm     Reply with quote

What happens if you use the CCS example from the manual:
Code:

setup_nco(NCO_ENABLED|NCO_OUTPUT|NCO_FIXED_DUTY_MODE|NCO_CLOCK_FOSC, 8192);

It compiles to this with vs. 5.044:
Code:

001C:  BCF    NCO1CON.N1EN
001D:  MOVLW  FB
001E:  MOVWF  TRISA
001F:  MOVLW  20
0020:  MOVWF  NCO1INCH
0021:  CLRF   NCO1INCL
0022:  MOVLW  01
0023:  MOVWF  NCO1CLK
0024:  MOVLW  C0
0025:  MOVWF  NCO1CON


Also, asmboy has posted demo code for the 16F1509 NCO module here:
http://www.ccsinfo.com/forum/viewtopic.php?t=50121
starfire151



Joined: 01 Apr 2007
Posts: 195

View user's profile Send private message

PostPosted: Sat Jun 20, 2015 8:18 pm     Reply with quote

That worked! Great!

Now I have something to compare to Very Happy

Thanks.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group