Version for FZ420ZI

Fork of Task442 by University of Plymouth - Stages 1, 2 and 3

Committer:
noutram
Date:
Tue Feb 13 11:39:11 2018 +0000
Revision:
2:6c9c8dfe36e6
Parent:
0:44a74c1bc812
Child:
3:36ab439835c7
Updated for FZ429ZI

Who changed what in which revision?

UserRevisionLine numberNew contents of line
noutram 0:44a74c1bc812 1 #include "mbed.h"
noutram 0:44a74c1bc812 2
noutram 0:44a74c1bc812 3 //Function prototype
noutram 0:44a74c1bc812 4 void doSample1Hz();
noutram 0:44a74c1bc812 5
noutram 0:44a74c1bc812 6 //Global objects
noutram 0:44a74c1bc812 7 Serial pc(USBTX, USBRX);
noutram 0:44a74c1bc812 8 AnalogIn POT_ADC_In(A0);
noutram 2:6c9c8dfe36e6 9 DigitalOut led1(LED1);
noutram 2:6c9c8dfe36e6 10 DigitalOut led2(LED2);
noutram 0:44a74c1bc812 11
noutram 0:44a74c1bc812 12 //Shared variables
noutram 0:44a74c1bc812 13 volatile static unsigned short sample16 = 0;
noutram 0:44a74c1bc812 14
noutram 0:44a74c1bc812 15 //The ticker, used to sample data at a fixed rate
noutram 0:44a74c1bc812 16 Ticker t;
noutram 0:44a74c1bc812 17
noutram 0:44a74c1bc812 18 //Main function
noutram 0:44a74c1bc812 19 int main()
noutram 0:44a74c1bc812 20 {
noutram 0:44a74c1bc812 21 //Set baud rate to 115200
noutram 0:44a74c1bc812 22 pc.baud(115200);
noutram 0:44a74c1bc812 23
noutram 2:6c9c8dfe36e6 24 //Power on self test
noutram 2:6c9c8dfe36e6 25 led1 = 1; led2 = 1;
noutram 2:6c9c8dfe36e6 26 pc.printf("TESTING\n\r");
noutram 2:6c9c8dfe36e6 27 wait(1.0);
noutram 2:6c9c8dfe36e6 28 led1 = 1; led2 = 1;
noutram 2:6c9c8dfe36e6 29 pc.printf("DONE\n\r");
noutram 2:6c9c8dfe36e6 30 wait(1.0);
noutram 2:6c9c8dfe36e6 31
noutram 0:44a74c1bc812 32 //Set up the ticker - 100Hz
noutram 0:44a74c1bc812 33 t.attach(doSample1Hz, 1.0);
noutram 0:44a74c1bc812 34
noutram 0:44a74c1bc812 35 while(1) {
noutram 0:44a74c1bc812 36
noutram 0:44a74c1bc812 37 //Sleep
noutram 0:44a74c1bc812 38 sleep();
noutram 0:44a74c1bc812 39
noutram 2:6c9c8dfe36e6 40 //READ ADC as an unsigned integer.
noutram 2:6c9c8dfe36e6 41 //Shift right 4 bits (this is a 12bit ADC) & store in static global variable
noutram 2:6c9c8dfe36e6 42 sample16 = POT_ADC_In.read_u16() >> 4;
noutram 2:6c9c8dfe36e6 43
noutram 2:6c9c8dfe36e6 44 //Hardware debug to verify this is working
noutram 2:6c9c8dfe36e6 45 led2 = !led2;
noutram 2:6c9c8dfe36e6 46
noutram 0:44a74c1bc812 47 //Displauy the sample in HEX
noutram 0:44a74c1bc812 48 pc.printf("ADC Value: %X\n", sample16);
noutram 0:44a74c1bc812 49
noutram 0:44a74c1bc812 50 } //end while(1)
noutram 0:44a74c1bc812 51 } //end main
noutram 0:44a74c1bc812 52
noutram 0:44a74c1bc812 53 //ISR for the ticker - simply there to perform sampling
noutram 2:6c9c8dfe36e6 54 void doSample1Hz() {
noutram 0:44a74c1bc812 55 //Toggle on board led
noutram 2:6c9c8dfe36e6 56 led1 = !led1;
noutram 0:44a74c1bc812 57 }
noutram 0:44a74c1bc812 58