High priority/low priority program parts


Closed Thread
Results 1 to 21 of 21

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: High priority/low priority program parts

    Since you have a WAIT state in the DEBUGIN statement that part of the code will take as many millesconds or years it takes for that "*" to arrive - simple as that.

    You have lot of nice peripherals available to you, why not make use of them?
    Use the UART for communication and a timer to count the pulses for you.

    Also, each time you update the dutycycle using the HPWM command you'll get a small "glitch" in the waveform (due to the fact that HPWM completely reconfigures the CCP module each time). You're better off just writing to the dutycycle register(s) directly.

    /Henrik.

  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 Henrik,
    the HPWM glitch doesn´t matter because its driving an electric fuel pump.
    I read the UART section in the old PBP handbook and it says: "very complicated" which is a nogo for me .
    When i remember right I may use the HSERIN/HSEROUT command? Is that the USART thing?
    Can I let go of the "wait" statement when using HSERIN/HSEROUT?
    And using a timer to count....thanks for the advice that looks like a dive into assembler which causes freezing my neurons.

    Regards

  3. #3
    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,

    for your entertainment a picture that shows some of these clunky metal chunks that are at the center of my profession. Just imagine the mental distance between bringing these chunks back to life for more than 20 years and programming assembler.Yes, its difficult to teach an old dog new tricks.Name:  old metal.jpg
