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.

PIC Siren Generator

Status
Not open for further replies.

meguitarist

New Member
Good day everyone.

I'm a beginner in electronics & PICs even new to this Forum.
I've compiled this coding & wondering someone can point me how can I calculate the required frequency & timing for this project using internal 4MHz oscillator

I need the sound to be raise from 500Hz to 1200Hz & falling again to 500Hz repeat forever.

change the constant value it changed the tone & timing too. How I know what is the frequency that I'm playing & the timing that repeated?

;Project: Siren Sound
List P = 12F675
#include <p12F675.inc>

__CONFIG _CP_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT & _MCLRE_ON & _BODEN_ON

#define OUT GPIO,0 ;port pin defined as the actual output

errorlevel -302

;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 .5 ; number of cycles
N_steps EQU .25 ; number of steps
N_freq EQU .170 ; 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.

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 ;Go to 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

Goto Repeat
GOTO Siren

END
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top