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.

Help me with coding for PIC12F675 in PIC Siren

Status
Not open for further replies.

me_guitarist

Full Member level 6
Joined
Oct 3, 2006
Messages
338
Helped
0
Reputation
0
Reaction score
0
Trophy points
16
Location
Malaysia
Activity points
0
Can someone convert this code to suite into PIC12F675?

;Project: Siren Sound
List P = 16F84
#include <p16F84.inc>
__CONFIG 1Bh ;_CP_OFF & _PWRTE_ON & _WDT_OFF & _RC_OSC

ORG 0 ;This is the start of memory for the program.
Setup BSF 03,5 ;Go to Bank 1
CLRF 06 ;Make all port B output
BCF 03,5 ;Go to Bank 0 - the program memory area.
CLRF 06 ;Clear display
GOTO Siren

Siren MOVLW 80h ;Number of cycles for each tone
MOVWF 0Eh
MOVWF 10h
MOVLW 50h ;Number of steps
MOVWF 0Fh ;File 0F holds the number of steps
MOVLW 50h ;Determines frequency
MOVWF 0Ch ;File 0C determines the frequency

Repaet MOVF 0C,0 ;File 0C is moved to W
MOVWF 0D ;W is moved to file 0D for decrementing

On BSF 06,7 ;Length of HIGH time to Piezo
DECFSZ 0D,1
GOTO On
MOVWF 0Dh ;W is moved to file 0D again

Off BCF 06,7 ;Length of LOW time to Piezo
DECFSZ 0D,1
GOTO Off
DECFSZ 10h,1 ;Number of cycles for each tone
GOTO Repeat
DECF 0C,1 ;HIGH and LOW is shortened -tone rises
INCF 0E,1 ;Increase the number of cycles
MOVF 0E,0 ;File 0E to W
MOVWF 10h ;W to file 10h
DECFSZ 0F,1 ;Number of steps
GOTO Repeat
GOTO Siren

END
 

pic siren generator

Anyone can help to post some PIC siren schematic?
Hopefully is 12F675 as I have some of it.
 

sirene com pic

Here you go.
Note that the oscillator is still RC, as in the original design, so you can easily adjust the tone.
GPIO0 is the output. If you don't like that, change it.
Code:
;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
 

pic code siren

Thanks VVV.

Can this program work on this circuit?
 

12f675 tone

Anyone can help to write a code for this circuit?
 

pic siren code

You need the oscillator components. Use figure 9-3 in the datasheet. Choose the values to suit your desired tones.
Since you have nothing connected to MCLR, then change the configuration to : __CONFIG _CP_OFF & _PWRTE_ON & _WDT_OFF & _EXTRC_OSC_NOCLKOUT & _MCLRE_ON & _BODEN_ON

That way the MCLR will get its pullup enabled, so you can leave it floating.
 

+pic +siren

Can I add a 10K across MCLR & VDD?

The RC didn't work. Sound very slow.

Added after 4 hours 23 minutes:

Can someone convert this code for 12F675?

Expt7a.asm
;Project: Hee Haw Sound
List P = 16F84
#include <p16F84.inc>
__CONFIG 1Bh ;_CP_OFF & _PWRTE_ON & _WDT_OFF & _RC_OSC

ORG 0 ;This is the start of memory for the program.





SetUp BSF 03,5 ;Go to Bank 1
CLRF 06 ;Make all port B output
BCF 03,5 ;Go to Bank 0 - the program memory area.
CLRF 06 ;Clear display
GOTO Hee1

Hee1 MOVLW 0FFh ;Number of loops
MOVWF 14h ;The loop file
Hee2 MOVLW 0C0h ;Duration of HIGH
BSF 06,7 ;Turn on piezo
Hee3 NOP
DECFSZ 15h,1 ;Create the HIGH time
GOTO Hee3
MOVLW 0C0h ;Duration of the LOW
MOVWF 15h ;The LOW file
BCF 06,7 ;Turn off piezo
Hee4 NOP
DECFSZ 15h,1 ;Create the LOW time
GOTO Hee4
DECFSZ 14h,1 ;Decrement the loop file
GOTO Hee2 ;Do more cycles

MOVLW 0C0h ;Number of loops
MOVWF 14h ;The loop file
Haw1 MOVLW 0FFh
MOVWF 15h
BSF 06,7 ;Turn on piezo
Haw3 NOP
DECFSZ 15h,1 ;Create the LOW time
GOTO Haw3
DECFSZ 14h,1 ;Decrement the loop file
GOTO Haw1 ;Do more cycles
GOTO Hee1

END
 

siren using pic

Yes, you can add a 10k from MCLR to Vdd.
What do you mean the RC didn't work and what do you mean the sound is too slow? You need to adjust the RC to get the sound pitch you want. Start by using the same RC components as in the original schematic with the 16F84.
 

12f675 schema

Hi VVV,

if I use the RC, the sound are very slow, even can't hear it. If I removed the capacitor the sound is ok.

The problem is the sound going from low to high, how to make it from low to high & high to low?
 

10f200

Hi guys,

I can't get the required freq can someone pls help?
500/1200Hz freq needed.

Added after 4 hours 52 minutes:

my circuit.
 

list p=10f200

What are the values of Rext and Cext and which code are you using?
 

siren pic 10f200

I'm using Rext=10k, Cext=22pf & yr 12f675 code.
 

sirene pic

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.
 

__config 10f200 mclr

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.

Should I try internal OSC?
I had tried many Rext & Cext the tone just going up & doesn't falling.
You r right, the tone are too high & working too long.
 

12f675 rext cext

I changed the config to internal OSC it work but same result.
 

siren circuit pic

Hi VVV,

how do I change repeat rate & freq?

Thanks
 

russian ts a siren

To change the frequency, change N_freq; to change the repeat rate, change N_cycles. N_steps will have a similar effect.
 

#include p12f675.inc __config _extrc_osc_noclkout

VVV said:
To change the frequency, change N_freq; to change the repeat rate, change N_cycles. N_steps will have a similar effect.

Hi VVV,

Thanks for yr reply & explanation.
However, It doesn't content a value like .xxx so how do I adjust the N_freq & N_cycle?

Can this be run with external 20Mhz crystal? How ?:cry:
 

siren sound code

The code I modified for you has equates at the top. All you have to do is change those lines. For instance change:
N_Freq EQU 64H

To use an external 20MHz crystal, change the oscillator option to _HF_OSC in the config word.
But why would you do that, since the internal oscillator is stable and accurate enough for this application? And it's absolutely free, as there are no components to add.
Plus, a 20MHz clock will make the sound pitch too high.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top