Help Quick Need to make code smaller


Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 40 of 42
  1. #1
    Programmednew's Avatar
    Programmednew Guest

    Question Help Quick Need to make code smaller

    I need to srink this code from 1688 to 1024 or less for a 16F84.
    This to make a car horn honk when the circuit gets power. It's adjustable from one to ten honks. This is the first code I have ever written so if you find any thing else wrong please tell me.


    DEFINE OSC 4
    TRISA.2 = 0
    High PORTA.2
    Pause 50
    TRISB = %11111111
    TRISA.0 = 1
    TRISA.1 = 1
    TRISA.3 = 1
    TRISA.4 = 1
    SWITCH:
    Pause 250
    IF PORTA.4 = 1 Then End
    IF (PORTB.2 = 0) AND (PORTB.3 = 0) AND (PORTB.6 = 0) AND (PORTB.4 = 0) AND (PORTB.5 = 1) Then GoTo SW10
    IF (PORTB.2 = 0) AND (PORTB.3 = 0) AND (PORTB.6 = 0) AND (PORTB.4 = 1) AND (PORTB.5 = 1) Then GoTo SW1
    IF (PORTB.2 = 1) AND (PORTB.3 = 0) AND (PORTB.6 = 0) AND (PORTB.4 = 0) AND (PORTB.5 = 1) Then GoTo SW2
    IF (PORTB.2 = 1) AND (PORTB.3 = 0) AND (PORTB.6 = 0) AND (PORTB.4 = 1) AND (PORTB.5 = 1) Then GoTo SW3
    IF (PORTB.2 = 0) AND (PORTB.3 = 0) AND (PORTB.6 = 1) AND (PORTB.4 = 0) AND (PORTB.5 = 1) Then GoTo SW4
    IF (PORTB.2 = 0) AND (PORTB.3 = 0) AND (PORTB.6 = 1) AND (PORTB.4 = 1) AND (PORTB.5 = 1) Then GoTo SW5
    IF (PORTB.2 = 1) AND (PORTB.3 = 0) AND (PORTB.6 = 1) AND (PORTB.4 = 0) AND (PORTB.5 = 1) Then GoTo SW6
    IF (PORTB.2 = 1) AND (PORTB.3 = 0) AND (PORTB.6 = 1) AND (PORTB.4 = 1) AND (PORTB.5 = 1) Then GoTo SW7
    IF (PORTA.2 = 0) AND (PORTB.3 = 1) AND (PORTB.6 = 0) AND (PORTB.4 = 0) AND (PORTB.5 = 1) Then GoTo SW8
    IF (PORTA.2 = 0) AND (PORTB.3 = 1) AND (PORTB.6 = 0) AND (PORTB.4 = 1) AND (PORTB.5 = 1) Then GoTo SW9
    GoTo SWITCH
    SW1:
    PulsOut PORTA.2, 50000
    End
    SW2:
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    End
    SW3:
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    End
    SW4:
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    End
    SW5:
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    End
    SW6:
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    End
    SW7:
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    End
    SW8:
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    End
    SW9:
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    End
    SW10:
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    End

    Any help is appreciated.
    Thanks

  2. #2
    Join Date
    May 2004
    Location
    New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default Re: Help Quick Need to make code smaller

    Hi Programmednew,
    Well, just at a glance you might try nested IF...THEN's instead of using the "AND"s (try to get rid of all of the AND's if you can).

    The "PULSEOUT"s can be replaced with something like:

    PortB.0 = 1 ; Make PortB.0 'high'
    pause 1000 ; or whatever pause you need
    PortB.0 = 0 ; Make portb.0 'low'

    Try to get rid of all the PULSEOUT's too.

    Using the "HIGH" command automatically makes the pin an output, so these two commands could be changed:

    TRISA.2 = 0
    High PORTA.2

    To just this:
    HIGH PORTA.2

    Better yet, can all the "HIGHs and "LOW"s and just set your TRIS registers as needed then use:

    PortA.2 = 1

    Arch

  3. #3
    Join Date
    May 2004
    Location
    New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default Re: Help Quick Need to make code smaller

    Couldn't edit my last post for some reason - so here's another idea to try:

    Where you have some code like this:

    SW10:
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000
    Pause 500
    PulsOut PORTA.2, 50000

    You could try this:

    CounterA VAR BYTE

    FOR CounterA = 0 TO 9
    PulsOut PORTA.2, 50000
    Pause 500
    NEXT CounterA

    Or get rid of the PULSEOUT as mentioned above.
    Starting the FOR...NEXT loop at 0 instead of 1 saves a bit of space too.

    >>>>
    Also, you could set up the loop in a sub-routine, then just load a CounterStop value:

    CounterStop VAR BYTE

    ; Your code sets a loop amount here.
    CounterStop = 5 ; Or whatever amount of loops you want

    GoSUB HornLoops

    Horn_Loops:
    FOR CounterA = 1 TO CounterStop
    PulsOut PORTA.2, 50000
    Pause 500
    NEXT CounterA
    RETURN


    Arch
    Last edited by Archilochus; - 16th January 2005 at 19:20.

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    I don't think i can do better than the following... 197 words now !!

    Code:
    DEFINE OSC 4
    
    TRISB = %11111111
    TRISA=%11111011
    
    MaskFromPORTB   var byte
    AmountOfPulsout var byte
    LoopVar         var byte
    PORTA.2=1
    Pause 50
    
    SWITCH:
           Pause 250
           IF PORTA.4 = 1 Then End
           MaskFromPORTB=PORTB & %01111100 ' Get only PORTB<6:2> bits 
           SELECT CASE MaskFromPORTB
                  CASE %00100000
                       amountofpulsout=10
    
                  case %00110000
                       amountofpulsout=1
    
                  case %00100100
                       amountofpulsout=2
    
                  case %00110100
                       amountofpulsout=3
    
                  case %01100000
                       amountofpulsout=4
    
                  case %01110000
                       amountofpulsout=5
    
                  case %01100100
                       amountofpulsout=6
    
                  case %01110100
                       amountofpulsout=7
    
                  case %00101000
                       amountofpulsout=8
    
                  case %00111000
                       amountofpulsout=9
    
                  case else
                       amountofpulsout=0
           end select
    
           if amountofpulsout>0 then 
                for loopvar=0 to amountofpulsout
                   PulsOut PORTA.2, 50000
                   Pause 500
                next
                end
           endif
           GoTo SWITCH

    the only thing i'm not sure of was on your following lines
    Code:
    IF (PORTA.2 = 0) AND (PORTB.3 = 1) AND (PORTB.6 = 0) AND (PORTB.4 = 0) AND (PORTB.5 = 1) Then GoTo SW8
    IF (PORTA.2 = 0) AND (PORTB.3 = 1) AND (PORTB.6 = 0) AND (PORTB.4 = 1) AND (PORTB.5 = 1) Then GoTo SW9
    Since PORTA.2 is the output for your pulsout... i'd assume you was meaning PORTB.2

    let us know what happen on this.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    you can still save codespace using the following... but this imply to modify your circuit too. It will gives you pulses from 0-15 depending on the PORTB<3:0> binary representation

    Code:
    DEFINE OSC 4
    
    TRISB = %11111111
    TRISA=%11111011
    
    MaskFromPORTB   var byte
    AmountOfPulsout var byte
    LoopVar         var byte
    PORTA.2=1
    Pause 50
    
    SWITCH:
           Pause 250
           IF PORTA.4 = 1 Then End
           MaskFromPORTB=PORTB & %00001111 ' Get only PORTB<3:0> bits 
           amountofpulsout = maskfromPORTB
           if amountofpulsout>0 then 
                for loopvar=0 to amountofpulsout
                   PulsOut PORTA.2, 50000
                   Pause 500
                next
                end
           endif
           GoTo SWITCH
    about 118 words nows... can use PIC12c508 or else 12c or 12F for that. without any need of external crystal or oscillator.

    if you remove PULSOUT statement and you use those line
    Code:
    PORTA.2=0
    PAUSE 500
    PORTA.2=1
    the whole code will take about 87 words...
    Last edited by mister_e; - 16th January 2005 at 21:02.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    Join Date
    May 2004
    Location
    New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    Nice example code Steve!

    You can shave off a tiny bit more by changing:

    IF amountofpulsout > 0 THEN


    To:

    IF amountofpulsout THEN

    Since when you're just checking if the variable is any value more than 0, if it is more than 0, the IF...THEN will return true.

    Arch

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Talking

    yeah for sure, we can also remove the FOR TO NEXT loop and place a simple IF THEN at the end or do few assembly language lines too to save few more words. There's so many way to save codespace.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  8. #8
    Programmednew's Avatar
    Programmednew Guest


    Did you find this post helpful? Yes | No

    Default

    I changed the code to

    DEFINE OSC 4
    Input PORTA.2
    High PORTA.2
    Pause 50
    Input PORTB.2
    Input PORTB.3
    Input PORTB.4
    Input PORTB.5
    Input PORTB.6
    Input PORTA.4
    Horncount VAR BYTE
    CounterStop VAR BYTE
    SWITCH:
    Pause 250
    IF PORTA.4 = 1 Then End
    IF (PORTB.2 = 0) AND (PORTB.3 = 0) AND (PORTB.6 = 0) AND (PORTB.4 = 0) AND (PORTB.5 = 1) Then CounterStop = 9: GoTo Horn_Loops
    IF (PORTB.2 = 0) AND (PORTB.3 = 0) AND (PORTB.6 = 0) AND (PORTB.4 = 1) AND (PORTB.5 = 1) Then CounterStop = 0: GoTo Horn_Loops
    IF (PORTB.2 = 1) AND (PORTB.3 = 0) AND (PORTB.6 = 0) AND (PORTB.4 = 0) AND (PORTB.5 = 1) Then CounterStop = 1: GoTo Horn_Loops
    IF (PORTB.2 = 1) AND (PORTB.3 = 0) AND (PORTB.6 = 0) AND (PORTB.4 = 1) AND (PORTB.5 = 1) Then CounterStop = 2: GoTo Horn_Loops
    IF (PORTB.2 = 0) AND (PORTB.3 = 0) AND (PORTB.6 = 1) AND (PORTB.4 = 0) AND (PORTB.5 = 1) Then CounterStop = 3: GoTo Horn_Loops
    IF (PORTB.2 = 0) AND (PORTB.3 = 0) AND (PORTB.6 = 1) AND (PORTB.4 = 1) AND (PORTB.5 = 1) Then CounterStop = 4: GoTo Horn_Loops
    IF (PORTB.2 = 1) AND (PORTB.3 = 0) AND (PORTB.6 = 1) AND (PORTB.4 = 0) AND (PORTB.5 = 1) Then CounterStop = 5: GoTo Horn_Loops
    IF (PORTB.2 = 1) AND (PORTB.3 = 0) AND (PORTB.6 = 1) AND (PORTB.4 = 1) AND (PORTB.5 = 1) Then CounterStop = 6: GoTo Horn_Loops
    IF (PORTB.2 = 0) AND (PORTB.3 = 1) AND (PORTB.6 = 0) AND (PORTB.4 = 0) AND (PORTB.5 = 1) Then CounterStop = 7: GoTo Horn_Loops
    IF (PORTB.2 = 0) AND (PORTB.3 = 1) AND (PORTB.6 = 0) AND (PORTB.4 = 1) AND (PORTB.5 = 1) Then CounterStop = 8: GoTo Horn_Loops
    GoTo SWITCH
    Horn_Loops:
    For Horncount = 0 TO CounterStop
    PulsOut PORTA.2, 50000
    Pause 500
    Next Horncount
    End

    It did compile but I have another problem now. Its is with the circuit. I have attached a picture of the schematic. In it with with everything hooked up U2 overheats. Without the PIC in it it has a five volt output.
    Attached Files Attached Files

  9. #9
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    You revert PIC voltage PIN... VSS= Ground VDD=5Volt And now your PIC is probably burn!!!!

    + you can't connect two 7805 output together...

    1000uF at the output of the regulator is unusefull. Can be good to place them at the input (ignition switch). at the output i suggest 10uF(tantalum or 47uF electrolitic) + 0.1uF ceramic.

    I'll also suggest to tie to ground unused input to avoid electric interference from any external car noise(common CMOS handling... also avoid to burn PIC). Be sure of your TRIS define for the unused pins... must be set as input.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  10. #10
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    and the IF THEN statement will have to be modify.
    Code:
    IF (PORTB.2 = 0) AND (PORTB.3 = 0) AND (PORTB.6 = 0) AND (PORTB.4 = 0) AND (PORTB.5 = 1) Then CounterStop = 9: GoTo Horn_Loops
    to something like that
    Code:
    IF (PORTB.2 = 0) AND (PORTB.3 = 0) AND (PORTB.6 = 0) AND (PORTB.4 = 0) AND (PORTB.5 = 1) Then 
         CounterStop = 9
         GoTo Horn_Loops
    endif
    in case you don't modify, PBP will not execute the GOTO Horn_Loops statement.

    Input/output statements are great, but i'll prefer to use only TRIS and comment it on the right like
    Code:
    TRISA=%10101010  'PORTA definition
                     'Input on bits : 1,3,5,7
                     'output on bits : 0,2,4,6
    it's my own opinion. I can agree it can be a bit more readable when using Input/Output statement.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  11. #11
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Originally posted by mister_e
    You revert PIC voltage PIN... VSS= Ground VDD=5Volt And now your PIC is probably burn!!!!

    + you can't connect two 7805 output together...

    1000uF at the output of the regulator is unusefull. Can be good to place them at the input (ignition switch). at the output i suggest 10uF(tantalum or 47uF electrolitic) + 0.1uF ceramic.

    I'll also suggest to tie to ground unused input to avoid electric interference from any external car noise(common CMOS handling... also avoid to burn PIC). Be sure of your TRIS define for the unused pins... must be set as input.
    Programmednew

    please forgive me

    Steve is absolutely right, your PIC is most likely dead
    and this is good for a 16F84.
    There are far better chips at much lower prices available.

    As you now have got to get a new one anyway this is
    a perfect moment to think about a re-design of your hardware.
    (This will reduce the total cost of the circuit dramatically!)

    Sorry again, but your initial design wouldn't have worked anyway.
    In addition to what Steve already has mentioned,
    there should be Pull Down Resistors on RB2,3,4,5,6 and RA4

    If you need help with the re-design let us know.

    Steve

    Yet another case where someone started with 16F84 where life could have been so easy.
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  12. #12
    Programmednew's Avatar
    Programmednew Guest


    Did you find this post helpful? Yes | No

    Unhappy

    The chip did burn and the reason why is that I have a cousin that knows a lot about electronics and me not knowing a lot I sent the circuit off to him. He sent it back and said it's fixed. So I wired it up. I think he just wasn't thinking but anyways thank you for all the help and I mean that, I am really thankfull. I have the hex file thanks to y'all and will be getting another PIC. If I have anyother problems I will come back to this thread.

  13. #13
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    I agree with Ralph on that issue... Let us know what's happen, if we can help you on anything else. Let us suggest you PIC16F627 or PIC16f628. If you still want to do your project, PIC12F508 can be the cheapest FLASH PIC you can use for your need, and you'll not need any external crystal.

    Give some *words* to your cousin...

    Ralph

    Steve is absolutely right, your PIC is most likely dead
    and this is good for a 16F84.
    There are far better chips at much lower prices available.
    Hehe... seems you really don't like those F84. I have to agree to the better chips at much lower price. Maybe one day Microchip will stop the production... they're still bringing$$$

    In addition to what Steve already has mentioned,
    there should be Pull Down Resistors on RB2,3,4,5,6 and RA4
    Indeed, just forget/skip when i saw *virtually blown* PIC with VSS VDD inverted. Next design could be also made with internal pull up.

    BTW Programmednew welcome to the forum and in the PIC world!!!
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  14. #14
    Warrier's Avatar
    Warrier Guest


    Did you find this post helpful? Yes | No

    Default

    Hi Programmednew:

    Besides all that Steve and Ralph suggested don't forget that the PIC chips don't put out lot of current to drive a relay directly. Absolute rating is only 25mA so unless you are using a hi sensitivity type you're going to kill the output of the PIC pretty fast! Talk to your cousin about this also.


    STEVE:

    It looks like he needs more I/O than the F508 can get him even if he uses IntRC clock!

    Using F628 or F630 would be cheaper for him but then he shouldn't forget the CMCON settings! F630 has 4 lesser pins to boot.

    He can replace the 7805 coming out of his ignition switch with a series resistor and a 5Vzener, I would assume....or use two 1N4148 diodes to configure an OR gate.

    __warrier

  15. #15
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Just to summarize:

    An 8pin pic running on INTRC OSC would perfectly fit with it's 6 I/O-pins.

    1 pin for external switch / ignition detection
    1 pin to drive the relay

    leaves 4pins for "Config options"
    that gives 16 different possibilities !

    >>He can replace the 7805 coming out of his ignition switch
    >>with a series resistor and a 5V zener.
    this is absolutely correct, but
    a simple voltage divider consisting of two resistors would do the job as well

    Let Programmednew come back with his requirements and we will draw a working schematic for him.

    The final board (including the relay) will fit in a matchbox.
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  16. #16
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Programmednew, can you access to the horn wire directly to the stearing collumn instead, most of them are negative. In this case most car alarm/remote starter use a simple transistor npn TO92 package to drive it directly.

    this is absolutely correct, but
    a simple voltage divider consisting of two resistors would do the job as well
    Can also be a simple resistor (let's say 1k-10K) in serie with the ignition wire(thanks to the internal diode of PIC). When you turn off the key, this wire will give enough *low level signal impedance* to avoid PIC read a floating signal.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  17. #17
    Warrier's Avatar
    Warrier Guest


    Did you find this post helpful? Yes | No

    Default

    Ralph:

    So long as our friend knows that in an 8pin device, he is forced to use the MCLR pin as the input and ports are GPIOs rather than PORT x etc.

    __warrier

  18. #18
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    well this is why we offer our service to plan his next code/schematics.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  19. #19
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    OK, Guys,

    let's stop here and wait for Programmednew to come back with his requirements.
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  20. #20
    Programmednew's Avatar
    Programmednew Guest


    Did you find this post helpful? Yes | No

    Angry

    I'm back. My current circuit didn't work and was to big. I need your help on designing a whole new circuit. What I need it to do is when 12VDC is put in to the circuit it needs to work a relay that uses the same 12VDC out of its point to produce pulses to honk the horn relay. I need the beeps to be adjustable from 1 to 8-10 beeps. Then I need a external switch that if it is on then the circuit won't put anything out. Then I need to monitor the ignition switch. If it is on then the circuit should not put anything out. That is it for the requirements. I am sooooo thankful that I found this forum and that ya'll are on it. I thankyou for your help soooo much.
    Last edited by Programmednew; - 21st January 2005 at 02:02.

  21. #21
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Programmednew

    attached is a qiuck draft of a schematic and Board Layout.
    (It will fit in a Matchbox)


    regards

    Ralph
    Attached Images Attached Images  

  22. #22
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Attached is a Board Layout

    regards

    Ralph
    Attached Images Attached Images  

  23. #23
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Programmednew

    Ralph idea is quite good. But car horn need more than 300mA. So be carefull on your relay choice. Most car horn will need up to 5-7 amps. In thise case, most relay, that i know, will need more than 25mA to drive them. Be carefull on that to avoid blow your PIC output.

    BTW i attach my own version.

    Ralph
    i don't want to start any kind of controversy here. Agree my apologies on that issue.
    Attached Images Attached Images  
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  24. #24
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Steve,

    I agree there are "many" possible ways.

    I was assuming (and according to the "original" schematic) there is another relay that drives the horn.
    (I just wanted to make it as small as possible as I had promised it would fit in a matchbox)

    I had the "IGNITION Bypass" Diode in mind to free up another Port to double the options.

    regards

    Ralph

  25. #25
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Ralph,

    If Programmednew can access the horn wire directly under the dash at the column stearing it will be easier. Most of them are negative and they drive an external relay to drive the horn. In this case, he will be able to remove the relay and keep only the transistor + diode.

    OR skip the relay idea and use a MOSFET to drive in positive the horn is a common use in some car stuff.

    Programmednew

    If you can provide your car model and year, i can provide you the color of the horn wire at the stearing... if i know you car model.
    Last edited by mister_e; - 21st January 2005 at 15:34.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  26. #26
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Here's a code for you to start.
    Attached Files Attached Files
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  27. #27
    Programmednew's Avatar
    Programmednew Guest


    Did you find this post helpful? Yes | No

    Question

    The model is a ford 350 and year 2000. I like mister_e's idea. I also need to know whether or not the horn wire is positive. I also need help in the code you sent me.

    AmountOfPulses = GPIO & $0F ' Get only value of GP<3:0>

    I assume that it reads those pins and stores the value in the variable. I need to know how it does that and how does it adjust from 0 to 16 pulses with only three switches. I can access the wire from under the dash.

    P.S. My Name is Albert

  28. #28
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Ford F-350 must be BLUE (around 20 AWG) right to the stearing column... as i remind in a black 5-8 pin connector, the last one right to the stearing column. Just remove the panel under the stearing and look at this. As i remind it's in the same connector as the cruise control too (if you have)

    Under the dash you can acces also
    1. 12V = Yellow or Green (sometimes green/black) (14-16 AWG)
    2. Ignition = RED with GREEN tracer, (sometimes green/something)

    Be careful when testing the horn wire, use multimeter or logic probe. AND it's a negative signal to activate the horn.

    AmountOfPulses = GPIO & $0F ' Get only value of GP<3:0>

    I assume that it reads those pins and stores the value in the variable. I need to know how it does that and how does it adjust from 0 to 16 pulses with only three switches.
    with my circuit, you're using 4 switches. In binary, it gives you 16 possibility

    DIP PULSES
    0000 = 0
    0001 = 1
    0010 = 2
    0011 = 3
    0100 = 4
    0101 = 5
    0110 = 6
    0111 = 7
    1000 = 8
    1001 = 9
    1010 = 10
    1011 = 11
    1100 = 12
    1101 = 13
    1110 = 14
    1111 = 15
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  29. #29
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Originally posted by mister_e

    0000 = 0
    0001 = 1
    0010 = 2
    0011 = 3
    0100 = 4
    0101 = 5
    0110 = 6
    0111 = 7
    1000 = 8
    1001 = 9
    1010 = 10
    1011 = 11
    1100 = 12
    1101 = 13
    1110 = 14
    1111 = 15
    There are only 10 types of people:
    Those who understand binary, and those who don't ...


    ;-)

  30. #30
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Talking

    LOL !

    That's why i really love your signature ! ;-)
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  31. #31
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Steve,

    you have "won" the price.

    As your design is preferred I'll leave the further support with you.

    ;-)
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  32. #32
    Programmednew's Avatar
    Programmednew Guest


    Did you find this post helpful? Yes | No

    Thumbs up

    I got Ralph's signature but clearly I am not a binary thinking guy. Great Idea for the binary switch but how is the new circuit hookup ( I just don't want to get this wrong) and instead of the relay I would like to just use the transistor and diode and only if you think it will handle it.

    P.S What kind of schematic drawing software are you using.

  33. #33
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    I'm using EAGLE

    you can download a free version at

    http://www.cadsoftusa.com/
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  34. #34
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    The circuit i provide you will handle it. As i said, the stearing column activate an external relay wich is need less than 60mA

    I use P-CAD.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  35. #35
    Programmednew's Avatar
    Programmednew Guest


    Did you find this post helpful? Yes | No

    Default

    Ok Thankyou. I will just use the transistor. Will let you know

  36. #36
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Originally posted by mister_e


    Ralph idea is quite good. But car horn need more than 300mA. . .

    Steve

    B.T.W.

    The OMRON Relais are good for 3 Amps

    I used this one with "my design" because I have about 60pcs. in stock.

    See: Relais Specs
    Last edited by NavMicroSystems; - 23rd January 2005 at 15:24.
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  37. #37
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Ralph

    I've to do some apologies for that... sorry Ralph. I was refering to the Digikey website, in the contact rating column they said 300ma. Forgeting the voltage rating and read the whole datasheet.

    BUT, maybe i'm blind on this G6K-2P-DC5

    http://rocky.digikey.com/WebLib/Omro...20Data/G6K.pdf

    contact rating 1 amp @ 30VDC. let's say 2.5 amp @ 12Volts.

    DPDT with contact in parrallel... can be good up to 5 amps

    It was my 2 cents

    Last edited by mister_e; - 24th January 2005 at 02:01.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  38. #38
    Programmednew's Avatar
    Programmednew Guest


    Did you find this post helpful? Yes | No

    Question

    I like using your circuit but there is one problem. The programmer I use is the one attached in the picture, it hooks to a serial port (I didn't want to spend a lot after buying PIC Basic Pro). The hex burner I use is ICProg and it doesn't handle that chip. Any suggestions. I haven't ordered the parts yet so if you need to change the circuit then it's ok.
    Attached Images Attached Images  

  39. #39
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Is your device support one of the following?

    PIC12F629
    PIC12F675
    PIC12F683

    But i think, not tested yet, you can program 12F508 with the PIC12C508 protocol.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  40. #40
    Programmednew's Avatar
    Programmednew Guest


    Did you find this post helpful? Yes | No

    Thumbs up

    Yes the PIC12F629 and the PIC12F675. Which one do I use and is there anything else before I order the parts.

Similar Threads

  1. Code doesn't work on 16F648A
    By Mr_Joe in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 1st September 2018, 22:09
  2. Cordic trig assembly code for PIC18f
    By ScaleRobotics in forum mel PIC BASIC Pro
    Replies: 54
    Last Post: - 8th September 2015, 05:36
  3. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  5. Replies: 1
    Last Post: - 31st August 2005, 20:00

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts