View previous topic :: View next topic |
Author |
Message |
dish_moose
Joined: 06 Oct 2006 Posts: 13
|
|
Posted: Wed Jan 21, 2015 1:01 pm |
|
|
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: 19539
|
|
Posted: Thu Jan 22, 2015 3:35 am |
|
|
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
|
|
Posted: Thu Jan 22, 2015 6:48 am |
|
|
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: 19539
|
|
Posted: Fri Jan 23, 2015 2:23 am |
|
|
That is one that is well worth 'filing' as likely.
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.... |
|
|
|