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.
final design schematic

have built most on a breadbosrd but it should all work.
haven't tested the RA3 port/dip switch routine but it should work hopfully.
any suggestions before etching a pc board
cross the fingers etc.
 

Attachments

  • Capture4-27-2009-7.40.51 AM.jpg
    Capture4-27-2009-7.40.51 AM.jpg
    166.8 KB · Views: 275
Well it kinda works??

The dip switches don't affect the DELAY()
I had the poert B0 set low but realized I had it backwards.
changed to high, still no different. I read 2.5v on pin 8, not 4.5?? Dip switches take the other ports LOW. ANY suggestions WHY??
Code:
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

Dim Amp As PORTB.1 // turns on amp power
dim AmpTris as TrisB.1//turns on amp pin 9
Dim Speed As Word
Dim dip1 As PORTA.0

Dim dip2 As PORTA.1

Dim dip3 As PORTA.2

Dim dip4 As PORTA.3

Dim dipRD As PORTB.0

//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

Speed = ((PORTB/2) And 7)*25+25
      PORTB.0=1 // goes high to read dips

OSCCON = $72 //select 8MHz internal clock
NOT_RBPU=0 //WPUs on port B
ADCON1=$7f //all digital
//main code starts here

OSCCON = $72            //select 8MHz internal clock
NOT_RBPU=0              //WPUs on port B
ADCON1=$70              //all digital
portB.0=1
T1CON = %10000001       //pre=1
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 PORTA.0=1 Then //dip1 pin 1
       Speed=25
    EndIf
    
    If PORTA.1=1 Then // dip 2 pin 2
       Speed=50 
    EndIf
    
    If PORTA.2=1 Then //dip3 pin 6
       Speed=75
    EndIf
    
    If PORTA.3=1 Then //dip4 pin 
       Speed=Rand(10)*15+15    //Speed = 25 to 250 random select speed
       
    EndIf
    PORTB.0=0// port goes LOW to conserve powerfinished reading dips
    
   
    
If PORTB.1=0 Then //if button 1 pressed add PIR=1 here
For i = 1 To 200 //play 20 tones
    Tone=Rand(5) //each tone is random frequency
DelayMS(Speed) //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
 

Attachments

  • Capture5-1-2009-5.36.00 PM.jpg
    Capture5-1-2009-5.36.00 PM.jpg
    183.4 KB · Views: 293
IS that the code your using. If so why are you configuring the chip two times.
Code:
OSCCON = $72            //select 8MHz internal clock
NOT_RBPU=0              //WPUs on port B
ADCON1=$70              //all digital
That doesn't work to well seeing you have done twice.
 
Its the copy paste ghost

after looking at your post and viewing what I have I see where the code is almost done twice.
will edit out one of them.
which one??
or does it matter??
Another problem I discovered was I failed to include the 2n2222 in the PIR circuit.
the PIR goes HIGH on trigger. I have it configured for the pushbutton on the Junebug.
I made a biggy mistake etching boards- the printout came out smaller by a little bit and the dip sockets don't fit.
Need to re-etch and re-drill new boards.
Going with SMT after I get these 5 units built and working.
WHY only 2.5v on high ?? if thats what I told the PIC to do (portb.0)
 
Revised PIR input

