Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

16f628

Status
Not open for further replies.
And software makes it just as trivial, and probably more accurate - it really depends what he's wanting to do. I seem to recall that 1750Hz is the toneburst frequency used to open up amateur radio repeaters?.
 
Yes, as Nigel said, i need it to open a repeater. but i can not program a tone, never did it before so if some one can give me a tip here so i can try it.
 
Here's an untested example. Hope it helps.

Mike, K8LH

Code:
        list p=16F628A, b=8, c= 102, n=71, t=on, st=off, f=inhx32
;******************************************************************
;*                                                                *
;*  Filename: Burst Test.asm                                      *
;*    Author: Mike McLaren, K8LH  (k8lh_at_arrl.net)              *
;*      Date: 27-Oct-07  (last revision 27-Oct-07)                *
;*                                                                *
;*                                                                *
;*                                                                *
;*     MPLab: 7.40    (tabs=8)                                    *
;*     MPAsm: 5.03                                                *
;*                                                                *
;******************************************************************

        #include        <p16f628A.inc>
        errorlevel      -302

      __config  _PWRTE_ON&_LVP_OFF&_WDT_OFF&_INTRC_OSC_NOCLKOUT&_MCLRE_OFF
;
TMRH    equ     0x20            ;

;******************************************************************
;*  Reset Vector                                                  *
;******************************************************************

        org     0x0000

Reset
        clrf    STATUS          ;                                 |B0
        clrf    PORTA           ;                                 |B0
        clrf    PORTB           ;                                 |B0
        goto    Main            ;                                 |B0

;******************************************************************
;*  Subroutines                                                   *
;******************************************************************
;
;  setup PWM -> 572 usec period (1748.25 Hz) using a 4 MHz clock
;
InitPWM
        movlw   b'00000010'     ; '000000010'                     |B0
                                ; '-0000---' postscaler 1:1
                                ; '-----0--' timer 2 off
                                ; '------01' prescaler 1:4
        movwf   T2CON           ; produces 4 usec 'ticks'         |B0
        clrf    CCPR1L          ; 0% duty cycle (tone off)        |B0
        bsf     STATUS,RP0      ; select bank 1                   |B1
        movlw   d'143'-1        ; 143 4-usec 'ticks'              |B1
        movwf   PR2             ; 572 usec period (1748.25 Hz)    |B1
        bcf     TRISB,3         ; make RB3/CCP1 pin output        |B1
        bcf     STATUS,RP0      ; select bank 0                   |B0
        movlw   b'00001100'     ; '----1100'                      |B0
        movwf   CCP1CON         ; put CCP module in PWM mode      |B0
        bsf     T2CON,TMR2ON    ; turn on TMR2                    |B0
        return                  ;                                 |B0

;******************************************************************
;                                                                 *
;  DelayUS(16..262159), 4-MHz         Mike McLaren, K8LH, Jun'07  *
;                                                                 *
;  requires the use of constant operands known at assembly time!  *
;                                                                 *
;  12 words, 1 RAM variable, 14-bit core                          *
;                            ^^^^^^^^^^^                          *
;  the macro produces 4 instructions;                             *
;                                                                 *
DelayUS macro   delay           ; parameter range 16..262159
        movlw   high((delay-16)/4)+1
        movwf   TMRH
        movlw   low ((delay-16)/4)
        call    DelayLo-(delay%4)
        endm
;
Delay.16F
        nop                     ; entry point for delay%4 == 3    |B0
        nop                     ; entry point for delay%4 == 2    |B0
        nop                     ; entry point for delay%4 == 1    |B0
DelayLo addlw   -1              ; subtract 4 cycle loop time      |B0
        skpnc                   ; borrow?  yes, skip, else        |B0
        goto    DelayLo         ; do another loop                 |B0
        nop                     ;                                 |B0
DelayHi addlw   -1              ; subtract 4 cycle loop time      |B0
        decfsz  TMRH,F          ; done?  yes, skip, else          |B0
        goto    DelayLo         ; do another loop                 |B0
        goto    $+1             ; burn off 2 cycles               |B0
        return                  ;                                 |B0

;******************************************************************
;*  Main program                                                  *
;******************************************************************

Main    movlw   h'07'           ;                                 |B0
        movwf   CMCON           ; turn comparator off             |B0
        bsf     STATUS,RP0      ; bank 1                          |B1
        clrf    TRISA           ; PORTA all outputs               |B1
        clrf    TRISB           ; PORTB all outputs               |B1
        bcf     STATUS,RP0      ; bank 0                          |B0
;
;  initialize PWM module for 1750 Hz Period
;
        call    InitPWM         ;                                 |B0
;
;  test 1750 Hz tone
;
Test    movlw   d'71'           ; approx 50% duty cycle           |B0
        movwf   CCPR1L          ; turn tone on                    |B0
        DelayUS(250000)         ; 1/4 second delay                |B0
        clrf    CCPR1L          ; turn off tone (0% duty cycle)   |B0
        DelayUS(250000)         ; 1/4 second delay                |B0
        goto    Test            ; loop forever                    |B0

;******************************************************************
        end
 
Last edited:
Hello again Mike,

