How to make an over-current fuse/switch to avoid damage to a brushless motor

Discussion in 'OnBoard Electronics & Controls' started by BertKu, Aug 15, 2015.

  1. BertKu
    Joined: May 2009
    Posts: 2,521
    Likes: 47, Points: 58, Legacy Rep: 223
    Location: South Africa Little Brak River

    BertKu Senior Member

    Good morning EK and Porta,
    Tomorrow morning I am on the way to Cape Town again. This week I had no time to attend to the 2 systems. I had to modify my Colt, so that the electric fan would come on as soon the engine starts heating up. It is a 2.8 Liter engine and thus generate enough heat to get into trouble.
    Next week maybe I will have more time.
    Bert
     
  2. BertKu
    Joined: May 2009
    Posts: 2,521
    Likes: 47, Points: 58, Legacy Rep: 223
    Location: South Africa Little Brak River

    BertKu Senior Member

    Good morning Porta and EK

    No, I haven’t forgotten or wish to stop with this project for you both. I am not looking for excuses, but had absolute no time on working on the projects, other than buying more components and material. The sale of my daughter’s flat in Cape Town was taken all my time up. Not only driving to and from there, took lots of time, but the transfer was a nightmare in getting all the documents organised at a time that everybody is gearing up for our annual Summer Holiday. Also selling and packing her left over belongings to Europe took much more time than I ever could have thought it would.

    At least that is now over.

    I bought some hall sensors and want to experiment which method works the best. Not so much for you EK, but for Porta. The advantage is that one has no losses due to measuring resistance in the current wiring, in view that the sensor will be glued onto the copper wire. Only the power consumption of the IC/Electronics and MOSfet losses is now what we will have and that has to be less. The ADC takes 200 nano Second, while the sensor only Microseconds and thus the spikes may no longer be an issue.

    I am afraid, I will not be finished before Christmas. I have a few personal problems to resolve first. Sorry Porta, I would have loved to have it posted as a Christmas gift, now you have to wait even longer. EK is in any way in the snow and rough weather, thus there I have some time. I do my best.
    Bert
     
  3. BertKu
    Joined: May 2009
    Posts: 2,521
    Likes: 47, Points: 58, Legacy Rep: 223
    Location: South Africa Little Brak River

    BertKu Senior Member

    Oh I forgot,
    Every time we make a change, I have to make a new PC board layout and make a new pc board. Thus again I have to make new pc boards.
     
  4. BertKu
    Joined: May 2009
    Posts: 2,521
    Likes: 47, Points: 58, Legacy Rep: 223
    Location: South Africa Little Brak River

    BertKu Senior Member

    Good morning Porta and EK,

    Compliments of the season , although is is a little late.
    After a fantastic summer holiday and seeing my daughter from Europe again, I had a miserable start of the new year, a fall and a car accident, thus only now I am able to restart your projects again. My own projects are up to date, thus let’s see whether we can bring it to a good end for you both.

    First at all EK, I think you are wrong in assuming that the maximum current at 12 – 17 Volt is only 30 Ampere. As soon you turn the speed up from zero to maximum, fast, fast, your impedance is not build up and you will be surprised how high the current is. I do not think you run the motor on 30 x 12 = 360 watt i.e. ½ horsepower or at full speed and at 17 Volt, 40Ampere x 17 Volt = nearly 1 horsepower. I think you run the motor at 1 horse power most of the time.

    I therefore will make you 2 IC’s., one for 40 Ampere and one for 50 Ampere. Except if you strongly disagree, I will then make it for 30 Ampere and 40 Ampere. But I think you could possible avoid let me unnecessary spend my money.

    Monday I have my last treatment from the physiotherapist, Tuesday – Thursday I will be in Cape Town again and will see how far we will get.
    Porta for you, the system is running so, so. I am worried that your average current is not what I am testing the system with. Bear in mind the Analogue to Digital converter is very fast in relation to the pulses and spikes from your motor. Thus average current is a big gamble for me.
    Bert
     
  5. ElectricKayak
    Joined: Mar 2015
    Posts: 78
    Likes: 0, Points: 0, Legacy Rep: 10
    Location: Canada

    ElectricKayak Junior Member

    Sorry to hear about the fall and car accident Bert. Hopefully all is well.

    I typically run my motor with a 4S lipo battery and draw only between 2-4 amps. So operate at less than a tenth of a horse power. I don't increase the speed quickly. So i would like 30 amp. If you will have two IC's then perhaps the second can be 50 rather than 40 (ie 30 and 50)? Nevertheless i like 30.
     
  6. BertKu
    Joined: May 2009
    Posts: 2,521
    Likes: 47, Points: 58, Legacy Rep: 223
    Location: South Africa Little Brak River

    BertKu Senior Member

    Thanks EK, Yes, me too am sorry that it happened. Here a photo, the car was hit at my driver side and the damage is 90.000 Rand +/- 5000 dollar.
    The force of the accident threw my head against the window and I damage my neck badly.

    What I did, at the beginning of me making those controllers, not realized was that, the current one has to take into consideration, is the current when the motor is at full blast and at the highest Voltage. That is also the current which is for fractions of a second applicable. Although the average current maybe 200 milli Ampere. For that reason a brushless motor has maximum torque, even at 1 rpm. The Analogue to Digital converter is substantial faster than the pulses created by the PWM. It picks up all the highest peaks.
    One notice it clearly when one turns the controller on and move directly to maximum speed, before the motor with load can keep up. Your low resistance is playing then a major role.

    Your suggestion is a fair one and I will make it for 30 and 50 Ampere. Good compromise.
     

    Attached Files:

  7. BertKu
    Joined: May 2009
    Posts: 2,521
    Likes: 47, Points: 58, Legacy Rep: 223
    Location: South Africa Little Brak River

    BertKu Senior Member

    Good day EK,

    You must be pleased that you use Lithium batteries. The reason I say so, it is a known factor that if a Sealed Lead Acid Battery draws high currents, although the average may be within specifications of the Ah rating of a SLAB, with a brushless motor you would have substantial less battery usage than indicated on the Ah rating. In your case, if you would use a 9Ah SLAB, one should not discharge it to less than 50% i.e. 4,5 Ah, and you use like you said 2-3 Ampere , you would think, that you have 1,5 to 2 hours. Unfortunately you may have only 1 hour. The 30 Ampere currents, although it gives you an average of 2 - 3 Ampere, is the reason for that.
    Bert
     
  8. ElectricKayak
    Joined: Mar 2015
    Posts: 78
    Likes: 0, Points: 0, Legacy Rep: 10
    Location: Canada

    ElectricKayak Junior Member

    Actually I get almost exactly what is spec'd for my AGM battery based on drawing the stated average amps. If it predicts 3 amps will last 3 hours then I get 3 hours.

    Also I design for 90% DOD. Theoretically less cycles but double the range. Energy density is more important than maximizing the cycle count. Even at 90% DOD I get several hundred cycles and that lasts years and years. :)
     
  9. BertKu
    Joined: May 2009
    Posts: 2,521
    Likes: 47, Points: 58, Legacy Rep: 223
    Location: South Africa Little Brak River

    BertKu Senior Member

    Just came back from Cape Town.

    You are right, for an AGM, the plates are thicker with more lead.
    I was not able to get the zenerdiode I liked to get, but will use 2 x 500mw in series, giving me the right voltage. When will you start Kayaking again?
    Bert
     
  10. ElectricKayak
    Joined: Mar 2015
    Posts: 78
    Likes: 0, Points: 0, Legacy Rep: 10
    Location: Canada

    ElectricKayak Junior Member

    It will be several months still... Lol
     
  11. Jim Caldwell
    Joined: Aug 2013
    Posts: 267
    Likes: 8, Points: 18, Legacy Rep: 48
    Location: Cleveland, Ohio

    Jim Caldwell Senior Member

    Just a note about LI vs lead acid, I have a 24 volt electric bike (curie?)that used 2-12 volt small batteries that would only last about 60 days in almost daily use around the property with a BIG performance drop off after 30 days.
    I was a fast electric boat racer for 20+ years so I installed 6s 5000mah LI batteries and my Data Logger.
    Bike has a cheap 40 amp controller, first full throttle take off produced blinding acceleration and 82!!! AMPS, last time I did that, but controller survived.
    The take away is LI because of their vastly lower risestence ( below 2.0 Mohm )
    are capable producing whatever the motor calls for.
    Now I slowly roll the throttle on over about 10 seconds.
    The 6s (24.6 volt) race boat pulls 240 amps on start up and 180 amps continuous for the 2 minute race.
     
  12. portacruise
    Joined: Jun 2009
    Posts: 1,475
    Likes: 178, Points: 63, Legacy Rep: 218
    Location: USA

    portacruise Senior Member

    New year's greetings, guys.
    EK, your setup allows for 90% DOD because you are running the motor at maybe 10% of rated capacity. So you can crank up the speed control to deliver good but whatever short performance is left, even when the voltage drops to near 100% DOD or below. For most systems with mated battery/motor design, the performance suffers considerably as the capacity of both volts and amps drops. My equivalent way of doing is overvolt the motor and keep the speed control below 100% once the motor is warm and vulnerable. When not using a speed control, I quick change (1 min.) out props to more aggresive models which restores performance when reaching down to 80% DOD. Either way monitoring the amps and backing off is the way to keep from cooking anything.
    There are trade offs in the various different lithium battery chemistries, the greatest number of cycles may not be achieved with the low internal resistance types. Nicads are the toughest in my experience (some early satellite designs still active AFAIK), thrive on 100% DOD to keep the memory effect away.
     
  13. BertKu
    Joined: May 2009
    Posts: 2,521
    Likes: 47, Points: 58, Legacy Rep: 223
    Location: South Africa Little Brak River

    BertKu Senior Member

    Good morning EK and Porta,
    Everybody probably thinks, nothing will materialize. Tough luck for those people, who thought so. Actually I should never have offered to make those units for you both. The problems I experienced during some hundreds of hours to solve this simple problem and when I was so dumb to have my main computer to change to Win10, gave me weeks of trouble, my printer and scanner did no longer work. My software for making pc boards had the most incredible errors in them and so also my development platform. I could not go back to Win7, as Microsoft did not let me, although it states: select WIN10 or an older version. I did not have the time with those games they are playing. They changed the boot sector. All what I got, was those childish messages: Do you like this picture? But those 500 youngsters working on WIN10 should spend their time on more important issues, like getting Win10 stable.

    So that is off my chest.

    EK I have your unit working and reasonable happy with it. What I did is the following.

    a) I could not make the DC-DC converter properly going. To need 12 Volt on top of the 12 Volt to switch the IRFP064N to the plus line . The DC-DC is a 100KHz chopper, but with the internal capacity, it took too long to switch the MOSfet off, as fast as you requested.
    b) Secondly I could not get the internal 8 millOhm low enough and the power dissipation was too high to my liking,
    c) Thirdly, if the IC (PIC12F675) fails the MOSfet is not switched off and that was not acceptable to me. Also a couple of other issues.
    d) Thus I switch now the minus line.
    e) I have a 30 Ampere IC and 50 Ampere PIC12F675 IC. Open the unit careful, by removing the temporally insulation tape, thereafter by losing the 2 cable gland nuts and remove the inside to the plus 12 Volt input side. Careful not to break the wires to the Blue Flashing LED. Before you swap, please test the system with the already placed 30 Ampere IC. If your controller/motor is giving also very fine spikes when the P(ulse) W(idth) M(odulator) is opened by 1 % , like mine, you may have to place the 50 Ampere IC in the socket. I had very fine pulses at opening of the speed control due to the fast switching of the MOSfets. That is logical, because de MOSFets at 1% PWM are switching very fast and a brushless motor has maximum currents basically even at 1% PWM.
    f) Observe the little dot, which must be in the correct position. Towards the Plus 12 VOLT >> IN
    g) Do not reverse accidental the + and – 12 Volt.
    h) Your Input is from 10 to 20 Volt.
    i) I have in the parcel an old small board with 2 extra 10 milli Ohm resistors.
    j) The rules are simple.
    a. If you remove 2 x 10 mOhm resistors on that little board i.e. 4 x 10 mOhm , your cut off point is +/- 20 Ampere
    b. As it is with the 30 Amp IC, it is +/- 30 Ampere
    c. If you add 2 resistors, i.e. 8 x 10 mOhm your cut off point is +/- 40 Ampere
    d. If you swap the IC for the 50 Amp, your cut off will be +/- 50 Ampere, without the 2 extra added resistors
    e. If you add those two resistors, i.e. 8 x 10 mOhm, your cut off will be +/- 60 Ampere
    k) Do not swap the + 12 Volt input with the output, you will have a conductive circuit.
    l) It is clearly marked “12 V >> IN”. And “>> OUT”.
    m) If everything is working to your satisfaction, you have to seal the unit with Marine silicone.
    The problem is, that I have no clue, on how your unit is performing, you may get fine spikes. It is very difficult to make something one cannot test on the end product. Those spikes are at a frequency of +/- 10 – 20 Khz, The Analogue to Digital converter is always faster and is not synchronised. My oscilloscope is only a 10Mhz one. The crystal runs at 20 Mhz and one cycle takes 50 nano Second and a loop +/- 4 Micro second. I still want to see whether I can improve on some issues, but basically it is ready.
    Please may I have a Poste Restante Post office address, I will then give you a private message how the markings are, photo’s and the tracking number.
    I will leave for Europe in 3 weeks time and like to have it settled before that time.


    Now you, Porta.

    I have no clue what the actual peaks are of your currents. I cannot test the final product from this distance. Your average is not good enough for the Analogue To Digital Converter. They sense the fast peak voltages/currents. Thus I have to gamble. I wish that I could have better information about your currents and waveform.
    I have the software running already in August 2015 with 12 loops. I.e. As soon the voltage drops or increases between 17 and 23 Volt, a different loop is selected, which determine the lower or higher overload/cut off currents. Thus when a battery gets emptier, the lower overload current or cut off current is selected.
    We may have to post you a unit and then you may have to send the IC on its own back to me, for either update higher or lower values, should it not work to your satisfaction. I have found a development platform I am not using anymore and let this have you with my compliments. It will be the PICKIT 2. You get a DVD with the Microchip software and you can modify the current and overload cut off levels for higher or lower current. Or you don’t want to use the DVD, download all info from Microchip. But that take approx a year.
    Go to www.microchip.com/mplabx and try to find your way. But I recommend, load the DVD version V8.70 in the parcel. The software is already written and you need only to know how to modify and how to program the chip again. It runs on Win, Win7, WinXP, Win8, Win10. But I am not too sure about WIN10 , 100% working anymore.
    In the parcel you will find some instructions on how to get to know the development platform and as much help from me to make it a success.

    This you only need, if you are unhappy with the performance of what I have done.

    DO not lock your PIC12F675, i.e. you MUST select : “not code protected”. Otherwise you cannot modify your IC for changes approx a Hundred thousand times. As soon you have locked it, that is it, you have to buy a new IC . Locking a Microchip is basically to protect intellectual property , the software what you have modified. But we both do not care whether it gets copied or not.
    I will get you a detailed list on what to do, step by step. I am away travelling through various European countries and thus If it does not get resolved now, we have to wait for June, when I am back.
    Bert
     
    Last edited: Mar 14, 2016
  14. BertKu
    Joined: May 2009
    Posts: 2,521
    Likes: 47, Points: 58, Legacy Rep: 223
    Location: South Africa Little Brak River

    BertKu Senior Member

    My apology, probably the above is misunderstood and could have interpreted as rude or he is looking for an excuse to get out of his offer. What I meant is that I am so sorry that it took so long to come up with the final product. I apologise for that.

    Porta, I would appreciate, if you could glance through the software I wrote and I personally think that we together could make it work at the end of the day. I am sitting here in Jersey (UK islands) , not in South Africa and have borrowed a laptop to see whether you are still interested to make it work (both , also for you EK, also my apology to you that it took so long).

    Here is the software for you Porta, My problem is that the values for the spikes of your current waves has to come from you, even if it is very close and gambled by you.

    Together , we can probably after 2 or 3 attempts and also some extra postages of an update, get it right. You will see that the values for measuring the battery voltage is correct. Not the values for the overcurrent and labouring. Sadly I will still be for 5 weeks out of my country. However you EK, your concern about battery Voltage drop could also be solved in a similar way as I have done it for Porta. When I am back in South Africa, I will place MY gambled values as a start. I know that you are much more intelligent than me and if I can make it work, so you would be able. But I need some values to start off with.

    Also, I was waiting for a private message from you both, with your confidential and anonym address (Poste Restante), where I could sent the unit to you.

    Porta, The offer for your programmer is still standing. If you don't want it, then EK probably would like to have it. He then can change his values to make it work, by entering low values ( 20 Ampere) and then slowly higher ( 30 or 40 Ampere) until satisfactory.

    Bert

    ******************************************************
    include "P18F2431.INC"
    ; list P=P18F2431

    ; Author Bert Kuijpers ; Date 15 August 2015
    ; Overcurrent and battery protocol to stop the motor.
    ; company none, private
    ; file-name TexasPorta

    ; This programmed chip cuts off at 24 Volt at 3 Ampere
    ; shunt resistor must be 40 milliOhm i.e.= 120 milliVolt + 100 Ohm inseries
    ; i.e. depending on the tolerance = 106 mV , total thus +/- 220 mV

    ; voltages: 256 bit = 5 Volt. One step = 19,53125 Volt. However, due to the voltage divider.
    ; It is actual 6 x larger i.e. +/- 0,47 Volt steps. 6 times 4 bit steps x 19.53125 = 0,46875 Volt steps
    ;
    ; 8 bit ...... voltage over ........ battery voltage
    ; v........... 1 killiOhm ............. v
    ;
    ; 204 = 3.9843 Volt = nearly 24.0 Volt (remember, the voltage
    ; 200 = 3.9062 Volt = 23.7637 Volt is measured 1/6 of 24 Volt,
    ; 196 = 3.8281 Volt = 22.9686 Volt due to the 2 resistore in serial
    ; 192 = 3.7500 Volt = 22.5000 Volt one of 1 Kilo Ohm and 1 0f 5 Kilo Ohm
    ; 188 = 3.6719 Volt = 22.0312 Volt because the micropocessor can only
    ; 184 = 3.5937 Volt = 21.5625 Volt measure voltages of up to 5 Volt maximum
    ; 180 = 3.5156 Volt = 21.0937 Volt
    ; 176 = 3.4375 Volt = 20.6250 Volt
    ; 172 = 3.3593 Volt = 20.1562 Volt
    ; 168 = 3.2812 Volt = 19.6785 Volt
    ; 164 = 3.2031 Volt = 19.2187 Volt
    ; 160 = 3.1250 Volt = 18.7500 Volt


    ; The overcurrent sensing and shutdown 1st bit port A,AN0. pin 2
    ; The battery sensing and control 2nd bit port A,AN1. pin 3

    #define LED1 PORTB,1 ;pin 22 whiteLED 390 Ohm
    #define LED2 PORTB,2 ;pin 23 blueLED 270 Ohm
    #define LED3 PORTB,3 ;pin 24 redLED 270 Ohm
    #define BC337 PORTB,4 ;pin 25 BC337



    TEMP1 equ 40h
    TEMP2 equ 41h
    TEMP3 equ 42h
    TEMP4 equ 43h
    cnt equ 44h
    cnt1 equ 45h
    ; ------------------------------------------------------------------------------
    org 0x000 ; startup vector
    nop ; required for ADC operation
    clrf PCLATH ; ensure page bits are cleared
    goto Initialize ; go to beginning of program
    org 0x008 ; interrupt vector location
    retfie ; return from interrupt
    org 0x018 ; interrupt vector location
    retfie
    Initialize
    movlw B'00000011' ; A/D on RA0, RA1.
    movwf TRISA
    movlw b'00000011'
    movwf LATA
    movlw b'00000000' ; outputs and cutoff to PIC16F877A/1937
    movwf TRISB
    movwf b'00000000'
    movwf LATB
    movlw b'00000000'
    movwf LATC
    bcf LED1 ; ensure LED on is switched off
    bcf LED2 ; ensure overheating is reset
    movlw B'11000000' ; timer0 = on ; timer0 = 8bit 1;2
    movwf T0CON
    clrf TEMP1
    clrf TEMP2
    bsf LED1 ; display program running
    call SetAN0
    Loop
    call ReadADC
    next
    movlw 0x0F
    movwf cnt
    next1
    decfsz cnt
    goto next1
    bcf BC337 ; after a succesful reading, open MOSFet
    goto Loop

    ReadADC
    btfsc ADCON0,DONE
    bra ReadADC
    movf ADRESL,w ; get ADC result, overcurrent first
    movwf TEMP1,TEMP4 ; save result for calculatng over-current
    movlw B'00010001'
    movwf ADCON1
    movf ADRESL,w ; get second ADC result for actual battery voltage
    movwf TEMP2,TEMP3 ; save result for calculating what to do next
    movf TEMP2,w
    sublw 0xC8 ; subtract 200 step (Hex C8)
    btfss STATUS,N ; if negativ bit is set > voltage < 23.8 Volt
    goto checkcurrent1
    movf TEMP3,TEMP2
    movf TEMP2,w
    sublw 0xC4 ; subtract 196 step (Hex C4)
    btfss STATUS,N ; if negativ bit is set > voltage < 22.9 Volt
    goto checkcurrent2
    bcf STATUS,N
    movf TEMP3,TEMP2
    movf TEMP2,w
    sublw 0xC0 ; subtract 192 step (Hex C0)
    btfss STATUS,N ; if negativ bit is set > voltage < 22.5 Volt
    goto checkcurrent3
    bcf STATUS,N
    movf TEMP3,TEMP2
    movf TEMP2,w
    sublw 0xBC ; subtract 188 step (Hex BC)
    btfss STATUS,N ; if negativ bit is set > voltage < 21.6 Volt
    goto checkcurrent4
    movf TEMP3,TEMP2
    movf TEMP2,w
    sublw 0xB8 ; subtract 184 step (Hex B8)
    btfss STATUS,N ; if negativ bit is set > voltage < 21.1 Volt
    goto checkcurrent5
    bcf STATUS,N
    movf TEMP3,TEMP2
    movf TEMP2,w
    sublw 0xB4 ; subtract 180 step (Hex B4)
    btfss STATUS,N ; if negativ bit is set > voltage < 20.7 Volt
    goto checkcurrent6
    bcf STATUS,N
    movf TEMP3,TEMP2
    movf TEMP2,w
    sublw 0xAC ; subtract 176 step (Hex AC)
    btfss STATUS,N ; if negativ bit is set > voltage < 20.2 Volt
    goto checkcurrent7
    movf TEMP3,TEMP2
    movf TEMP2,w
    sublw 0xA8 ; subtract 172 step (Hex A8)
    btfss STATUS,N ; if negativ bit is set > voltage < 19.7 Volt
    goto checkcurrent8
    bcf STATUS,N
    movf TEMP3,TEMP2
    movf TEMP2,w
    sublw 0xA4 ; subtract 168 step (Hex A4)
    btfss STATUS,N ; if negativ bit is set > voltage < 19.3 Volt
    goto checkcurrent9
    bcf STATUS,N
    movf TEMP3,TEMP2
    movf TEMP2,w
    sublw 0xA0 ; subtract 164 step (Hex A0)
    btfss STATUS,N ; if negativ bit is set > voltage < 18.8 Volt
    goto checkcurrent10

    clrf TEMP1, TEMP2
    clrf ADRESH, ADRESL
    bcf STATUS,N
    movlw B'00010000'
    movwf ADCON1
    bsf ADCON0,GO ; restart ADC
    return




    checkcurrent1
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no overcurrent
    goto overcrntloop
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no laboring
    goto laboringloop
    goto Loop
    checkcurrent2
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no overcurrent
    goto overcrntloop
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no laboring
    goto laboringloop
    goto Loop
    checkcurrent3
    movf TEMP1,TEMP4
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no overcurrent
    goto overcrntloop
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no laboring
    goto laboringloop
    goto Loop
    checkcurrent4
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no overcurrent
    goto overcrntloop
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no laboring
    goto laboringloop
    goto Loop
    checkcurrent5
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no overcurrent
    goto overcrntloop
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no laboring
    goto laboringloop
    goto Loop
    checkcurrent6
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no overcurrent
    goto overcrntloop
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no laboring
    goto laboringloop
    goto Loop
    checkcurrent7
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no overcurrent
    goto overcrntloop
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no laboring
    goto laboringloop
    goto Loop
    checkcurrent8
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no overcurrent
    goto overcrntloop
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no laboring
    goto laboringloop
    goto Loop
    checkcurrent9
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no overcurrent
    goto overcrntloop
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no laboring
    goto laboringloop
    goto Loop
    checkcurrent10
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no overcurrent
    goto overcrntloop
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no laboring
    goto laboringloop
    goto Loop





    overcrntloop
    bsf LED2 ; put blue LED2 on
    movlw 0xFF
    movwf cnt
    movwf cnt1
    loop2
    decfsz cnt
    goto loop2
    decfsz cnt1
    goto loop2
    bcf LED2 ; switch LED2 off
    movlw 0xFF
    movwf cnt
    movwf cnt1
    loop3
    decfsz cnt
    goto loop3
    decfsz cnt1
    goto loop3
    goto overcrntloop

    laboringloop
    bsf BC337
    bsf LED3 ; put Red LED on
    movlw 0xFF
    movwf cnt
    movwf cnt1
    loop4
    decfsz cnt
    goto loop4
    decfsz cnt1
    goto loop4
    bcf LED3 ; switch Red LED off
    movlw 0xFF
    movwf cnt
    movwf cnt1
    loop5
    decfsz cnt
    goto loop5
    decfsz cnt1
    goto loop5
    goto laboringloop

    SetAN0
    movlw B'00010000'
    movwf ADCON1
    movlw B'10101001' ; right justified, 10 TAD, FOSC/8
    movwf ADCON2
    movlw B'00000100'
    movwf ADCON3
    movlw B'00000000'
    movwf ADCHS
    movlw B'00000011'
    movwf ANSEL0 ; ensure AN0,1,2 ADC input is analogue
    movlw B'00010001'
    movwf ADCON0
    bsf ADCON0,GO ; start ADC
    return
     
    Last edited: Apr 26, 2016

  15. BertKu
    Joined: May 2009
    Posts: 2,521
    Likes: 47, Points: 58, Legacy Rep: 223
    Location: South Africa Little Brak River

    BertKu Senior Member

    In November 2015 I made some modifications, whereby should the Voltage drop too low, the system carried on, in testing the over current and labouring.

    Here is the updated program.

    for info: btfss is an instruction which makes the processor skipping or jumping.
    btfss stands for: skip if Negative bit is set.
    btfsc stands for; skip if Negative bit is clear (0)

    By deducting an amount, one can manipulate the result and thereby if the battery voltage has dropped go to a different routine. I could have used "nesting" to make the program smaller, but this is easier to understand and give me estimated values for your kayak or boat.
    Bert


    include "P18F2431.INC"
    ; list P=P18F2431

    ; Author Bert Kuijpers ; Date 15 August 2015 - Modified for improvements 9 November 2015
    ; Overcurrent and battery protocol to stop the motor.
    ; company none, private
    ; file-name TexasPorta

    ; This programmed chip cuts off at 24 Volt at 3 Ampere
    ; shunt resistor must be 40 milliOhm i.e.= 120 milliVolt + 100 Ohm inseries
    ; i.e. depending on the tolerance = 106 mV , total thus +/- 220 mV

    ; voltages
    ; 8 bit voltage over battery voltage
    ; v 1 killiOhm v
    ; 204 = 3.9843 Volt = nearly 24.0 Volt (remember, the voltage
    ; 200 = 3.9062 Volt = 23.7637 Volt is measured 1/6 of 24 Volt,
    ; 196 = 3.8281 Volt = 22.9686 Volt due to the 2 resistore in serial
    ; 192 = 3.7500 Volt = 22.5000 Volt one of 1 Kilo Ohm and 1 0f 5 Kilo Ohm
    ; 188 = 3.6719 Volt = 22.0312 Volt because the micropocessor can only
    ; 184 = 3.5937 Volt = 21.5625 Volt measure voltages of up to 5 Volt maximum
    ; 180 = 3.5156 Volt = 21.0937 Volt
    ; 176 = 3.4375 Volt = 20.6250 Volt
    ; 172 = 3.3593 Volt = 20.1562 Volt
    ; 168 = 3.2812 Volt = 19.6785 Volt
    ; 164 = 3.2031 Volt = 19.2187 Volt
    ; 160 = 3.1250 Volt = 18.7500 Volt


    ; The overcurrent sensing and shutdown 1st bit port A,AN0. pin 2
    ; The battery sensing and control 2nd bit port A,AN1. pin 3

    #define LED1 PORTB,1 ;pin 22 whiteLED 390 Ohm
    #define LED2 PORTB,2 ;pin 23 blueLED 270 Ohm
    #define LED3 PORTB,3 ;pin 24 redLED 270 Ohm
    #define BC337 PORTB,4 ;pin 25 BC337



    TEMP1 equ 40h
    TEMP2 equ 41h
    TEMP3 equ 42h
    TEMP4 equ 43h
    cnt equ 44h
    cnt1 equ 45h
    ; ------------------------------------------------------------------------------
    org 0x000 ; startup vector
    nop ; required for ADC operation
    clrf PCLATH ; ensure page bits are cleared
    goto Initialize ; go to beginning of program
    org 0x008 ; interrupt vector location
    retfie ; return from interrupt
    org 0x018 ; interrupt vector location
    retfie
    Initialize
    movlw B'00000011' ; A/D on RA0, RA1.
    movwf TRISA
    movlw b'00000011'
    movwf LATA
    movlw b'00000000' ; outputs and cut-off.
    movwf TRISB
    movwf b'00000000'
    movwf LATB
    movlw b'00000000'
    movwf LATC
    bcf LED1 ; ensure LED on is switched off
    bcf LED2 ; ensure overheating is reset
    movlw B'11000000' ; timer0 = on ; timer0 = 8bit 1;2
    movwf T0CON
    clrf TEMP1
    clrf TEMP2
    bsf LED1 ; display program running
    call SetAN0
    bcf BC337 ; open MOSFet
    next
    movlw 0x0F
    movwf cnt
    next1
    decfsz cnt
    goto next1
    Loop
    call ReadADC
    goto Loop

    ReadADC
    btfsc ADCON0,DONE
    bra ReadADC
    movf ADRESL,w ; get ADC result, overcurrent first
    movwf TEMP1,TEMP4 ; save result for calculatng over-current
    movlw B'00010001'
    movwf ADCON1
    movf ADRESL,w ; get second ADC result for actual battery voltage
    movwf TEMP2,TEMP3 ; save result for calculating what to do next
    movf TEMP2,w
    sublw 0xC8 ; subtract 200 step (Hex C8)
    btfss STATUS,N ; if negativ bit is set > voltage < 23.8 Volt
    goto checkcurrent1
    movf TEMP3,TEMP2
    movf TEMP2,w
    sublw 0xC4 ; subtract 196 step (Hex C4)
    btfss STATUS,N ; if negativ bit is set > voltage < 22.9 Volt
    goto checkcurrent2
    bcf STATUS,N
    movf TEMP3,TEMP2
    movf TEMP2,w
    sublw 0xC0 ; subtract 192 step (Hex C0)
    btfss STATUS,N ; if negativ bit is set > voltage < 22.5 Volt
    goto checkcurrent3
    bcf STATUS,N
    movf TEMP3,TEMP2
    movf TEMP2,w
    sublw 0xBC ; subtract 188 step (Hex BC)
    btfss STATUS,N ; if negativ bit is set > voltage < 21.6 Volt
    goto checkcurrent4
    movf TEMP3,TEMP2
    movf TEMP2,w
    sublw 0xB8 ; subtract 184 step (Hex B8)
    btfss STATUS,N ; if negativ bit is set > voltage < 21.1 Volt
    goto checkcurrent5
    bcf STATUS,N
    movf TEMP3,TEMP2
    movf TEMP2,w
    sublw 0xB4 ; subtract 180 step (Hex B4)
    btfss STATUS,N ; if negativ bit is set > voltage < 20.7 Volt
    goto checkcurrent6
    bcf STATUS,N
    movf TEMP3,TEMP2
    movf TEMP2,w
    sublw 0xAC ; subtract 176 step (Hex AC)
    btfss STATUS,N ; if negativ bit is set > voltage < 20.2 Volt
    goto checkcurrent7
    movf TEMP3,TEMP2
    movf TEMP2,w
    sublw 0xA8 ; subtract 172 step (Hex A8)
    btfss STATUS,N ; if negativ bit is set > voltage < 19.7 Volt
    goto checkcurrent8
    bcf STATUS,N
    movf TEMP3,TEMP2
    movf TEMP2,w
    sublw 0xA4 ; subtract 168 step (Hex A4)
    btfss STATUS,N ; if negativ bit is set > voltage < 19.3 Volt
    goto checkcurrent9
    bcf STATUS,N
    movf TEMP3,TEMP2
    movf TEMP2,w
    sublw 0xA0 ; subtract 164 step (Hex A0)
    btfss STATUS,N ; if negativ bit is set > voltage < 18.8 Volt
    goto checkcurrent10
    goto checkcurrent10
    carryon
    clrf TEMP1, TEMP2
    clrf ADRESH, ADRESL
    bcf STATUS,N
    movlw B'00010000'
    movwf ADCON1
    bsf ADCON0,GO ; restart ADC
    return




    checkcurrent1
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no overcurrent
    goto overcrntloop
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no laboring
    goto laboringloop
    goto carryon
    checkcurrent2
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no overcurrent
    goto overcrntloop
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no laboring
    goto laboringloop
    goto carryon
    checkcurrent3
    movf TEMP1,TEMP4
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no overcurrent
    goto overcrntloop
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no laboring
    goto laboringloop
    goto carryon
    checkcurrent4
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no overcurrent
    goto overcrntloop
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no laboring
    goto laboringloop
    goto carryon
    checkcurrent5
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no overcurrent
    goto overcrntloop
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no laboring
    goto laboringloop
    goto carryon
    checkcurrent6
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no overcurrent
    goto overcrntloop
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no laboring
    goto laboringloop
    goto carryon
    checkcurrent7
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no overcurrent
    goto overcrntloop
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no laboring
    goto laboringloop
    goto carryon
    checkcurrent8
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no overcurrent
    goto overcrntloop
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no laboring
    goto laboringloop
    goto carryon
    checkcurrent9
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no overcurrent
    goto overcrntloop
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no laboring
    goto laboringloop
    goto carryon
    checkcurrent10
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no overcurrent
    goto overcrntloop
    movf TEMP1,w
    sublw 0xC8 ; subtract ???? step (Hex ??)
    btfsc STATUS,N ; if positiv, (bit is not set) > no laboring
    goto laboringloop
    goto carryon




    overcrntloop
    bsf LED2 ; put blue LED2 on
    movlw 0xFF
    movwf cnt
    movwf cnt1
    loop2
    decfsz cnt
    goto loop2
    decfsz cnt1
    goto loop2
    bcf LED2 ; switch LED2 off
    movlw 0xFF
    movwf cnt
    movwf cnt1
    loop3
    decfsz cnt
    goto loop3
    decfsz cnt1
    goto loop3
    goto overcrntloop

    laboringloop
    bsf BC337
    bsf LED3 ; put Red LED on
    movlw 0xFF
    movwf cnt
    movwf cnt1
    loop4
    decfsz cnt
    goto loop4
    decfsz cnt1
    goto loop4
    bcf LED3 ; switch Red LED off
    movlw 0xFF
    movwf cnt
    movwf cnt1
    loop5
    decfsz cnt
    goto loop5
    decfsz cnt1
    goto loop5
    goto laboringloop

    SetAN0
    movlw B'00010000'
    movwf ADCON1
    movlw B'10101001' ; right justified, 10 TAD, FOSC/8
    movwf ADCON2
    movlw B'00000100'
    movwf ADCON3
    movlw B'00000000'
    movwf ADCHS
    movlw B'00000011'
    movwf ANSEL0 ; ensure AN0,1,2 ADC input is analogue
    movlw B'00010001'
    movwf ADCON0
    bsf ADCON0,GO ; start ADC
    return
    END
     
Loading...
Forum posts represent the experience, opinion, and view of individual users. Boat Design Net does not necessarily endorse nor share the view of each individual post.
When making potentially dangerous or financial decisions, always employ and consult appropriate professionals. Your circumstances or experience may be different.