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.

Junebug help??

Status
Not open for further replies.
The 10k is to the base you get the full 5 volts to the speaker no current limit on the speaker but the 8 ohms of the speaker
 
he meant like this
Code:
 For i = 1 To 20     //play 20 tones
            Tone=Rand(5)    //each tone is random frequency
            DelayMS(1000)    //and for 1.00 seconds
 
Last edited:
were missing something??

I need to get some wood project done for cub scouts today
will get back at it tonight for sure
oups need to clear table for my dear
 
spead up and more tones

changes made in red
tried several combos
this sounds ok but would like more volume
I copied n pasted 2x the AS WORD numbers


{
*****************************************************************************
* Name : sound freq gen.BAS *
* Author : *
* Notice : Copyright (c) 2009 [select VIEW...EDITOR OPTIONS] *
* : All Rights Reserved *
* Date : 4/15/2009 *
* Version : 1.0 *
* Notes : *
* : *
*****************************************************************************
}
Device = 18F1320
Clock = 8 // 8MHz clock
Config OSC = INTIO2, WDT = OFF, LVP = OFF

Dim NOT_RBPU As INTCON2.7
Dim TMR1IE As PIE1.0
Dim TMR1IF As PIR1.0
Dim TMR1 As TMR1L.AsWord
Dim Speaker As PORTB.3
Dim SpeakerTris As TRISB.3

//global variables
Dim Seed As LongWord, Tone As Byte
Dim i As Byte

//half period delays = clock speed divided by 2*frequency
Const Tones(18) As Word = (2000000/12000,2000000/10000,2000000/8000,2000000/6000,2000000/4000,1000,
2000000/12000,2000000/10000,2000000/8000,2000000/6000,2000000/4000,1000,2000000/12000,2000000/10000,2000000/8000,2000000/6000,2000000/4000,1000)

//interrupt routine
Interrupt MyInt()
T1CON.0=0 //stop timer
TMR1=-Tones(Tone) //reset period
T1CON.0=1 //restart timer
If Tone=5 Then //if silence
Speaker=0 //speaker off
Else //otherwise
Toggle(Speaker) //make sound
EndIf
TMR1IF=0 //clear interrupt flag
End Interrupt

Function Rand(Range As Byte) As Byte
Dim i As Byte, feed As Bit, temp As Word
For i = 0 To 7 //generate 8 bits
Feed = Seed.30 Xor Seed.27 //make new bit
Seed=Seed*2+Feed //shift seed left and add new bit
Next
Temp=(Seed And 255) * Range //change Rand from 0 to 255
Rand = Temp/256 //to 0 to (Range-1)
End Function

//main code starts here

OSCCON = $72 //select 8MHz internal clock
NOT_RBPU=0 //WPUs on port B
ADCON1=$70 //all digital
T1CON = %10000001 //pre=1
Tone=5 //no sound please
TMR1IE=1 //enable timer 1 interrupt
Enable(MyInt) //set interrupt going
SpeakerTris=0 //Setup Port
Seed=$12345678 //seed random number
While(TRUE) //repeat forever
If PORTB.0=0 Then //if button 1 pressed add PIR here
For i = 1 To 15 //play 20 tones
Tone=Rand(5) //each tone is random frequency
DelayMS(100) //and for 1.00 seconds
Next //end for loop
Else //otherwise
Tone=5 //silence
i=Rand(255) //make rand more random
EndIf //end if condition
Wend //end of while loop
 
Where is advance??

and # tags?
using the swordfish prg/F10 then
press sw1 and tones are generated.
are the advance and # tags in pickit2 or mplab as I am not using either one.
should I be??
 
where is this feature?

been trying to figure out mplab but the swordfish prg does the comipling/progrsamming.
maybe not right?
will investigate the line numbering
 
thank goodness for forget MPLAB