No i really did not got it to work, i did try the code you posted but it is making a beebing tone, and i need a constant tone burst on 1750Hz or as close as possible.
 
Hi,
CCPR1L is used to determine the pulse width, if you don't want it to be beeping, just delete this line:
clrf CCPR1L

when CCPR1L is cleared, the duty cycle of the PWM is 0%, means constantly 0.
 
Take a look at this little thingy I wrote to aid programming the CCP1 and CCP2 PWM modules for a routine in Swordfish Basic. It shows all the possible PWM frequencies and resolution for a given Oscillator value and Prescaler Value.

**broken link removed**

The whole PWM module is here: http://www.sfcompiler.co.uk/wiki/pmwiki.php?n=SwordfishUser.PWM2

1748 Hz is possible using the CCP PWM module with 4MHz Osc, Timer2 Prescaler = 4, and PR2 = 142. Set for 50% Duty with 572/2 = 286. That's pretty close.
 
I have now modyfied the code to a constant toneburst but the frequens is a lot to low only about 450 Hz:confused:
 
Leif (OY2L),

Sorry to hear you're still having problems.

The values in the PWM program above look correct but I don't have a way to test it at the moment.

Can you try the short program below? It uses a plain vanilla delay routine to produce precise 50% duty cycle output on the RA0 pin at 1748.25 Hz.

Regards, Mike

Code:
        list p=16F628A, b=8, c= 102, n=71, t=on, st=off, f=inhx32
;******************************************************************
;*                                                                *
;*  Filename: Tone Burst.asm                                      *
;*    Author: Mike McLaren, K8LH  (k8lh_at_arrl.net)              *
;*      Date: 08-Jul-08  (last revision 08-Jul-08)                *
;*                                                                *
;*  1750 Hz Tone Burst Experiment                                 *
;*                                                                *
;*     MPLab: 8.01    (tabs=8)                                    *
;*     MPAsm: 5.15                                                *
;*                                                                *
;******************************************************************

        #include        <p16f628A.inc>
        errorlevel      -302
        radix   dec
      __config  _PWRTE_ON&_LVP_OFF&_WDT_OFF&_INTRC_OSC_NOCLKOUT&_MCLRE_OFF
;
TMRH    equ     0x20            ;

clock   equ     4               ; user clock frequency in MHz
usecs   equ     clock/4         ; cycles/microsecond multiplier
msecs   equ     usecs*1000      ; cycles/millisecond multiplier
;
DelayCy macro   pDelay          ; cycles (Tcy), minimum 16
        movlw   high((pDelay-16)/4)+1
        movwf   TMRH
        movlw   low ((pDelay-16)/4)
        call    DelayLo-(pDelay%4)
        endm

;******************************************************************
;*  Reset Vector                                                  *
;******************************************************************

        org     0x0000
Reset
        clrf    STATUS          ;                                 |B0
        clrf    PORTA           ;                                 |B0
        clrf    PORTB           ;                                 |B0
        movlw   h'07'           ;                                 |B0
        movwf   CMCON           ; turn comparator off             |B0
        bsf     STATUS,RP0      ; bank 1                          |B1
        clrf    TRISA           ; PORTA all outputs               |B1
        clrf    TRISB           ; PORTB all outputs               |B1
        bcf     STATUS,RP0      ; bank 0                          |B0

burst
        bsf     PORTA,0         ; continuous 1748.25 Hz on RA0
        DelayCy(286*usecs-1)    ;
        bcf     PORTA,0         ;
        DelayCy(286*usecs-3)    ;
        goto    burst           ;

;******************************************************************

Delay.16
        nop                     ; entry point for delay%4 == 3    |B0
        nop                     ; entry point for delay%4 == 2    |B0
        nop                     ; entry point for delay%4 == 1    |B0
DelayLo addlw   -1              ; subtract 4 cycle loop time      |B0
        skpnc                   ; borrow?  yes, skip, else        |B0
        goto    DelayLo         ; do another loop                 |B0
        nop                     ;                                 |B0
DelayHi addlw   -1              ; subtract 4 cycle loop time      |B0
        decfsz  TMRH,F          ; done?  yes, skip, else          |B0
        goto    DelayLo         ; do another loop                 |B0
        goto    $+1             ; burn off 2 cycles               |B0
        return                  ;

;******************************************************************
        end
 
Ok, I just found the error in that original PWM code.

The comments are correct but the actual value that I write to the T2CON register is wrong. So I was telling the CCP module to use a 1:16 prescaler setting instead of a 1:4 prescaler setting. This explains why you were getting a much lower frequency output.

I apologize.

Mike

Code:
        movlw   b'000000[COLOR=Red]10[/COLOR]'     ; '000000[COLOR=Red]10[/COLOR]'                     |B0
                                ; '-0000---' postscaler 1:1
                                ; '-----0--' timer 2 off
                                ; '------[COLOR=Black][COLOR=Blue]01[/COLOR]' [COLOR=Blue]prescaler 1:4
        [COLOR=Black]movwf   T2CON           ; produces 4 usec 'ticks'        |B0[/COLOR]
[/COLOR][/COLOR]

 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top