added a 2n2222 to the PIR input (PIR goes HIGH(3v) on trigger so taking RB2 LOW to wake up PIC.
the 5kbase and 20k collector should work??
now hopfully the fact that the PIR wasn't triggering the PIC correctly, maybe with the 2n2222 it will??
coulds be why the dip switchwes don't work??
OH on the PC board printout, only thing I can find is I printed in landscape instead of portrait. I printed out in portrait and it looks good.
 
driving an 8 ohm speaker?

do I or should I add the cap to the output and base resistor value?
using the LM386 it called for a cap on the output??
 

Attachments

  • Capture5-1-2009-9.16.14 PM.jpg
    Capture5-1-2009-9.16.14 PM.jpg
    147.6 KB · Views: 283
You can't see what your talking about you cut off you circuit. And the way you have the dip switch don't look like it read it right. Your making it high with RB0 and reading which is high it would work better like this
 

Attachments

  • maybe better.PNG
    maybe better.PNG
    7.5 KB · Views: 283
Almost the same??

end result the same???
what about the cap on the speaker and resistor from the PIC to the transistor base.
 

Attachments

  • Capture5-2-2009-8.49.37 AM.jpg
    Capture5-2-2009-8.49.37 AM.jpg
    108.4 KB · Views: 295
It's not the same your setup can act like a voltage divider. That's why your reading 2.5 volts
 

Attachments

  • div.PNG
    div.PNG
    4.6 KB · Views: 292
Last edited:
Still dosn't work??

The dang dip switch is acting like a voltage divider still??
getting only 2.4 volts on pin 8 when I have any one dip switch on.
I measured between ports pins 1,2,6,7 (no PIC inserted) and all switches off I show 44K ohms.
turn on a switch and get 0 between pin 8 and port but show 22k between ports
DANG it Im so confused.
getting late.
will configure something else??
need to simulate in TINA and move stuff around but this should work but it doesn't.
 

Attachments

  • Capture5-2-2009-8.56.34 PM.jpg
    Capture5-2-2009-8.56.34 PM.jpg
    105.4 KB · Views: 280
You need the switches connected to 5V or you need to set PortB.0 to output (TRISB.0=0) and make it high (PORTB.0=1).

Mike.
 
You need the switches connected to 5V or you need to set PortB.0 to output (TRISB.0=0) and make it high (PORTB.0=1).
I thought that was the ideal for using RB0 so he could turn it off when the pic went to sleep and power his switches high with it on wake up his code showed him setting it high I didn't catch it still being a input.
 
Right here what doing it
Code:
OSCCON = $72 //select 8MHz internal clock
NOT_RBPU=0 //WPUs on port B
ADCON1=$7f //all digital
//main code starts here

OSCCON = $72            //select 8MHz internal clock
NOT_RBPU=0              //WPUs on port B
ADCON1=$70              //all digital
[COLOR="Red"]trisB.0=0[/COLOR]
My bag He has the portb set right in his code I meant (TrisB.0=0) I told him about the rest where he was setting this chip up twice. I was writing some code for a 18f1320. And had portb on my mind.
 
Last edited:
He needs to remove the blue bits, change the green bit and add the red bits.

Code:
[COLOR="Blue"]OSCCON = $72 //select 8MHz internal clock
NOT_RBPU=0 //WPUs on port B
ADCON1=$7f //all digital[/COLOR]
//main code starts here

OSCCON = $72            //select 8MHz internal clock
NOT_RBPU=0              //WPUs on port B
ADCON1=$7[COLOR="Lime"]f[/COLOR]              //all digital
[COLOR="Red"]TRISB.0=0               //make output
PORTB.0=1               //and high[/COLOR]

Mike.
 
He needs to work on flow set up the chip test for Pir then make some sounds, Next time Pir gos off make some new sounds go to sleep till Pir gos off.I think that would make it more readable
 
This won't solve the 2.5v problem??

here is the code to date with any and hopfully all the changes suggested.
BUT I still willonly show 2.5 volts on pin 8 if any dip switch is on.
with all off it shows 5v well actually 4.5 as I am powering using 3 AAA batteries.
Code:
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

Dim Amp As PORTB.1 // turns on amp power
Dim AmpTris As TRISB.1//turns on amp pin 9
Dim Speed As Word
Dim dip1 As PORTA.0

Dim dip2 As PORTA.1

Dim dip3 As PORTA.2

Dim dip4 As PORTA.3

Dim dipRD As PORTB.0

//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

Speed = ((PORTB/2) And 7)*25+25
      PORTB.0=1 // goes high to read dips


//main code starts here

       OSCCON = $72            //select 8MHz internal clock
       NOT_RBPU=0              //WPUs on port B
       ADCON1=$7f              //all digital
       TRISB.0=0               //make output
       PORTB.0=1 //makes pin 8 high for dip switches
       T1CON = %10000001       //pre=1
       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 PORTA.0=1 Then //dip1 pin 1
       Speed=25
    EndIf
    
    If PORTA.1=1 Then // dip 2 pin 2
       Speed=50 
    EndIf
    
    If PORTA.2=1 Then //dip3 pin 6
       Speed=75
    EndIf
    
    If PORTA.3=1 Then //dip4 pin 
       Speed=Rand(10)*15+15    //Speed = 25 to 250 random select speed
       
    EndIf
    PORTB.0=0// port goes LOW to conserve powerfinished reading dips
    
   
    
If PORTB.1=0 Then //if button 1 pressed add PIR=1 here
For i = 1 To 200 //play 20 tones
    Tone=Rand(5) //each tone is random frequency
DelayMS(Speed) //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
 
Do I need to designate input ports as LOW

by adding PORTA.0=0
PORTA.1=0
and so on.
I cliped the resistor gong to PORTA.3 and with the dip switch on I still get 2.3 volts, not 4.5
If I have all the dip switches off then pin 8 PORTB.0 is 4.5 volts
I must have something wrong with setting up PORTS A.0-A.3??
they are inputs so do I need to DIM them in the beginning??
and TRIS is to set up a port for input??
 
There not one place where you set portA up as input and outputs but only for the amp and it's on portB try this and see if it works better
Code:
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

Dim Amp As PORTB.1 // turns on amp power
Dim AmpTris As TRISB.1//turns on amp pin 9
Dim Speed As Word
Dim dip1 As PORTA.0

Dim dip2 As PORTA.1

Dim dip3 As PORTA.2

Dim dip4 As PORTA.3

Dim dipRD As PORTB.0

//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

Speed = ((PORTB/2) And 7)*25+25
      PORTB.0=1 // goes high to read dips


//main code starts here

       OSCCON = $72            //select 8MHz internal clock
       NOT_RBPU=0              //WPUs on port B
       ADCON1=$7f              //all digital
       TRISB.0=0               //make output
       PORTB.0=1 //makes pin 8 high for dip switches
       T1CON = %10000001       //pre=1
       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
        trisa =%00001111          //[COLOR="Red"]sets your inputs on porta [/COLOR]
While(TRUE) //repeat forever

    If PORTA.0=1 Then //dip1 pin 1
       Speed=25
    EndIf
    
    If PORTA.1=1 Then // dip 2 pin 2
       Speed=50 
    EndIf
    
    If PORTA.2=1 Then //dip3 pin 6
       Speed=75
    EndIf
    
    If PORTA.3=1 Then //dip4 pin 
       Speed=Rand(10)*15+15    //Speed = 25 to 250 random select speed
       
    EndIf
    //PORTB.0=0// port goes LOW to conserve powerfinished reading dips
    //[COLOR="Red"]leave this off for now and see what happens  [/COLOR]
   
    
If PORTB.1=0 Then //if button 1 pressed add PIR=1 here
For i = 1 To 200 //play 20 tones
    Tone=Rand(5) //each tone is random frequency
DelayMS(Speed) //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
 
Last edited:
no change

I copied n pasted your post and renamed it.
I disconnected one of the resistors just to see it it still works the same.
same DELAYMS() in other words no change
I really want these dip switches but ??
I might breadboard again and leave out the resistors, have pin 8 (RA0 - RA3) connected to dip switch directly w/o resistors or feed the dip switch with 4.5 volts directly but use a transistor connected to RB.0
this way the resistors etc are connected directly to he power supply but not until RB.0 becomes HIGH
a long way around but ??
 
Status
Not open for further replies.

Latest threads

Back
Top