;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; 4 Tone CTCSS generator ; for Australian VHF and UHF Repeaters ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Author: John Kent - VK3BIZ ; Revision: 0.1 2008-05-24 ; ; Uses a 16 bit phase accumulator and ; pulse width modulated sine wave ; implemented using a PIC12C508A microcontroller ; with a 4MHz external crystal oscillator. ; ; PIC 12C508 ; ; VDD (1) (8) VSS ; OSC1 (2) (7) GP0 ; OSC2 (3) (6) GP1 ; GP3 (4) (5) GP2/T0CLKI ; ; The tone set is for Australian repeaters ; and may be selected using the GP0 and GP1 ; inputs. GP2 is the output and should be ; filtered with an RC filter with cut off ; frequency around 200Hz. ; The GP3 input is used as a tone enable. ; ; GP0 GP1 GP3 ; 0 0 0 91.5 Hz ; 1 0 0 123.0 Hz ; 0 1 0 141.3 Hz ; 1 1 0 100.0 Hz ; X X 1 Disabled ; ; GP2 = Output ; ; F = 1 / 2 pi R C ; F = 160Hz ; R = 10K ; C = 0.1 uF ; ; TRIS = 00111011 = 03Bh GP2 = output ; LIST P=12C508A,R=DEC #INCLUDE "p12C508A.inc" ; ; Configuration: ; ; Bit 11 - 5 unimplemented ; bit 4 MCLRE = 0 MCLR* tied to VDD ; bit 3 CP = 1 Code protection off ; bit 2 WDTE = 0 Watch Dog Timer disabled ; bit 1 FOSC1 = 0 XT Oscillator ; bit 0 FOSC0 = 1 __CONFIG _MCLRE_OFF & _CP_OFF & _WDT_OFF & _XT_OSC ; accum1 equ H'08' ; tone accumulator high byte accum2 equ H'09' ; tone accumulator low byte temp equ H'0C' ; temporary sine table data holder toneind equ H'0D' ; index to tone constants locount equ H'0E' ; Pulse width low hicount equ H'0F' ; Pulse width high ; ; ORG 0x000 start goto init ; ORG 0x004 init movlw b'00111011' ; GP2 = Output TRIS GPIO ; ; Options: ; ; bit 7 GPWU* = 1 Disabled ; bit 6 GPPU* = 0 Enable week pull ups GP0, GP1,GP3 ; bit 5 T0CS = 0 Transition on internal instruction clock ; bit 4 T0SE = X T0CLKI Edge ; bit 3 PSA = 1 Prescaler assigned to WDT ; bit 2 PS2 = 1 WDT Rate 1:128 ; bit 1 PS1 = 1 ; bit 0 PS0 = 1 ; movlw b'10001111' option bcf GPIO,2 ; Clear ouput bit clrf accum1 ; clear the the phase accumulator clrf accum2 ; ; 43 instruction cycles up to "loloop" ; PWM loop is 199 instruction cycles ; gives 242usec for the loop = 4132.231 Hz ; ; 4132.231 / 91.5 = 45.161 ; 65536 / 45.161 = 1451 = 05ABh ; ; 4132.231 / 123.0 = 33.595 ; 65536 / 33.595 = 1950 = 079Eh ; ; 4132.231 / 141.3 = 29.244 ; 65536 / 29.244 = 2241 = 08C1h ; ; 4132.231 / 100.0 = 41.322 ; 65536 / 41.322 = 1586 = 0632h ; tonelp btfsc GPIO,3 ; test for transmit enable goto tonelp ; ; Tone active determine tone value ; movf GPIO,W ; get tone select andlw b'00000011' ; mask out bits 0 and 1 movwf toneind ; save bcf STATUS,C ; clear carry rlf toneind,F ; shift left for table index movf toneind,W ; load into W call tonetbl ; look up low tone value addwf accum2,F ; add to phase accumulator btfsc STATUS,C ; test for carry incf accum1,F ; add in carry incf toneind,W ; tone index to W call tonetbl ; look up high tone value addwf accum1,F ; add high phase accumulator bcf STATUS,C ; clear carry rrf accum1,W ; divide by two movwf temp ; save bcf STATUS,C ; clear carry rrf temp,W ; divide by 4 call sinetbl ; look up sine value ; ; ; 0 => 1 high 64 low ; 1 => 2 high 63 low ; 62 => 63 high 2 low ; 63 => 64 high 1 low ; movwf hicount ; save it as the high pulse width bcf STATUS,C ; clear carry rrf hicount,F ; divide by two bcf STATUS,C ; clear carry rrf hicount,F ; divide by four incf hicount,F ; movlw H'41' ; set the low count to 61 movwf locount movf hicount,W ; fetch the high count subwf locount,F ; 61 - hicount -> hicount ; ; Pulse width loop ; ; (65 * 3us) + 4us = 199us ; loloop decfsz locount,F goto loloop bsf GPIO,2 ; Set ouput bit hiloop decfsz hicount,F goto hiloop bcf GPIO,2 ; Clear ouput bit ; goto tonelp ; ; Tone constant values ; tonetbl addwf PCL,F ;compute the jump value ; ; 91.5 Hz tone ; retlw h'ab' ; low byte retlw h'05' ; high byte ; ; 123.0 Hz tone ; retlw h'9e' ; low byte retlw h'07' ; high byte ; ; 141.3 Hz tone ; retlw h'c1' ; low byte retlw h'08' ; high byte ; ; 100.0 Hz tone ; retlw h'32' ; low byte retlw h'06' ; high byte ; ; sinetbl: ; A table of sine values - 64 bytes in length ; generated table with sine11.bas Qbasic program ; sinetbl addwf PCL,F ;compute the jump value retlw 128 ; 0 0 retlw 140 ; 1 9.801706E-02 retlw 152 ; 2 .1950902 retlw 165 ; 3 .2902845 retlw 176 ; 4 .3826831 retlw 188 ; 5 .4713964 retlw 198 ; 6 .5555698 retlw 208 ; 7 .6343929 retlw 218 ; 8 .7071064 retlw 226 ; 9 .77301 retlw 234 ; 10 .8314692 retlw 240 ; 11 .8819209 retlw 245 ; 12 .9238791 retlw 250 ; 13 .9569401 retlw 253 ; 14 .9807851 retlw 254 ; 15 .9951846 retlw 255 ; 16 1 retlw 254 ; 17 .9951848 retlw 253 ; 18 .9807855 retlw 250 ; 19 .9569408 retlw 245 ; 20 .9238802 retlw 240 ; 21 .8819221 retlw 234 ; 22 .8314706 retlw 226 ; 23 .7730116 retlw 218 ; 24 .7071081 retlw 208 ; 25 .6343948 retlw 198 ; 26 .555572 retlw 188 ; 27 .4713986 retlw 176 ; 28 .3826855 retlw 165 ; 29 .2902869 retlw 152 ; 30 .1950926 retlw 140 ; 31 9.801959E-02 retlw 128 ; 32 2.535182E-06 retlw 115 ; 33 -9.801454E-02 retlw 103 ; 34 -.1950877 retlw 90 ; 35 -.290282 retlw 79 ; 36 -.3826808 retlw 67 ; 37 -.4713942 retlw 57 ; 38 -.5555677 retlw 47 ; 39 -.6343909 retlw 37 ; 40 -.7071046 retlw 29 ; 41 -.7730084 retlw 21 ; 42 -.8314677 retlw 15 ; 43 -.8819197 retlw 10 ; 44 -.9238782 retlw 5 ; 45 -.9569393 retlw 2 ; 46 -.9807846 retlw 1 ; 47 -.9951844 retlw 0 ; 48 -1 retlw 1 ; 49 -.9951851 retlw 2 ; 50 -.980786 retlw 5 ; 51 -.9569415 retlw 10 ; 52 -.9238811 retlw 15 ; 53 -.8819233 retlw 21 ; 54 -.831472 retlw 29 ; 55 -.7730132 retlw 37 ; 56 -.7071099 retlw 47 ; 57 -.6343968 retlw 57 ; 58 -.5555741 retlw 67 ; 59 -.4714009 retlw 79 ; 60 -.3826878 retlw 90 ; 61 -.2902893 retlw 103 ; 62 -.1950951 retlw 115 ; 63 -9.802211E-02 ; END