News:

Let's find out together what makes a PIC Tick!

Main Menu

PIC16F15376 NCO

Started by JONW, Jan 24, 2023, 05:19 PM

Previous topic - Next topic

JONW

Has anyone had any issues with the NCO in the P16F15376?  I just cant seem to be able to get anything more than 3.9kHz

It has a 20bit increment counter and a 20 bit acc so in theory it should be able to go right up to FOSC!  working on the curiosity nano

SETUP

'NCO SETUP
        NCO1CON = %10010000             ' NCO ON,  NON INVERTED, FIXED DUTY
        NCO1CLK = %00000000             ' CLK FOSC
        NCO1INCL = $FF                  ' SET INC TO 20 BIT MAX
        NCO1INCH = $FF                  '
        NCO1INCU = $FF                  '
        RD3PPS = $1A                    ' NCO OUT TO PORTD.3

The asm also looks ok

F1_000278 equ $ ; in [CERTUS_TX_V1.BAS] T0CON0 =    %10000000
    movlb 0x0B
    movlw 128
    movwf T0CON0
F1_000279 equ $ ; in [CERTUS_TX_V1.BAS] T0CON1  =   %01000101
    movlw 69
    movwf T0CON1
F1_000281 equ $ ; in [CERTUS_TX_V1.BAS] NCO1CON = %10010000
    movlw 144
    movwf NCO1CON
F1_000282 equ $ ; in [CERTUS_TX_V1.BAS] NCO1CLK = %00000000
    clrf NCO1CLK
F1_000283 equ $ ; in [CERTUS_TX_V1.BAS] NCO1INCL = $FF
    movlw 255
    movwf NCO1INCL
F1_000284 equ $ ; in [CERTUS_TX_V1.BAS] NCO1INCH = $FF
    movwf NCO1INCH
F1_000285 equ $ ; in [CERTUS_TX_V1.BAS] NCO1INCU = $FF
    movwf NCO1INCU
F1_000289 equ $ ; in [CERTUS_TX_V1.BAS] UNLOCKPPS()
    movlb 0x00
    movlp ((UNLOCKPPS) >> 8)   



JONW

DOH. my fault
you need to load U then H then L in the inc reg!!

Woking now, very cool bit of hardware with a 20bit Inc!


Yves

I often notice when I'm stuck with a problem and then start typing the issue on the forum I find my own answer. That is why most of the time I type it first in a text editor before pasting to the forum. It is bit like you in the forest I don't see the trees.  :-[

Yves 
Yves

GDeSantis

I don't have a PIC16F15376; but an NCO program example using a PIC16F18323 is attached.

top204

What is the highest frequency you can get out of the NCO at 32MHz fOsc Jon? And at what frequency change resolution?

I have the PIC16F15376 family running nicely now with the compiler's commands and will upload an update in the next couple of days, but my scope is missing somewhere so I cannot test the NCO frequencies. I ask because it may work as the oscillator for a MW, AM transmitter, once the square is filtered to sine waves. So approx 500KHz to 2MHz square wave would do the trick nicely.

John Lawton

Aha, could be useful for local transmissions to old AM/MW valve radios in the house. How would you do the AM though?

JONW

#6
Hi Les

For 32MHz its 16MHz at 15.25Hz resolution.  Attached Pics of it running at full speed from the internal OSC, when a 2^n division is in the INC Reg the jitter is minimal and due the the nature of the NCO and its roll over (without resetting the ACC in an interrupt) the jitter is related to the overflow of the acc and is carried over in the adder.  Attached some shots of the math and screenshots from the scope I have here.  Am not in the lab so am limited to a few G/S with a Pico3406 but you an see its clean at 16MHz, if you are interested I can feed it into a Speccy next week when i'm in the Lab and show a plot well into GHz range and a decent shot close to carrier (jitter).  I am modulating this particular NCO at  low bit rate OOK 1/3rd bit timing and the control is crisp.  The plots are running in Fixed Duty but there are Pulse Freq modes and you can drive into the CLC for other modulation schemes.

As this is Hardware I recon you could easily overclock this well beyond 100MHz Pushing into the FM band and then you could do OOK or FSK into the FM band or pick off a harmonic in the UHF and probably L-Band!

just added filtered version (applied digital filter).  Aslo a  Jitter trace (persistence) for a non 2^n increment value.  The jitter improves with a higher fosc for a given fout. 



calcs.jpgNCOjpg.jpgBURST MODULATEDjpg.jpg16MHz.jpg  Not a valid attachment ID.LPF 16M.jpgjitter.jpg

JONW

Drive the output through a single pin diode driven from the DAC, PWM or R2R ladder would do direct AM nicely, with a bit of memory you could send data or voice from flash, ( Its just a very basic digitally controlled attenuator).  A Quad Pin would give a better return loss. 

top204

#8
Wow!!!! Many thanks Jon, but you went a bit over my head with Pin diodes etc... LOL I've only ever used Pin diodes once before as an aerial switcher back in the 1980s. :-)

QuoteAha, could be useful for local transmissions to old AM/MW valve radios in the house. How would you do the AM though?

That is exactly what I want to build. :-) AM modulation would a simple audio amplifer feeding the collector of the final RF amplifier. I used to make them as a boy, but always had a transistor oscillator that was fiddly and drifted and required a coil and a variable capacitor or varactor etc, but an inexpensive microcontroller would give the ability to use a rotary encoder and a simple LCD display.