I hit F10 then the chip is programed = correct?
now If I install a pic in a breadboard w/ the 5v power supply I can connect Junebug to the chip and program it? using the ICD plug #6=correct??
just would like more volum and maybe have the prg run longer but not essential
this is much easier (not so many parts) as the circuit I was working with where I change the timing resistors on a 555 to change the different frequencies.
this PIC stuff has a taller learning curve for sure.
 
If you've set Swordfish up as described in the manual to use the PK2CMD.EXE command line programming software then pressing F10 should compile, program & run the program on the target PIC.
Yes it's a lot less parts on the outside. A PIC is thousands of times more complex than a 555 on the inside.
 
adding an amp to con5

contemplating adding an amp to con5
looking at an lm386
it was suggested just connect a 9v to the speaker instead of the 5v from con5
for a standalone battery powered project, 3 AA batteries or 4 and a regulator?
thought about even using a 9v battery but the amp hrs are less.
any suggestions on powering this device?
the PIR ill run on 4.5 - 20v
https://www.electro-tech-online.com/custompdfs/2009/04/DC-SS013_Ver10_EN.pdf
add the lm386?? and speaker.
 
This plays sound with a keypad figure you may want to play with it Mrdeb

Code:
Device = 18F1320
Clock = 8
Config OSC = INTIO2
Config MCLRE = OFF
Include "INTOSC8.bas"
Include "Utils.bas"
//Dim count As Byte
//Dim keypress As Byte 
//Dim holdkey As Byte
Dim key1 As Byte
Dim key2 As Byte
Dim key3 As Byte
Dim key4 As Byte
Dim key5 As Byte
Dim key6 As Byte
Dim key7 As Byte
Dim key8 As Byte
Dim key9 As Byte
Dim key10 As Byte
Dim key11 As Byte
Dim key12 As Byte
Dim out As PORTB.3
Dim col1 As PORTA.0
Dim col2 As PORTA.1
Dim col3 As PORTA.2
Dim roll1 As PORTA.3
Dim roll2 As PORTA.4
Dim roll3 As PORTA.6
Dim roll4 As PORTA.7
SetAllDigital
Input (roll1)
Input (roll2)
Input (roll3)
input (roll4)
Output (out)
Output (col1)                   
Output (col2)
Output (col3)
Low (out)

 While True
        High (col1) Low (col2) Low (col3)      // col 1
    If col1 = 1 And col2 =0 And col3 = 0 And roll1 = 1 Then
    key1 =1
    high (out)
       delayus (1400)
       low (out)
       delayus (700)
    EndIf
    High (col1) Low (col2) Low (col3)
    If col1 = 1 And col2 =0 And col3 = 0 And roll2 = 1 Then
    key2 =2
    high (out)
       delayus (1600)
       low (out)
       delayus (700)
    EndIf
    High (col1) Low (col2) Low (col3)
    If col1 = 1 And col2 =0 And col3 = 0 And roll3 = 1 Then
    key3 =3
    high (out)
       delayus (1800)
       low (out)
       delayus (700)
    EndIf
    High (col1) Low (col2) Low (col3)
    If col1 = 1 And col2 =0 And col3 = 0 And roll4 = 1 Then
    key4 =4
    high (out)
       delayus (2000)
       low (out)
       delayus (700)
    EndIf
        Low (col1) High (col2) Low (col3)         // col 2
    If col2 = 1 And col1 =0 And col3 = 0 And roll1 = 1 Then
    key5 =5
    high (out)
       delayus (1400)
       low (out)
       delayus (600)
    EndIf
    Low (col1) High (col2) Low (col3)
    If col2 = 1 And col1 =0 And col3 = 0 And roll2 = 1 Then
    key6 =6
    high (out)
       delayus (1600)
       low (out)
       delayus (600)
    EndIf
    Low (col1) High (col2) Low (col3)
    If col2 = 1 And col1 =0 And col3 = 0 And roll3 = 1 Then
    key7 =7
    high (out)
       delayus (1800)
       low (out)
       delayus (600)
    EndIf
    Low (col1) High (col2) Low (col3)
    If col2 = 1 And col1 = 0 And col3 = 0 And roll4 = 1 Then
    key8 =8
    high (out)
       delayus (2000)
       low (out)
       delayus (600)
    EndIf
       Low (col1) Low(col2) High (col3)         // col 3
    If col3 = 1 And col1 =0 And col1 = 0 And roll1 = 1 Then
    key9 =9
    high (out)
       delayus (1400)
       low (out)
       delayus (500)
    EndIf
    Low (col1) Low (col2) High (col3)
    If col3 = 1 And col2 =0 And col1 = 0 And roll2 = 1 Then
    key10 =10
    high (out)
       delayus (1600)
       low (out)
       delayus (500)
    EndIf
    Low (col1) Low (col2) High (col3)
    If col3 = 1 And col2 =0 And col1 = 0 And roll3 = 1 Then
    key11 =11
    high (out)
       delayus (1800)
       low (out)
       delayus (500)
    EndIf
    Low (col1) Low (col2) High (col3)
    If col3 = 1 And col2 =0 And col1 = 0 And roll4 = 1 Then
     key12 =12
     high (out)
       delayus (2000)
       low (out)
       delayus (500)
     EndIf
  
     
 Wend
 
