PIC18F458 (main and ISR flowchart)

Thread Starter

xiandra park

Joined Jul 26, 2018
9
Can someone help me to come out with a main program and ISR flowchart of this circuit below (pic18f458), it is about a car system, with start engine, stop engine, lock door, unlock door and alarm (following sequence - basic steps to get into a car: unlock the door, start engine, lock the door... etc). Just a simple flowchart, without ADC and USART. Just use 1.5s delay and TIMER0

Input (Switches):

START -------> RB0/INT0
STOP -------> RB1/INT1
LOCK -------> RB2/INT2/CANTX
UNLOCK -----> RB3/CANRX
ALARM -------> RB4

Output:

RC0 -----> START1 (LED-YELLOW)
RC1 -----> STOP1 (LED-YELLOW)
RC2 -----> LOCK1 (LED-YELLOW)
RC3 -----> UNLOCK1 (LED-YELLOW)
RC4 -----> ALARM1 (LED-YELLOW)
 
Last edited:

JohnInTX

Joined Jun 26, 2012
4,787
You need to approach the project differently. You are getting into the hardware (like interrupts) way too early. There are two things to consider, planning and implementation.

---------------
Planning:
Think about the big picture first - the step by step sequence needed to do what you want. Identify each step. What does each step do? What inputs got you to that step and what actions get you to the next step. Don't worry about how things are done, just assume you can do them. Figure out the logic first. Consider that rather than a firm sequence, you might want to identify each step in the process as a STATE - a unique condition that the system can be in with well defined entry and exit conditions.

In a state diagram, each state that the system can be in is represented by a circle. Inside the circle is the name of the state and/or the conditions that describe it. There is a always a loop that describes the conditions that will cause the system to stay in the state. For each of these conditions there is an arrow (called an 'edge') that tells where the system will go when one of the conditions changes and it enters a new state.

Attached (Start Car State Diagram.pdf) is a sample state diagram that addresses your needs but still has some issues. But note how it is constructed. Each state shows exactly ONE condition that the program can be in, how it got there and how it goes to something else. The dashed line is an example of an incomplete diagram and indicates more design work is necessary:
What happens if the engine is running and the doors are locked? You would have to take care of each combination of engine, doors, transmission settings etc. to make a good vehicle controller. Print the diagram and try to fill in the missing stuff - what happens if the doors are locked while in DRIVE? Hmmm.. Think about that. What do the doors have to do with the engine running or not? How would you handle that? Hint: more than one state diagram. See diagram #2.

In #2, the door functions have been split from the engine/transmission stuff - you can drive with the doors locked or unlocked, yes? The door logic uses the fact that the engine is running to know if the door was opened by the owner or not but that's all of the interaction.

So first step: understand the two state diagrams and why #2 is better than #1. Second, realize that your LED indicators are now attached to and indicate the state. Finally, at this point, realize that you haven't done any coding yet. This is how it's done.

--------------------
Implementation:
At his stage in the design, we don't really care how we know that a door is open or how to start the engine. That's not important at this stage but as preview of coming attractions I'll just say:
You DON'T sample input switches with an interrupt.
You DO use a timer interrupt to generate intervals that you use to sample the input switches and post the results so that the state machine(s) can just sample the switch status. That timer interrupt can also be uses to generate system delays, etc.

But for now, none of that is important. What IS important is to describe the design on paper and account for all of the ways it can go.

------------------------
That's how this stuff is done. At this stage in the process, we are designing the solution to a problem. It doesn't matter if you are using the PIC18F458 or crayons, the procedure is the same. Only when you have a working design on paper can you actually code it.

If you are on board with the approach, drill down into those diagrams, revise as necessary and we can go from there.

Have fun!
 

Attachments

Last edited:
Top