High priority/low priority program parts


Closed Thread
Results 1 to 21 of 21

Hybrid View

  1. #1
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: High priority/low priority program parts

    ON INTERRUPT works just fine, especially when you are only using one interrupt. For multiple INTERRUPTs, your ISR does nothing more than filter through possible Flags & sends the code where it needs to go.

    Not sure what all you're controlling, but HPWM can control your coolant fan, with temperature thresholds for duty cycle. Reading the analog port only takes maximum 50 uS (microseconds). If no change in temperature, no change to the HPWM DC%. As for fuel pump Duty Cycle%, what are you using to determine your needs? I would use either a pressure sensor (some of the newer vehicles have them built into the fuel rail) with a MAP where you are maintaining a constant absolute pressure, or perhaps just TPS. Absolute pressure is way more accurate and would be less likely to cause a lean condition at WOT.

    May I suggest using something like a PIC18F46K22. It is a 40-pin device. You have an entire PORTB to control your LCD, it has plenty of analog channels, plus it has 5 CCP/PWM modules. Use one Analog port for your ECT, one for MAP, one for Fuel Pressure, and perhaps one for TPS. Controlling the fan is rather simple using SELECT CASE CTS
    CASE IS < 90 : HPWM 1, 0, 1000
    CASE IS < 100 : HPWM 1, 127, 1000
    CASE ELSE : HPWM 1, 200, 1000
    END SELECT

    For fuel pressure & MAP you'll need to find what voltages equate to what pressures. If turbo, you're probably using at least a 2-BAR MAP. With a 5 volt VREF, anything above 2.5 volts and you have boost. You probably need about 2.4 BAR of fuel pressure.
    Duty VAR BYTE
    IF (Fuel_Value) < (MAP) THEN
    Duty = Duty + 1
    HPWM 2, DUTY, 1000
    ENDIF

    Of course this is rather simplified as you need to do the conversions before comparing.

    If you can get by with 28 pins, the PIC18F26K22 is the same basic MCU but with fewer pins.

  2. #2
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Re: High priority/low priority program parts

    Hello mpgmike,

    you are totally right. Problem is: I already made the PCB for this double-PIC Project and it works halfways.
    If I had to begib new i would take your advice and get the 18F26k22. Maybe I got some liying around.
    I bought 18F45K... for a projekt Henrik supports me but this device is too big in pin-through case form. Its HUUUGE
    compared to a 18F1320 in SMD which I have.
    It took me days to develop the PCB and manufacture it and I think optimizing the program is way less work
    than starting new.Next thing is : I try the HSEROUT/HSERIN thingy and watch if the cycle gets faster.
    I don´t have as much leisure time as I would like to.

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: High priority/low priority program parts

    HSERIN/HSEROUT won't make any difference on it's/their own.

    You need to look at the system level. Why is this code taking up to 300ms to execute? Because it sits here waiting for data for 300ms Before continuing (if no data arrives). So, the next question then is what is the F88 doing and how often does it actually SEND data?

    And again, think about implementing some handshaking or polling scheme.

    /Henrik.

  4. #4
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Re: High priority/low priority program parts

    hello Henrik,
    I thought HSERIN/HSEROUT would automatcally take care of the handshake. In the background.

    On the other hand i could put some more debug commands into the 16F88 code so that it has for example

    3 Debug commands between the main program lines. That should translate to 3 times sending the same which
    translates to less waiting of the 18F1320 to get what it wants.It doesn´t matter that this will slow down the 16F88, it has the slow task.

    Haha! Thats the total primitive method. I guess you will call it "Flintstone style programming".

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: High priority/low priority program parts

    No, HSERIN/HSEROUT does not do handshaking automatically, in the background.
    The UART in the PIC can receive one byte/character (and almost a second full byte/character) without the code doing anything but when that byte/character is received the code must fetch the byte from the receive buffer. This is where interrupts come in but you you were quite clear you didn't want to go that route - and frankly, it should not be needed for this.

    And again, using HSERIN with a WAIT statement in place of DEBUGIN will gain you pretty much nothing.

    Can you post the '88 code for us to take a look at, I'm sure you'll get plenty of suggestions on how to improve it.

    /Henrik.

  6. #6
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Re: High priority/low priority program parts

    Hello Henrik,
    thank you for your suggestion
    here:

    '************************************************* ***************
    '* Name : PUMP16F88V1 *
    '* Test with 20-23 °C RB0 = HPWM out *
    '* Author : M.David *
    '* Notice : Copyright (c) 2018 *
    '* : All Rights Reserved *
    '* Date : 01.01.2018 *
    '* Version : AB sensor M12x1,5 *
    '* Notes : 16F88 kein LCD funktioniert halbwegs *
    '* : PORTA.0 analog IN 0-2V channel 0 *
    '* PORTB.1 Fan out PPORTB.0 Water pump out *
    '************************************************* ***************

    #CONFIG
    __config _CONFIG1,_EXTCLK & _WDT_ON & _LVP_OFF & _CP_OFF
    #ENDCONFIG
    Define OSC 20
    TRISB = %00000000

    Define ADC_BITS 8 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uSec
    DEFINE DEBUG_REG PORTB
    DEFINE DEBUG_BIT 2
    DEFINE DEBUG_BAUD 19200
    DEFINE DEBUG_MODE 0
    DEFINE DEBUG_PACING 500

    define CCP1_REG PORTB 'für HPWM
    DEFINE CCP1_bit 0 'HPWM port B.0


    TRISA = %11111111 ' Set PORTA to all input
    ADCON1 = %00000010 ' Set PORTA analo
    CMCON = 7 ' Disable analog comparator
    ANSEL = %00000001 ' set AN0 (RA0) as analog, others to digital




    FAN VAR PORTB.1
    Uin VAR Word
    Temp Var word
    speed var word
    Pump var word
    RX var word
    RS var word
    B0 var word

    Speed = 0
    FAN = 0
    pause 1000
    DEBUG 10,13

    main:

    ADCIN 0,Uin ' Read channel 0 (RA)

    DEBUG "*.*",DEC3 RX,dec3 RS,dec1 FAN,13,10 ' dec3 is important
    DEBUG 10,13
    HPWM 1,speed,2442

    IF Uin => 64 then
    B0 = Uin/2
    Temp = 100-B0
    else
    Temp = 131 - Uin
    endif
    TEMP = Temp-5 ;Korrekturfaktor nach Kalibrierung Anzeige ok bei 75-90°C


    RX = TEMP
    RS = pump


    Select Case temp
    Case is < 67
    speed = 0
    pump = 0
    case 68, 69, 70, 71, 72
    speed = 8
    pump = 3
    case 73, 74
    speed = 16
    pump = 6
    case 75, 76
    speed = 32
    pump = 12
    case 77, 78
    speed = 64
    pump = 25
    case 79, 80
    speed = 124
    pump = 50
    case 81,82
    pump = 75
    Speed = 191
    case is > 80
    speed = 255
    pump = 100
    End Select

    IF (Temp <= 84 ) then
    FAN = 0
    else
    FAN = 1
    endif

    goto main

    END ' End of program

  7. #7
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Re: High priority/low priority program parts

    Here three pics of that housing and so on:Name:  Pumpcontroller1.png
Views: 1254
Size:  735.0 KBName:  Pumpcontroller2.png
Views: 1235
Size:  700.4 KBName:  Pumpcontroller3.png
Views: 1254
Size:  762.8 KB

Similar Threads

  1. DT lOW PRIORITY INTERRUPTS - ASM WARNING
    By longpole001 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 6th September 2014, 01:56
  2. Programme Flow Priority ?
    By gunayburak in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 10th August 2014, 00:20
  3. Replies: 4
    Last Post: - 24th January 2014, 20:38
  4. Priority interrupt?
    By Qacer in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 6th October 2006, 17:47
  5. Can you give varied levels of priority to blocks of code?
    By Archangel in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th August 2006, 02:58

Members who have read this thread : 0

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