The 20ma RB3 can source is not enough to drive a speaker, you need to add the simple resistor and transistor driver as shown by be80be.
What you're going to find out is with programming there are almost unlimited ways of doing something. It's confusing at first but stick with it and you'll get the hang of it.
Deer and other critters are attracted to diodes and RC circuits!!
you will have deer from miles around comming to munch on your garden w/ diodes and RC circuits --LOL
oh I come up with a new name for this device = CRITTER RIDDER
You may be correct if the driving transistor is working in linear mode and handling a sine wave. but an unbiased transistor driving a square wave into a speaker at its collector, I feel, definitely produces back emf and should be protected. I saw many such schematics where such protection is provided. Shortly, i shall be able to provide links to confirm my thought.
The subject of "back-EMF" from speaker drivers is one that has surfaced from time to time across many decades of audio engineering, and it always seems to get much discussion, much disagreement, and not a lot of conclusions reached. Atmasphere brought this up in the related thread of "why amps sound different", and it inspired me to do a couple of experiments.
its not going to hurt his little npn because it never going to send back more then his little npn can handle.Now if it was a 12volt motor then for sure put a diode on it.
1.It lowered the output of the speaker with it and the sound wasn't right. Diode in there
2.With out the sound was good it never hurt the npn. No diode on it.
you posted be80be.
but using something less elaborate than a RNG.
going to connect the 10k/npn to breadboard etc then run your code
have to come up with a way to change the DUTY variable you put in.
any suggestions??
only need to go from 2khz to 6khz randomally so a RNG prg that uses 5 numbers or maybe a few more.
THEN I need to trigger the pic with a PIR sensor.
What PIR are you using. I been playing with it but I can make better sound not using the PWM and using this
Code:
Device = 18F1320
Clock = 8 // tells the compiler the FOSC speed
Config OSC = INTIO2, WDT = OFF, LVP = OFF
Include "Utils.bas"
Dim out As PORTB.3
OSCCON = %01111111
SetAllDigital
Low (PORTB.3)
While true
High (out)
DelayUS (1400) // justs change this to change sound
Low (out)
DelayUS (700) // and this to
Wend
then set a timer and run the code with more delay
works better then the PWM
found on Ebay but SURE Electronics sells same.
Why cheaper on Ebay??
They have a spec sheet on their website on controlling w/ PIC
what frequency does this code produce?? remember 2-6 khz back n forth--want to drive them critters away.Be nice to have it sound different each time it runs.
Will have to look and see how to set up a timer.
You can change it how ever you want that just shows you how easy it is to get sound. thats about 11khz if my math is right. There are PIR that work like a switch easy to use with a pic almost a no brainer. That pir is easy to use. Not very good but easy to set up the range is to short.
is this several different timers or all as one.
not sure of what I need
1 = when PIR detects motion it sets the sound prg to run
2 = sound program to change frequencies from 2000 - 6000 hz back and forth
3 = after say 5 - 10 seconds the pic shuts off waiting for another occurrence.
be80be has posted several sound codes=THANKS
now I need to figure out how to increment and decrement the sound code value
I was thinking just a loop that adds say 100 to one variable then substracts 100 from second variable
TimerA()=0
A=700, B=1400 //A and B determine sound frequency see be80be post above
A + 100, B - 100
until A >= 1400
A= 700, B= 1400
if TimerA()=100 then wend
I have a hunch this is close (I remember programming the VIC 20, C64 and the C128)
yes I is an old fart
I had all three and a lot more What's hard is swordfish is not the same as the basic you used then so I have to do a lot of reading
and I just started back coding haven't done any in over 25 years till about year and a half ago i used a stamp it's easy to code but cost to much. been picking about 8 months still learning lol
I didn't say I can't The point was It's been a long time and just started back. Got to do a
lot of reading to get up to speed. Swordfish has a module for the timer. You can set like
3 events 1 if pir gos off then do low sound then high sound it's here. Swordfish Wiki | SwordfishUser / Timer0 browse
looks like greek but will try and understand it.
found a website that describes how to creat a sine wave using a PIC My PIC Projects
almost at the bottom
?????????