John Lawton

RF amplifier? How much power will you be running :)

I was thinking of using the venerable MC1496 as mentioned in this interesting video, which actually describes DSBSC modulation. https://www.youtube.com/watch?v=7nmmb0pqTU0

The MC1496 datasheet shows how to use it as an AM modulator. https://www.onsemi.com/pdf/datasheet/mc1496-d.pdf

Maybe follow it with an output buffer amp and a longish wire, it would only have to cover the house, not the street.

JONW

#10
Pin diodes are VERY simple  (just over complicated in books by engineers thinking they are trying to prove something)<<<<<< easier than a Transistor, just need to understand and picture the electron flow for the Chip and as frequency increases include package parasitics, bond wires, trace capacitances etc.  At sub 1Ghz (wiggly DC).  OFF they look like a very small capacitor (very small << 5pF) and the isolation (reverse) is best with reverse bias  but can be 0V at low frequencies.  ON, they look like a resistor.  In between think of them as a very broadband variable resistor.... Simples as that furry Meercat says

Pins are cool, they can be used as switches, broadband and narrowband with transmission lines, modulators (AM via attenuation), variable attenuators, limiters, they are fast, cheap and easy to control.  A $0.02 silicon Pin (not Gaas) can be used to low Ka band, not continuously but in bands, then you can use the bond wires and the OFF capacitance to create switches using the capacitance in the off state as on.  In a Quad config the impedances balance so you get a good S11 Vs attenuation, Vs frequency, basically  you configure the series shunt combination to maintain S11.

With 1 pic, 1 diode, a few L & C and a $0.02 BJT you can easily do that.  Get 10mW easy from a BJT running 20 - 30mA.  Also recon you could use parts of the CLC as a mixer, its a simple logic gate that theoretically has infinite gain, hence is highly nonlinear and a simple gate can be used as a switching mixer (if Fmod << FCarrier),  simple 74HC1G14GW switch can be a fantastic mixer, purely resistive/gated digitally or in a FET by the LO waveform..  Sampling mixer, just like the latest digital SDR of decimation and interpolation, mathematical summation (switching) in digital domain but broken down into math that's been there for 50 yrs or more. 

I still tend to view RF or electron flow (with the exception of Quantum Physics for the academics here) as fluid/flow and visualise components that way. 


We us a single GaaS fet at 20G in switching mixer config as a great mixer, up and down.  Very, very basic physics and most is lost information as todays engineers run straight for a SOC solution.  We still make DRO's and discrete mixers, LNA, VCO etc  1Hz to 1THz, its just physics and almost all people that can do this at 50khz can do the same 50G, its understanding the basics and applying actually applying logic in most cases.  Us a $5 chip, ok it works, and usually very well VS a few discrete parts, works ok and sometimes (rarely) better but is cheap and doesn't go EOL!

Sorry Chaps I can waffle for hours :-)









top204

The MC1496 device is now quite expensive to buy compared to a small, low powered, RF transistor, and not really repeatable.

I did some tests a few years ago using a TDA2820 amplifer feeding the VDD to the small RF amplifer, and the audio quality was very acceptable with the correct de-coupling and filtering and volume setting.

John Lawton

RS are selling them for £0.894 each in packs of 10 which isn't a bad price. Surprisingly PIN diodes I've seen aren't generally cheaper.

I'm not sure what you mean by not repeatable.

For the sort of microtransmitter device I'm looking at, I wouldn't want to use a tuned RF amplifier to avoid the need for retuning it for different frequencies / output loads and to prevent any RF bandwidth restriction it would cause which would of course affect the audio bandwidth too. AM can sound quite good if there is wide audio bandwidth and no compression.

top204

For the idea I have in mind for the MW, AM transmitter, another chip costing nearly £1 is not feasible for it. The MC1496 devices are also quite old, so they will become harder and harder to get over time, and as prices show, they vary so much in price and availability.

The final amplifier needs no coils, because it is a wide-band amplifier and is only the modulation mechanism and the buffer between the oscillator, square to sine filter, and the antenna. Any small NPN transistor will suffice, and they are plentiful and extremely inexpensive.

The buffer will suffice to have a range of 1m to 5m for the transmitter and the radio being used.

John Drew

I hope the filter is good if you're using a broadband amp. The 3rd harmonic is usually the worst offender. I think the standard is for it to be 60dB down.
It's amazing how far these small power devices will travel.
Various digital devices (especially switch mode power supplies) and their harmonics are killing our low frequency amateur radio bands.
Just a thought for consideration.
John

John Lawton

Good point, adding a third harmonic LPF shouldn't be a problem.

John Lawton

I've just had a thought, in days of old university campuses would put leaky loop cables around them to give MW coverage for the student radio. Could do the same in the home, avoiding interference to neighbours.

top204

#17
I'm sure I used an MC1496 back in the late 1980s to make a frequency doubler for a guitar effect and a Dalek voice effect. :-)

Sorry Jon, the thread has drifter off track a bit, but with very interesting stuff in it. :-)

JONW

O worries, It's all good info and my NCO is running OK.