Lab 6 code.

Dependencies:   mbed

Fork of WaG by GroupA

Committer:
spm71
Date:
Fri Apr 06 18:25:19 2018 +0000
Revision:
56:048b30c9f2a1
Parent:
53:389fe53b2642
Final update

Who changed what in which revision?

UserRevisionLine numberNew contents of line
spm71 24:0691bfc946e9 1 /******************************************************************************
spm71 24:0691bfc946e9 2 * EECS 397
spm71 24:0691bfc946e9 3 *
spm71 24:0691bfc946e9 4 * Assignment Name: Lab 6: WaG
spm71 24:0691bfc946e9 5 *
spm71 24:0691bfc946e9 6 * Authors: Sam Morrison and Phong Nguyen
spm71 24:0691bfc946e9 7 * File name: analog.cpp
spm71 24:0691bfc946e9 8 * Purpose: Analog functions
spm71 24:0691bfc946e9 9 *
spm71 24:0691bfc946e9 10 * Created: 03/20/2018
spm71 24:0691bfc946e9 11 * Last Modified: 03/20/2018
spm71 24:0691bfc946e9 12 *
spm71 24:0691bfc946e9 13 ******************************************************************************/
spm71 24:0691bfc946e9 14
spm71 24:0691bfc946e9 15 #include "mbed.h"
spm71 24:0691bfc946e9 16 #include "io_pins.h"
spm71 24:0691bfc946e9 17 #include "utility.h"
spm71 34:378a49e5b15f 18 #include "analog.h"
spm71 43:3b7f326aa096 19 #include "laser.h"
spm71 43:3b7f326aa096 20 #include "stepper.h"
spm71 24:0691bfc946e9 21 #include <stdlib.h>
spm71 24:0691bfc946e9 22 #include <stdio.h>
spm71 24:0691bfc946e9 23 #include <string.h>
spm71 24:0691bfc946e9 24
phn10 26:3006f5abc0a5 25 extern BusOut mux_select;
phn10 31:4fe43fa66ce8 26 extern AnalogIn mux_out;
spm71 43:3b7f326aa096 27 extern DigitalIn cal_button;
spm71 43:3b7f326aa096 28 extern DigitalOut laser;
phn10 35:7b562e336a26 29 extern Serial pc;
spm71 46:85c4b722baa7 30 extern DigitalIn jog_ccw;
spm71 46:85c4b722baa7 31 extern DigitalIn jog_cw;
phn10 35:7b562e336a26 32 float phototransistor_array[MUX_CHANS];
phn10 26:3006f5abc0a5 33
spm71 24:0691bfc946e9 34 /*
spm71 24:0691bfc946e9 35 * void ana_init();
spm71 24:0691bfc946e9 36 * Description: sets mux select bits to zero
spm71 24:0691bfc946e9 37 *
spm71 24:0691bfc946e9 38 * Inputs:
spm71 24:0691bfc946e9 39 * Parameters:
spm71 24:0691bfc946e9 40 * Globals:
spm71 24:0691bfc946e9 41 *
spm71 24:0691bfc946e9 42 * Outputs:
spm71 24:0691bfc946e9 43 * Returns: void
spm71 24:0691bfc946e9 44 */
spm71 24:0691bfc946e9 45 void ana_init() {
phn10 26:3006f5abc0a5 46 mux_select = 0; // set all mux select bits to zeros
spm71 24:0691bfc946e9 47 }
spm71 24:0691bfc946e9 48
spm71 24:0691bfc946e9 49 /*
spm71 24:0691bfc946e9 50 * void ana_scan_mux(float * an_array, int no_of_channels);
spm71 24:0691bfc946e9 51 * Description: sets mux select bits to respective channels
spm71 24:0691bfc946e9 52 *
spm71 24:0691bfc946e9 53 * Inputs:
spm71 24:0691bfc946e9 54 * Parameters:
spm71 24:0691bfc946e9 55 * float * an_array: pointer to channel array
spm71 24:0691bfc946e9 56 * int no_of_channels: number of channels to cycle through
spm71 24:0691bfc946e9 57 * Globals:
spm71 24:0691bfc946e9 58 *
spm71 24:0691bfc946e9 59 * Outputs:
spm71 24:0691bfc946e9 60 * Returns: void
spm71 24:0691bfc946e9 61 */
spm71 24:0691bfc946e9 62 void ana_scan_mux(float * an_array, int no_of_channels) {
spm71 34:378a49e5b15f 63 for (int i = 0; i < no_of_channels; i++) {
phn10 40:4e82369f337c 64 mux_select = i;
phn10 31:4fe43fa66ce8 65 an_array[i] = mux_out.read();
phn10 31:4fe43fa66ce8 66 }
phn10 35:7b562e336a26 67 }
phn10 35:7b562e336a26 68
phn10 35:7b562e336a26 69 /*
phn10 35:7b562e336a26 70 * void test_phototransistors();
phn10 35:7b562e336a26 71 * Description: scan the value of phototransistors on WAG board
phn10 35:7b562e336a26 72 *
phn10 35:7b562e336a26 73 * Inputs:
phn10 35:7b562e336a26 74 * Parameters:
phn10 35:7b562e336a26 75 * Globals:
phn10 35:7b562e336a26 76 *
phn10 35:7b562e336a26 77 * Outputs:
phn10 35:7b562e336a26 78 * Returns: void
phn10 35:7b562e336a26 79 */
phn10 35:7b562e336a26 80 void test_phototransistors () {
phn10 35:7b562e336a26 81 // check for button pressed and released to start PT scan test
phn10 40:4e82369f337c 82 while (uti_chk_ubutton() == 0);
phn10 40:4e82369f337c 83 pc.printf("test begin\n");
spm71 50:e3a03bc1e1a6 84 stp_init();
phn10 40:4e82369f337c 85 while (uti_chk_ubutton() == 0) {
spm71 46:85c4b722baa7 86
spm71 50:e3a03bc1e1a6 87 if (jog_ccw == 0) {
spm71 50:e3a03bc1e1a6 88 stp_step(STP_CCW);
spm71 53:389fe53b2642 89 wait(0.01);
spm71 50:e3a03bc1e1a6 90 }
spm71 50:e3a03bc1e1a6 91 if (jog_cw == 0) {
spm71 50:e3a03bc1e1a6 92 stp_step(STP_CW);
spm71 53:389fe53b2642 93 wait(0.01);
spm71 50:e3a03bc1e1a6 94 }
spm71 46:85c4b722baa7 95
spm71 46:85c4b722baa7 96 if (cal_button.read() == 0) {
spm71 43:3b7f326aa096 97 if (laser == 0)
spm71 43:3b7f326aa096 98 lzr_on();
spm71 43:3b7f326aa096 99 else
spm71 43:3b7f326aa096 100 lzr_off();
spm71 43:3b7f326aa096 101 wait(0.02);
spm71 43:3b7f326aa096 102 }
spm71 46:85c4b722baa7 103
phn10 40:4e82369f337c 104 ana_scan_mux(phototransistor_array, MUX_CHANS);
phn10 40:4e82369f337c 105 for (int i = 0; i < MUX_CHANS; i++) {
phn10 40:4e82369f337c 106 pc.printf("%d: %.3f ", i, phototransistor_array[i] * 3.3f);
phn10 40:4e82369f337c 107 }
phn10 40:4e82369f337c 108 pc.printf("\e[1;1H\e[2J");
phn10 35:7b562e336a26 109 }
spm71 50:e3a03bc1e1a6 110 lzr_off();
spm71 24:0691bfc946e9 111 }