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

Question about NCO demo code

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



Joined: 06 Oct 2006
Posts: 13

View user's profile Send private message

PostPosted: Wed Jan 21, 2015 1:01 pm     Reply with quote

I am now trying to use asmboy's demo code for the NCO - without luck.
Code:

#include "G:\PICC\NCO\NCO.h"
const unsigned int16 NcIcr[10]={20,100,200,500,1000,4000,8000,12000,20000,50000};
//frequency table in ~~ HZ above using INTOSC
void main()
{
   unsigned int8 fp=0;   // init the NCO to appx 4khz
   setup_nco(NCO_ENABLED|NCO_OUTPUT|NCO_FIXED_DUTY_MODE|NCO_CLOCK_FOSC,4000);
   while (1)
   {
     output_high(LED);
     delay_ms(3000); // wait 3 seconds
     set_nco_inc_value(NcIcr[fp++]);
     output_low(LED);
    if (fp>9) fp=0;
   }
 
}

With NCO.h
Code:

#include <16F1718.h>
#device ADC=10
#use delay(internal=8000000)

#define LED PIN_C0
#define DELAY 1000
#pin_select NCO1OUT=PIN_C3

The code gets lost after the set nco_inc_value.
-Bruce
Ttelmah



Joined: 11 Mar 2010
Posts: 19369

View user's profile Send private message

PostPosted: Thu Jan 22, 2015 3:35 am     Reply with quote

Compiler version?......
That way we can duplicate and see if it is a compiler problem (quite likely with this relatively new chip...).

Separately, look at:
<http://www.ccsinfo.com/forum/viewtopic.php?t=52628&highlight=nco>

A few weeks after the original post, Asmboy found problems with the CCS function causing glitching when changing the frequency, and posted this replacement version. Worth trying.

Third thing. It is common for the compiler to _not_ set TRIS when it is used with peripherals with relocatable pins. You may want to do this. (output_drive(PIN_C3);).

When you say 'lost', what do you mean?.
The actual setting of the frequency, only writes to the register. Could easily be the wrong register, but it shouldn't make the code go astray. Are you sure it is not doing something like a watchdog restart?. A lot of the newer chips default to enabling the watchdog. Notice you are not turning it off....
dish_moose



Joined: 06 Oct 2006
Posts: 13

View user's profile Send private message

PostPosted: Thu Jan 22, 2015 6:48 am     Reply with quote

Compiler ver. 5.036
By lost I mean when I step through it never comes back after the
"set_nco_inc_value(NcIcr[fp++]);"
-Bruce
Edit: Ttelmah - TRIS was the issue - I now have NCO - Thanks.
Ttelmah



Joined: 11 Mar 2010
Posts: 19369

View user's profile Send private message

PostPosted: Fri Jan 23, 2015 2:23 am     Reply with quote

That is one that is well worth 'filing' as likely. Smile

CCS defaults to setting the TRIS for fixed pins, but when #pin select is used often doesn't realise the TRIS needs to be set or cleared.

Interesting that it hung. Presumably was checking for a 'status' return somewhere (will have to look at the code), which wasn't happening, because the signal was not coming out the pin....
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