Views: 1332
Size:  176.6 KB
    Attached Images Attached Images  

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: High priority/low priority program parts

    Hi,
    > the HPWM glitch doesn´t matter because its driving an electric fuel pump.
    OK, no problem with that then.

    > I read the UART section in the old PBP handbook and it says: "very complicated" which is a nogo for me .
    If you say so.

    > When i remember right I may use the HSERIN/HSEROUT command? Is that the USART thing?
    Yes, HSERIN/HSEROUT is using the USART peripheral in the PIC instead of bitbanging.

    > Can I let go of the "wait" statement when using HSERIN/HSEROUT?
    Depends on how you go about doing the "whole thing". You can use the USART to receive characters in the background using interrupts but I suspect you don't want to go that route either.

    > And using a timer to count....thanks for the advice that looks like a dive into assembler which causes freezing my neurons.
    No need for any assembly language. Look at the Timer n section of the datasheet and you'll see how you can configure it as a counter.

    Here's an idea:
    Read up on how to use a timer as a counter and get that going.
    Write your LCDOUT and housekeeping code in such a way that always takes the same amount of time, like 50ms
    Use that time as the timebase for your counter.
    Instead of sitting around waiting for the other PIC to send data use a handshaking or polling scheme so that you'll get the data when you're ready for it. This might obviously "push" the timing problem over to the other PIC but I don't know enough about your system to say. Even so I'm guessing it would be easier to it all in one PIC.

    Cars are way to messy, greasy and complicated for me. I enjoy driving them but mostly it's just means of transportation for me and I absolutely hate fixing, servicing and messing around with them. It's a good thing we're not all alike :-)

  5. #5
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: High priority/low priority program parts

    Mugelpower, I would also like to help so, if you could please explain the whole project overview. Why do you need 2 processors?
    Dave Purola,
    N8NTA
    EN82fn

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


    Did you find this post helpful? Yes | No

    Default Re: High priority/low priority program parts

    Unlike Henrik, I happen to LOVE autos. What I would suggest is to set your UART Special Function Registers, add the DEFINEs in your header, and use the HSERIN/OUT commands for your serial communications. This puts communications things in the background. When working with LCDs I like to use a PORT for data when I can afford the MCU pins; this means PORTx is dedicated to LCD communication. Setting a PORT to a variable value only takes one instruction cycle. ENABLE = 1 takes one instruction cycle. How long you hold ENABLE High (I use 8 uS) may interfere with other activities.

    I suggest you prioritize your activities, use INTERRUPTs for the highest priorities, then use normal lines of code for things like the LCD, you should be good. Like Henrik said, you can also calculate how long it takes for various functions (like LCDOUT) and place them in your code so they don't interfere with other functions. I experienced something where using interrupts the processor would occasionally go into an unexpected RESET. I created a bit variable and cleared it in the normal code and set it in the Interrupt Routine. The Main loop would DO/LOOP WHILE until the Interrupt Routine did its thing and cleared that bit. The Main Loop would then set the bit, do other things, then DO/LOOP until it got the clear bit. You might try throttling (gating) your Main loop to correspond with your ISR.

  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

    Hello mpgmike,

    thanks for your offer.

    I decided to use two PICs because I´m too dumb to program everything correct to do the project with one PIC.
    Reason is I began setting footsteps into the PIC world about 10 years ago,"developed" a small singlesided one PIC16F88
    board and ordered about 30 of them from a PCB Professional. Now I had a small board to use for simple tasks
    like controlling an electric waterpump and switching a cooling fan and showing Temperature and pump load on an LCD.The code was primitive AND very slow, the PIC ran on 4 MHz but for temperature control it was ok. Was lucky with that then.
    Paused several years and began a project for one of the cars of my wife with a controller that added an electric fuel
    pump. Now problems began because I needed two HPWM outputs.Not possible with a 16F88. I had some simple thingys worked out with a 18F1320 and at the time I had established the right configs (with the help of this community) I wiped the sweat off my forehead and could do the same the 16F88 could but way faster.
    Serial communication didn´t work because of a problem in my homecomputer setup. Strange thing because I posted
    forum threads 8-10 years ago that showed serial com worked but now without changing the homecomputer or the software it didn´t anymore.
    So I purchased PBP3 Gold two month ago , set it up on my notebook and voila, serial com between PICs worked again.
    I decided to take two PICs , one for the slower Temperature control (16F88) and one 18F1320 for the faster fuel pump
    control. I dont want to run the fuel pump full load all the time because it draws more than 20 Amps.And it costs more than 300$ so I want to save it. Minimum load (plus a reserve) at engine idle and quick response to raising engine speed. Nowadays the cool guys control these pumps via a digital fuel pressure controller that sends a signal about the amount of return fuel, but these units cost about 500 $ and need a controller too (300$).
    With two PICs I can use my simple code concentrating on the single task , only the 18F1320 has to run the LCD too.
    HA! the "professional" pump controllers use LEDs and no LCD.
    here an example for a waterpump controller:

    https://www.tecomotive.com/en/products/tinycwa.html

    I use a "huge" billet aluminium case, a LCD and military style connectors capable of 40 AMPS.

    My problem: the communication of these two PICs and the LCD routine are slowing the 18F1320 down to
    uselessness.One mainprogram cycle may take 0.3 seconds. that 3 times more than the acceptable limit.
    Because when the engine revs up the fuel pump has to rev up too.Fast.otherwise the egine will bog.
    With Henriks help we have pinned it down the problem that the 18F1320 has to wait for the 16F88 to send
    a Character. The 16F88 has a slow routine wich slows down the 18F as well.
    So the communication between both shouldn´t disturb the 18Fs main routine. Now I have to separate
    the "count/HPWM" main routine from the "get charakters and show on LCD" routine. because the LCD routine
    can take a whole second or some more, that doesn´t matter.
    I appreciate your help.
    Next point: I´m somewhat happy getting the serial com between both pics running......old fart thing sort of.

  8. #8
    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

    can I use "on interrupt" or do I have to use DT´s interrupts?

    I hoped PBP3 Gold had swallowed up these advantage.

  9. #9
    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.

Similar Threads

  1. DT lOW PRIORITY INTERRUPTS - ASM WARNING
    By longpole001 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 6th September 2014, 00:56
  2. Programme Flow Priority ?
    By gunayburak in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 9th August 2014, 23:20
  3. Replies: 4
    Last Post: - 24th January 2014, 19:38
  4. Priority interrupt?
    By Qacer in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 6th October 2006, 16: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, 01: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