The CITROEN Saxo Vehicle Touch Sensitive switches For operating Hazards and two peripheral devices If you want to change the look of your dash board inside a vehicle, maybe just fancy some of modern electronics This could be the design for you
Faced with a challenge last year a young lad came and spoke to me re his vehicle
Of course the challenge was obviously to fit a car stereo and car amplifier but also to illuminate the rear shelf which held his speakers create some under car vehicle lighting , different colors of course and do away with the Hazard light switch such that he had touch sensitive switches to operate Relays
The task had to achieve the following
A: Switch the hazards lights on
B: use switches to ether switch under car lighting on in the form of LED’s and operate the rear Led’s independently
C: If the hazards were on they would flash at regular intervals keeping the front led’s on or the rear led’s on or both
D: Single touch to turn on visa versa to turn off
Nice easy Microchip to develop small applications for anybody that might be interested a good start to Micro Processors, wanting to learn how to handle interrupts and deal with sensing switches as well as Timer interrupts
The circuits comprises A power supply derived from the 13.8 volt Battery of the vehicle A cpu which uses port A as inputs which rely purely on the fact that our body potential is higher thanthat of ground potential i.e Zero volts combined with fet characteristics of PORTA
An output side comprising PORTB which is connected to relay’s 1 to 4 via npn transistors , pulling the relay’s in
Protection to the input i.e PORT A is set to 5V6 this ensures that any static voltages are suppressed and protects PORT A from spikes D1 to D4, D11Ignition sense is sensed on Porta RA4.
This ensures that we cant turn on the relays except the hazard lights which must be operable even when the car ignition is off
The relay’s simply short out the links on the back of the hazard switch which has been removed
See Diagram in PDF File for explanation
D9 to D13 provide back EMF protection for the transistors Q1 to Q 4 of the relay drive circuitry
R1 to R4 , R17 ensure that PORTA is held at Zero potential when switches are not being touched
D20 ensures reverse polarity protection as does D23 on the 5volt regulator for the cpu which comprises Q5 , R13, D18
D14 to D17 provide luminous indication that a switch has been activated, current limited through the led’s via R9,R10,R11,R12
D5 to D8 ensure that should the transistors break down that we don’t end up destroying PORTB in the case of Collector, Base short circuit fault symptoms
R5 to R8 ensure that we limit the base current to Q1 to Q4
D21 and R15 ensure only 5 volts to PORTA, RA4, which forms the ignition sense line
Finally D24 flashes in accordance with the normal hazard light indicator
Explanation of interrupts and code
An interrupt is an unscheduled input, which interrupts the normal flow of a program, causing it to temporarily suspend what it is doing and perform a specified sequence of instructions required by the interrupting agent before returning to its original point in the program
An interrupt is a signal originating in peripherals
In PIC microcontrollers, these peripherals need not necessarily be external devices, although they usually are,
In the PIC16F84A these interrupts are as follows
A rising or falling voltage pulse on pin RB0 / INT41
2. A change in one or more of the voltage levels on the group of pins RB4 to RB7
3. An overflow of the timer registers TMR0 from 0xFF to 0×0 Decimal 255
4. A ‘write complete’ signal generated when writing to the EEPROM is complete
There are four interrupt flags, namely TOIF, INTF, RBIF and EEIF which are bits in the INTCON register and are set whenever that particular interrupt triggers, irrespective of whether it has been enabled by setting its corresponding enable flag.
The interrupt enable flags are TOIE,INTE, RBIE and EEIE
When an interrupt occurs, the processor immediately pushes the return address onto the stack, branches to the interrupt vector at address 0×4 in program memory and starts executing the code at that address. The sequence of instructions executed is called the interrupt service routine.
When the system is switched on, the program begins at the reset vector address hex 0×00
We enable the interrupts through the intcon register. This is one many of what we call special function registers inside the CPU
The SFR or Special function registers are responsible for setting the ports direction
In other words whether its input or output
Other SFR’s deal with the timer register which overflows every 256 clock count inside the CPU
Looking at the code we can now see what “ON_INTERRUPT GoTo INTPROC” does
This should now begin to make the subject a little clearer
When the timer overflows execution of code at the interrupt vector begins i.e hex 0×04
‘ *********** Interrupt Procedure starts here ******************
INTPROC: ‘ Handles the interrupt procedure routine
GIE = 0 ‘ disable the interrupt until interrupt complete
T0IE = 0 ‘ disable Timer interrupt reason we dont want the interrupt service routine to interrupt again whilst executing this code
‘ * method for TMR0 starts here ‘
T0IF = 0 ‘ Clear the TMR0 overflow flag we clear the falgs so as to reset
TMR0 = 0 ‘ Clear TMR0 initially
If CLOCKTICKS = 15 Then
Toggle HZLED
CLOCKTICKS = 0
End If
If CLOCKTICKS < 20 Then
CLOCKTICKS = CLOCKTICKS + 1
End If
GIE = 1 ‘ re enable the interrupt flag
T0IE = 1 ‘ enable Timer interrupt
TMR0 = 62 ‘ reload the timer to interrupt 20 times per second
Context Restore
The above will restore the address where the code last executed before the interrupt occurred in our case for the hazard lights timing to turn the hazard indicator on and off.
This is the interrupt service routine
Initially we don’t deal with any interrupts occurring, So at hex 0X00 we start the program by calling procedure which is defined by a line label
This is equivalent to a jump to address instruction Line labeled OVERINT:Code execution start here and we set up ports timers different types of input and we ensure that we don’t have any interrupts enable until a particular switch on the micro is activated requesting Hazard Lights on
After Jumping to Address OVERINT: we call another sub procedure with a JUMP too Instruction labeled INITCPU:
Here is the INIT CPU Code
INITCPU:
ALL_DIGITAL = True
Clear
Clear INTCON
Clear PORTB ‘ make sure no output on port b
Clear PORTA ‘ make sure no output on port a
TRISA = $1F ‘ make all port a input
TRISB = $81 ‘ make portb output except bits 0 and 7
T0IF = 0 ‘ clear the timer interrupt flag
‘ 15 times per second pre-scaler setting
PS0 = 1
PS1 = 1
PS2 = 1
PSA = 0
T0CS = 0 ‘set the clock source for internal oscillator
GIE = 0 ‘ disable interrupts
T0IE = 0 ‘ clear Timer interrupt
Return
In this procedure we set up the ports direction The Pre-scaler and then finally we clear all the ports down so that we don’t land up with false values and clear all the Interrupt Flags which let us know that an Interrupt has occurred
Analogy
Imagine your self in a lecture hall with the CPU being the lecturer , the pupils being the interrupt flags as a student raises his / her hand The lecturer being the CPU stops execution of what he is saying and deals with the students question after answer in the student, “The interrupt service routine “ The student clears the Flag “Lowering of hand “ and a returns control back to the Main Class i.e. the lecturer recommences from where he left off “
We could call this the Main method
The Main Method we could analogise as the lecturer asking the Class to work in groups and discuss the topic further, each student being a button press
This would equate to one of his colleagues answering the concern or interaction equivalent to Hardware interaction within his / her group
If the question needs to go back to the lecturer a interrupt flag is enabled in our case a timer interrupt enablement and the lecturer re iterates his/ her service routine with the last event having occurred , stores that address and then returns to that address for the class to continue from where they left off
This should make this a lot easier for you to understand as to what’s happening in the code
The rest of the code should be self explanatory I have commented the code in full for you and also included the Drill Plots , Code in Hex and of course the code / circuits pcb layout , Gerber plots etc for you to download plus of course the Proteus design files in pdf as well as the circuit
I hope you will find this a very interesting project not only for your car but also from a standpoint of what I hope will help you further to understand Pic Micro devices and interrupts
Have fun I hope you’ve enjoyed reading about this and maybe even making this yourselves
The projects has been fully tested All the printed circuit bourds are made and assembled by hand
Mark
http:// http://www.harrington.force9.co.uk
| File Name | File Size |
|---|---|
| PCB Layout | 540.56 KB |
| Circuit design in PDF Format | 75.6 KB |
| Proteus design files PCB | 58.29 KB |
| Proteus design files Circuit | 113.56 KB |
| Bill Of matarials | 29.08 KB |
| PIC Basic code | 6.76 KB |
| Hex File for the 16F84A | 1.46 KB |
| ASM File for Code | 9.61 KB |
| Cadcam , gerber plot files | 43.99 KB |
Wire-to-board interconnection options from Sullins feature a wide range of sizes and applications
MCC’s TVS series high-power suppressors protect sensitive components from voltage spikes and transients
Evaluation boards that streamline evaluating circuit protection on RS-485 serial device ports
There are currently no comments.