Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] Help me with pic police siren

Status
Not open for further replies.

sbgkp

Newbie level 2
Joined
Jul 16, 2017
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
35
Can someone convert this code to sute into PIC10F200 ?


WAILING SIREN


Code is based on a system cycle clock of 4 MHz. If used on a system with a higher clock frequency, the timing will need to be adjusted accordingly to produce the required output frequencies.

************************************************************************************

;starting at 480Hz generate repeated sequences of 20 cycles all at the same frequency, then increase the frequency in 120 small steps and generate more cycles. When all completed, repeat the process whilst reducing the frequency at each step. Estimated time to complete a full sequence is 5 seconds


Code ASM - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
;Initialisation of registers
WAIL    movlw    d'180'        ;Starting value for timing loop counter
          movwf    CYCLETIME       ;stores the value for reload each half cycle
          movlw    d'120'          ;number of frequency steps per burst
          movwf    REPEATS   
RE_RISE    movlw   d'20'        ;number of cycles of same frequency
          movwf    CYCLES        
          call    TONEBURST    ;generate a burst of tone at fixed frequency
         decf    CYCLETIME,f    ;increase the frequency for the next tone burst
         decfsz    REPEATS,f    ;one less frequency step to do
          goto    RE_RISE         ;continue, starting  another burst at the new frequency
                                       ;until all finished
 
 
;A full sequence of 20 cycles in each of 120 frequency steps has now been completed
;now repeat the entire sequence as asbove but in steps of reducing frequency.
 
 
;Initialisation of registers
FALL         movlw    d'120'          ;number of frequency steps per burst
               movwf    REPEATS   
RE_FALL    movlw   d'20'        ;number of cycles of same frequency
               movwf    CYCLES        
               incf       CYCLETIME,f    ;increase the frequency for the next tone burst
               decfsz    REPEATS,f    ;one less frequency step to do
               goto    RE_FALL         ;continue, starting another burst at the new frequency,
                                        ;until all finished        
 
 
;one full rise and fall sequence completed, so go back do it all  over again       
              goto    WAIL        ;back to the start
 
 
 
;TONEBURST subroutine
; generates a sequence of 20 cycles all at the same frequency    
 
 
TONEBURST
             bsf    TONEOUT               ;set output I/O bit
              call    DELAY            ;wait for the end of the output half cycle
             nop
             nop            ;waste some more time to balance the on and off times
             bcf    TONEOUT        ;outpot low half cycle
             call    DELAY        
              decfsz    CYCLES,f    ;1 less cycle out of 20
             goto    TONEBURST    ;generate some more cycles at the same frequency
             return            ; return to make adjustments
 
 
 
;DELAY SUBROUTINE
 
;generates a time delay appropriate to the half cycle period of the output waveform ;being generated
 
 
 
DELAY    movwf    CYCLETIME    ;initialisation value for the time delay
            movwf    DELAY_CTR    ;load it into the decrementing counter
DELAYLOOP
            nop
           nop            ;waste some time
            decfsz    DELAY_CTR,f    ;less time remains now
            goto    DELAYLOOP    ;continue looping until all done
            return            ;Time is up, so quit

 
Last edited by a moderator:

If you want to use a higher clock frequency, then why not read the data sheet (which contains the number of cycles that each instruction takes - in your case I'd suggest you look at the 'nop' and 'decfsz' instructions etc plus the call/return overhead) and work out how many you need.
By the look of the code, it relies on the 'DELAY' function for al of the timing.
A (perhaps) more exact way to do the timing is to use a timer and an interrupt, creating a state machine that does the tone generation and advance the state for each interrupt. That way you only need the correct timer set up and it will work.
Susan
 
  • Like
Reactions: sbgkp

    sbgkp

    Points: 2
    Helpful Answer Positive Rating
Thank you for reply sir,

I need to design a siren sound at 500/1200hz falling at 0.25s. This is a standard fire alarm siren sound but wondering how to do it on 12F675.
I have no idea where to start so guys pls help.
 

I am confused about several things:
- which processor are you targeting - you have mentioned 2 so far
- what is the actual sound requirement - again you have mentioned 2
- are you wanting to convert the code you have shown in your original post or are you wanting to start from scratch
Also:
- do you need to write in assembler or would you consider C
- did you realise that the PIC12675 will need a separate header adapter for programming and debugging support - the PIC10F200 can be programmed via ICSP
- do you have a development board or are you designing your own board
Susan
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top