;Project: Siren Sound
List P = 12F675
#include <p12F675.inc>
; __CONFIG 1Bh ;_CP_OFF & _PWRTE_ON & _WDT_OFF & _RC_OSC
__CONFIG _CP_OFF & _PWRTE_ON & _WDT_OFF & _EXTRC_OSC_NOCLKOUT & _MCLRE_OFF & _BODEN_ON
#define OUT GPIO,0 ;port pin defined as the actual output
;VARIABLES
Cycles EQU 20H ;holds # of cycles
Steps EQU 21H ;holds # of steps
Freq EQU 22H ;holds frequency variable
Counter EQU 23H ;variable used as counter
Counter1 EQU 24H ;variable used as counter
;CONSTANTS
N_cycles EQU 80H ;number of cycles
N_steps EQU 50H ;# of steps
N_freq EQU 50H ;constant that determines frequency
ORG 0 ;This is the start of memory for the program.
Setup: CLRF GPIO ;all outputs are zeroed
MOVLW 07H ;GPIO2:0 are digital IO
MOVWF CMCON ;
BSF STATUS,RP0 ;Go to Bank 1
CLRF ANSEL ;all digital IO
CLRF TRISIO ;Make all port output
BCF STATUS,RP0 ;Go to Bank 0 - the program memory area.
; CLRF 06 ;Clear display ;not needed
; GOTO Siren ;not needed
Siren: MOVLW N_cycles ;Number of cycles for each tone
MOVWF Cycles ;
MOVWF Counter1 ;
MOVLW N_steps ;Number of steps
MOVWF Steps ;File 0F holds the number of steps
MOVLW N_freq ;Determines frequency
MOVWF Freq ;File 0C determines the frequency
Repeat: MOVF Freq,W ;File 0C is moved to W
MOVWF Counter ;W is moved to file 0D for decrementing
On: BSF OUT ;Length of HIGH time to Piezo
DECFSZ Counter,F
GOTO On
MOVWF Counter ;W is moved to file 0D again
Off: BCF OUT ;Length of LOW time to Piezo
DECFSZ Counter,F ;
GOTO Off
DECFSZ Counter1,F ;Number of cycles for each tone
GOTO Repeat
DECF Freq,F ;HIGH and LOW is shortened -tone rises
INCF Cycles,F ;Increase the number of cycles
MOVF Cycles,W ;File 0E to W
MOVWF Counter1 ;W to file 10h
DECFSZ Steps,F ;dec Number of steps
GOTO Repeat ;
GOTO Siren
END
VVV said:The code that I posted was simply your code with sligh modifications for the 11F675.
I think the problem may be that the frequency is very high and maybe the speaker just runs on a subharmonic. I looked at the code again it it seems that a 4MHz clock should be OK.
Try varying the resistor and cap, to see what happens. Maybe your oscillator runs at much more than 4MHz. That is the only suggestion I have. Since you are driving the speaker with a 5Vpp signal the only way your sound is too weak is if the sound frequency is too high and the speker cannot reproduce it.
VVV said:To change the frequency, change N_freq; to change the repeat rate, change N_cycles. N_steps will have a similar effect.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?