I may need an amp??

The LM386 with 1 capacitor will give a 20db gain
Not that I want to blow the deer ears out but??
Question about voltage and a stand alone circuit
using the 18F13420
maybe a LM386
a PIR = 4.5-20V
perhaps 3 AA batteries = 4.5V
or should I shoot for 6v and perhaps a zenier but I don't want to run the batteries down to fast.
suggestions?? as this is my first
need to know how much the RB3 port outputs to figure wattage output w/wo an lm386
the little speaker I bought from radio shack is perfect size = small
ts only 29mm (1 1/8 diameter)
.10W rated, max =.20W
 
MRdeb did you hook it up to RB 3 with the transistor like I showed you. if you did it's louder then you think the sound is such that you don't hear it but some people can hear it better or you hooked it up wrong. Like i said my wife could hear it about 50 feet away 3 rooms over and she had the tv on loud wanted to no what i was doing to make such a noise. You'll need 6 volts.
 
SEE she is a deer!!

that"s what I want to annoy.
I accept paypal--lol
I connected a larger speaker and yes it is louder but not real loud
your wife must have super hearing!!
using the 29mm speaker my wife could hear it but in sa,me room
using the larger SPARKOMATIC speaker SK6922 she could hear it in other room as well as the dog.which doesn't mean much, that dog barks during the broom mop commercial, thinks someones at the door-lol
don't know what to do.
larger speaker or add an amp??
still the issue of power supply??
 
The changes you made should have worked but not as you intended. You changed 250 to 100 and so shortened each note to a tenth of a second - change it to 1000 for 1 second.

Maybe an explanation of what the code is doing will help.

The length of the sound is not defined by the table (Notes). This just contains the number of cycles to produce a half waveform. So, 2,000,000 (the clock speed) divided by 6000 will give us 333. The 333 is loaded into the timer so that an interrupt will be generated every 333 cycles. This interrupt toggles the port pin and so produces a signal of 3000Hz. The final entry in the table is the value used when no note is being played so the interrupt stays running.

The variable Note is used to tell the interrupt which note we want to play. It is used to choose one of the values out of the Notes table. Note=0 will choose the first (zeroth) value and play 6kHz through to Note=4 will choose the 5th value (we include zero in the count) and play 2kHz. When Note=5 is a special case and is used to tell the interrupt to be silent.

The number of notes played is set by the number in the for-next loop and was originally set to 10. The note played is chosen randomly by the Note=Rand(5) line which will return a random number between 0 and 4 and place it in Note.

Hope that makes some sense.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top