avr code to code for PIC

Status
Not open for further replies.
Damn!!!

I picked the wrong micro!!! the serial port is on portb... changing to the slightly bigger pic16f1828 or 9..

I could swap to port a... I'll try that first!....
 
Ian, I just found some old notes on another method which pretty much eliminates frequency selection maths. I recall simulating it but I never tested on real hardware. I hope you or other members may find it useful.

Cheerful regards, Mike

Code:
;******************************************************************
;  more DDS musings                                  Mike, K8LH   *
;******************************************************************
;
;  use an 18F14K22 (64-MHz), a 32 cycle (500-kHz) DDS loop, and
;  25.575 bit accumulator and phase variables for a 0.01-Hz DDS
;  frequency resolution (log500000*100/log2).  subtract phase
;  offset each loop and add 500000*100 on accumulator underflow
;  then use upper 9.575 accumulator bits (b25..b16) as an index
;  into a 763 byte (2^9.575) sine array.
;
;  stuff 'phase' offset variable with frequency*100 values (use
;  75000 for 750.00-Hz, 104005 for 1040.05-Hz, etc).  consider
;  limiting upper frequency to 16 samples per cycle (500000/16)
;  which is 31250.00 Hz.  Experiment to determine lower limit.
;
dds64
        movf    phase+0,W       ; subtract phase offset from
        subwf   accum+0,F       ; the phase accumulator
        movf    phase+1,W       ;
        subwfb  accum+1,F       ; accumulator b15..b8
        movf    phase+2,W       ;
        subwfb  TBLPTRL,F       ; accumulator b23..b16
        movf    phase+3,W       ;
        subwfb  TBLPTRH,F       ; accumulator b25..b24
;
;  add 500000*100 to accumulator on accumulator underflow
;
        movlw   500000*100%0x0000100
        btfsc   TBLPTRH,7       ; negative? no, skip, else
        addwf   accum+0,F       ;
        movlw   500000*100/0x0000100
        btfsc   TBLPTRH,7       ; negative? no, skip, else
        addwfc  accum+1,F       ;
        movlw   500000*100/0x0010000
        btfsc   TBLPTRH,7       ; negative? no, skip, else
        addwfc  TBLPTRL,F       ;
        movlw   500000*100/0x1000000
        btfsc   TBLPTRH,7       ; negative? no, skip, else
        addwfc  TBLPTRH,F       ;

        movf    tbladdr,W       ; tables 1000, 1400, 1800, 1C00
        iorwf   TBLPTRH,F       ; select proper table
        tblrd*                  ; uses 2 cycles
        movff   TABLAT,PORTC    ; 8-bit sine value
        xorwf   TBLPTRH,F       ; restore accumulator value
        nop                     ;
        nop                     ;
        nop                     ;
        bra     dds64           ; must be exactly 32 cycles total

;******************************************************************
 
Last edited:
Cheers Mike..
The PORTA selection was useless anyway RA5 is a input only...

The conversion is taking up too much of my time so I suggest the OP uses your code.... He can then get the serial code from Nigels tutorials....

I don't need DDS code, I was trying to help the OP ( who seems to have disappeared..)
 
Can anyone suggest a means/method to do FHT on a PIC using asm? In order to differentiate the phase difference among 4 mic. sound streams? Thus assessing sound localization?
Sound freq range 0-8Khz. 250mS processing time per assessment.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…