This code will read from both heaters every 2 seconds

Dependencies:   mbed Watchdog Heater MODSERIAL FastPWM ADS8568_ADC

Committer:
omatthews
Date:
Tue Aug 06 12:46:14 2019 +0000
Revision:
0:aaad1791753c
AD_Logging

Who changed what in which revision?

UserRevisionLine numberNew contents of line
omatthews 0:aaad1791753c 1 #include "mbed.h"
omatthews 0:aaad1791753c 2 #include "MODSERIAL.h"
omatthews 0:aaad1791753c 3 #include "Watchdog.h"
omatthews 0:aaad1791753c 4 #include "ADS8568_ADC.h"
omatthews 0:aaad1791753c 5 #include "Heater.h"
omatthews 0:aaad1791753c 6 #include "FastPWM.h"
omatthews 0:aaad1791753c 7
omatthews 0:aaad1791753c 8
omatthews 0:aaad1791753c 9 /*------------------------------------------------------------------------------
omatthews 0:aaad1791753c 10 Codebase for T99004 Demo Control Board Rev A Firmware
omatthews 0:aaad1791753c 11 Date: 10/07/2018
omatthews 0:aaad1791753c 12 Author: AS7
omatthews 0:aaad1791753c 13
omatthews 0:aaad1791753c 14
omatthews 0:aaad1791753c 15 ------------------------------------------------------------------------------*/
omatthews 0:aaad1791753c 16
omatthews 0:aaad1791753c 17 #define ALL_CH 15 //value of convst bus to read all chanels simultaneosly
omatthews 0:aaad1791753c 18
omatthews 0:aaad1791753c 19
omatthews 0:aaad1791753c 20 Watchdog wd; //instantiate watchdog class
omatthews 0:aaad1791753c 21
omatthews 0:aaad1791753c 22 MODSERIAL pc(PA_9, PA_10, 512); //mcu TX, RX, 512 byte TX and RX buffers
omatthews 0:aaad1791753c 23
omatthews 0:aaad1791753c 24 //ADC object inherits SPI,
omatthews 0:aaad1791753c 25 ADS8568_ADC adc(PB_15, PB_14, PB_13, PB_12, PC_15, PC_0, PC_1, PC_2, PC_3);
omatthews 0:aaad1791753c 26
omatthews 0:aaad1791753c 27 //SPI spi(PB_15, PB_14, PB_13); // mosi, miso, sclk
omatthews 0:aaad1791753c 28 I2C i2c(PB_7, PB_8); //SDA, SCL
omatthews 0:aaad1791753c 29
omatthews 0:aaad1791753c 30 //indicator LEDs
omatthews 0:aaad1791753c 31 DigitalOut hb_led(PC_13); //Green
omatthews 0:aaad1791753c 32 DigitalOut led_0(PC_4); //Red
omatthews 0:aaad1791753c 33 DigitalOut led_1(PC_5); //Green
omatthews 0:aaad1791753c 34
omatthews 0:aaad1791753c 35 //User buttons
omatthews 0:aaad1791753c 36 DigitalIn user_0(PB_0);
omatthews 0:aaad1791753c 37 DigitalIn user_1(PB_1);
omatthews 0:aaad1791753c 38
omatthews 0:aaad1791753c 39 //ADC
omatthews 0:aaad1791753c 40 //BusOut adc_convt(PC_0, PC_1, PC_2, PC_3); //channel convert ch_A, ch_B, ch_C, ch_D
omatthews 0:aaad1791753c 41 //DigitalOut adc_ncs(PB_12); //chip n_select
omatthews 0:aaad1791753c 42 DigitalIn adc_busy(PA_8); //Busy interrupt sig
omatthews 0:aaad1791753c 43 //DigitalOut adc_reset(PC_15);
omatthews 0:aaad1791753c 44
omatthews 0:aaad1791753c 45 /*ADC channels are connected as follows------------
omatthews 0:aaad1791753c 46 CH_A0 = Heater 1 Current Sense
omatthews 0:aaad1791753c 47 CH_A1 = Heater 1 Voltage Sense
omatthews 0:aaad1791753c 48 CH_B0 = Heater 2 Current Sense
omatthews 0:aaad1791753c 49 CH_B1 = Heater 2 Voltage Sense
omatthews 0:aaad1791753c 50 CH_C0 = Photodiode Amp Out 1
omatthews 0:aaad1791753c 51 CH_C1 = Photodiode Amp Out 2
omatthews 0:aaad1791753c 52 CH_D0 = Photodiode Amp Out 3
omatthews 0:aaad1791753c 53 CH_D1 = Photodiode Amp Out 4
omatthews 0:aaad1791753c 54 ---------------------------------------------------*/
omatthews 0:aaad1791753c 55
omatthews 0:aaad1791753c 56 //Heater Control
omatthews 0:aaad1791753c 57 FastPWM drive_1(PC_9);
omatthews 0:aaad1791753c 58 FastPWM drive_2(PC_8);
omatthews 0:aaad1791753c 59 FastPWM guard_1(PC_7);
omatthews 0:aaad1791753c 60 FastPWM guard_2(PC_6);
omatthews 0:aaad1791753c 61 Timer timer;
omatthews 0:aaad1791753c 62
omatthews 0:aaad1791753c 63
omatthews 0:aaad1791753c 64 //Global vars instatiation (to be moved to new places)
omatthews 0:aaad1791753c 65 char buffer16[16];
omatthews 0:aaad1791753c 66 float voltages[8];
omatthews 0:aaad1791753c 67 int values[8];
omatthews 0:aaad1791753c 68 int i = 0;
omatthews 0:aaad1791753c 69 int log_count = 0;
omatthews 0:aaad1791753c 70
omatthews 0:aaad1791753c 71 float cur1 = 0;
omatthews 0:aaad1791753c 72 float cur2 = 0;
omatthews 0:aaad1791753c 73 float R1 = 0;
omatthews 0:aaad1791753c 74 float R2 = 0;
omatthews 0:aaad1791753c 75 float scale_factors[8];
omatthews 0:aaad1791753c 76 float scale_factor = 13.273;
omatthews 0:aaad1791753c 77 int drivetime_ms = 0;
omatthews 0:aaad1791753c 78 int OSR = 1;
omatthews 0:aaad1791753c 79 float R_avg = 0;
omatthews 0:aaad1791753c 80
omatthews 0:aaad1791753c 81 char outString[100];
omatthews 0:aaad1791753c 82
omatthews 0:aaad1791753c 83 Heater heater_1(0,1,&drive_1, &guard_1, 291, -209);
omatthews 0:aaad1791753c 84 Heater heater_2(2,3,&drive_2, &guard_2, 286, -203);
omatthews 0:aaad1791753c 85
omatthews 0:aaad1791753c 86
omatthews 0:aaad1791753c 87 int main()
omatthews 0:aaad1791753c 88 {
omatthews 0:aaad1791753c 89 // Initialsation
omatthews 0:aaad1791753c 90
omatthews 0:aaad1791753c 91 //for (int i = 0; i<8; i++) {scale_factors[i] = 13.273;} //TODO tweak for each individual channel
omatthews 0:aaad1791753c 92 pc.baud(115200);
omatthews 0:aaad1791753c 93 //led_1 = drive_1; //tie led 1 and heater 1 outputs together so LED shows while heater is on (initial debug purposes only)
omatthews 0:aaad1791753c 94 //wd.Configure(30.0); //configure watchdog timer to 1s interval
omatthews 0:aaad1791753c 95 adc.init(); //initialise ADC
omatthews 0:aaad1791753c 96 timer.start(); //Start the timer
omatthews 0:aaad1791753c 97 drivetime_ms = 50;
omatthews 0:aaad1791753c 98
omatthews 0:aaad1791753c 99 //Initialise drive periods
omatthews 0:aaad1791753c 100 drive_1.period_us(PWM_PERIOD);
omatthews 0:aaad1791753c 101 drive_2.period_us(PWM_PERIOD);
omatthews 0:aaad1791753c 102 guard_1.period_us(PWM_PERIOD);
omatthews 0:aaad1791753c 103 guard_2.period_us(PWM_PERIOD);
omatthews 0:aaad1791753c 104
omatthews 0:aaad1791753c 105 //while(user_1 == 0);
omatthews 0:aaad1791753c 106
omatthews 0:aaad1791753c 107 //Body
omatthews 0:aaad1791753c 108
omatthews 0:aaad1791753c 109 //if (wd.WatchdogCausedReset())
omatthews 0:aaad1791753c 110 // pc.printf("Watchdog caused reset.\r\n");
omatthews 0:aaad1791753c 111
omatthews 0:aaad1791753c 112 while(1){
omatthews 0:aaad1791753c 113
omatthews 0:aaad1791753c 114 heater_1.read();
omatthews 0:aaad1791753c 115 heater_2.read();
omatthews 0:aaad1791753c 116 wait(2);
omatthews 0:aaad1791753c 117
omatthews 0:aaad1791753c 118 }
omatthews 0:aaad1791753c 119
omatthews 0:aaad1791753c 120
omatthews 0:aaad1791753c 121 }