Driver to control a peripheral circuit being controlled by the operation of a FET. Inbetween the mbed and FET is a single D type latch, used to latch a signal to the driver.

Committer:
sk398
Date:
Sat Feb 20 13:22:50 2016 +0000
Revision:
5:7d1b124490ed
Parent:
4:6b3722251fd7
Child:
6:073ee2fd1245
Child:
7:909d7e3822d8
Commented and operational

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sk398 0:87f2d094bea3 1 #include "mbed.h"
sk398 0:87f2d094bea3 2 #include "Latch_FET_Driver.h"
sk398 0:87f2d094bea3 3
sk398 5:7d1b124490ed 4
sk398 5:7d1b124490ed 5 /* =============================================================
sk398 5:7d1b124490ed 6 Latch_FET_Driver constructor
sk398 5:7d1b124490ed 7
sk398 5:7d1b124490ed 8 Inputs
sk398 5:7d1b124490ed 9 ------
sk398 5:7d1b124490ed 10 PinName D: Pin to create D input to D Latch
sk398 5:7d1b124490ed 11 PinName CLK: Pin to create CLK input to D Latch
sk398 5:7d1b124490ed 12
sk398 5:7d1b124490ed 13 Description
sk398 5:7d1b124490ed 14 -----------
sk398 5:7d1b124490ed 15
sk398 5:7d1b124490ed 16 Once the new DigitalOut types are assigned, the D Latch at
sk398 5:7d1b124490ed 17 the given Pins is initialised to an outputLow state, ensuring
sk398 5:7d1b124490ed 18 that uopn setup, a known state is entered quickly.
sk398 5:7d1b124490ed 19
sk398 5:7d1b124490ed 20 ============================================================= */
sk398 5:7d1b124490ed 21 Latch_FET_Driver::Latch_FET_Driver(PinName D,PinName CLK)
sk398 0:87f2d094bea3 22 {
sk398 5:7d1b124490ed 23 // Assign passed in Pin Names as new DigitalOut data types
sk398 5:7d1b124490ed 24 _D = new DigitalOut(D);
sk398 5:7d1b124490ed 25 _CLK = new DigitalOut(CLK);
sk398 5:7d1b124490ed 26
sk398 5:7d1b124490ed 27 // Ensure that D latch does not enter unknown state
sk398 5:7d1b124490ed 28 // Initialise is the same as the outputLow method
sk398 5:7d1b124490ed 29 Latch_FET_Driver::outputLow();
sk398 0:87f2d094bea3 30 }
sk398 0:87f2d094bea3 31
sk398 5:7d1b124490ed 32 /* ================================================================
sk398 5:7d1b124490ed 33 outputHigh is a public method to set a HIGH output on the given
sk398 5:7d1b124490ed 34 D Latch.
sk398 5:7d1b124490ed 35
sk398 5:7d1b124490ed 36 The procedure to set Q into a HIGH condition is as follows;
sk398 5:7d1b124490ed 37
sk398 5:7d1b124490ed 38 1. Ensure CLK is low
sk398 5:7d1b124490ed 39 2. Set D high
sk398 5:7d1b124490ed 40 3. wait STATE_DELAY us
sk398 5:7d1b124490ed 41 4. Set CLK high
sk398 5:7d1b124490ed 42 5. wait 10*STATE_DELAY us
sk398 5:7d1b124490ed 43 6. Set CLK low
sk398 5:7d1b124490ed 44 7. wait STATE_DELAY us
sk398 5:7d1b124490ed 45 8. set D low
sk398 5:7d1b124490ed 46 9. return void
sk398 5:7d1b124490ed 47 ================================================================ */
sk398 5:7d1b124490ed 48 void Latch_FET_Driver::outputHigh()
sk398 0:87f2d094bea3 49 {
sk398 5:7d1b124490ed 50 _CLK -> write(LOW);
sk398 5:7d1b124490ed 51 _D -> write(HIGH);
sk398 5:7d1b124490ed 52 wait_us(STATE_DELAY);
sk398 5:7d1b124490ed 53 _CLK -> write(HIGH);
sk398 5:7d1b124490ed 54 wait_us(10*STATE_DELAY);
sk398 5:7d1b124490ed 55 _CLK -> write(LOW);
sk398 5:7d1b124490ed 56 wait_us(STATE_DELAY);
sk398 5:7d1b124490ed 57 _D -> write(LOW);
sk398 0:87f2d094bea3 58 }
sk398 0:87f2d094bea3 59
sk398 5:7d1b124490ed 60 /* ================================================================
sk398 5:7d1b124490ed 61 outputLow is a public method to set a HIGH output on the given
sk398 5:7d1b124490ed 62 D Latch.
sk398 5:7d1b124490ed 63
sk398 5:7d1b124490ed 64 The procedure to set Q into a LOW condition is as follows;
sk398 5:7d1b124490ed 65
sk398 5:7d1b124490ed 66 1. Ensure CLK is low
sk398 5:7d1b124490ed 67 2. Set D low
sk398 5:7d1b124490ed 68 3. wait STATE_DELAY us
sk398 5:7d1b124490ed 69 4. Set CLK high
sk398 5:7d1b124490ed 70 5. wait 10*STATE_DELAY us
sk398 5:7d1b124490ed 71 6. Set CLK low
sk398 5:7d1b124490ed 72 7. wait STATE_DELAY us
sk398 5:7d1b124490ed 73 8. return void
sk398 5:7d1b124490ed 74 ================================================================ */
sk398 5:7d1b124490ed 75 void Latch_FET_Driver::outputLow()
sk398 5:7d1b124490ed 76 {
sk398 5:7d1b124490ed 77 _CLK -> write(LOW);
sk398 5:7d1b124490ed 78 _D -> write(LOW);
sk398 5:7d1b124490ed 79 wait_us(STATE_DELAY);
sk398 5:7d1b124490ed 80 _CLK -> write(HIGH);
sk398 5:7d1b124490ed 81 wait_us(10*STATE_DELAY);
sk398 5:7d1b124490ed 82 _CLK -> write(LOW);
sk398 5:7d1b124490ed 83 wait_us(STATE_DELAY);
sk398 5:7d1b124490ed 84 }
sk398 2:9059b675917e 85
sk398 5:7d1b124490ed 86