Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ad5422_arduino mbed LT1446 LM35 PGA280_ADS1259
Diff: main.cpp
- Revision:
- 0:98fcc06c66bf
- Child:
- 1:5d28312892aa
diff -r 000000000000 -r 98fcc06c66bf main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Mon Jun 08 05:50:32 2020 +0000
@@ -0,0 +1,108 @@
+#include "PerifConfig.h"
+#include "PGA280.h"
+#include "ADS1259.h"
+#include "PGA280ADS1259.h"
+#include "main.h"
+
+/*Таймер для вызова функции каждые 40 мс*/
+Ticker adctask;
+/*Конец*/
+
+char mbflag;
+unsigned char pga280gain;
+char UComandFlag;
+volatile unsigned char UComand;
+volatile long tempdata=0;
+char ch=0; //адрес на плате ТЭД-2 = 6
+float x=0;
+float k;
+unsigned char str[];
+
+
+
+//функция чтения АДС для выполнения в задаче
+void readADC()
+{
+ tempdata=ads1259_readData(5); //функция может зависать (надо избавиться от бесконечного цикла)
+ x=NormADC(tempdata);
+ printf("%08f\r\n",x);
+}
+
+
+float inline NormADC(long data)
+{
+ x=data*2.5/0x800000;
+ //x=x*8/(1<<pga280gain);
+ return x;
+}
+
+void ComandCheck()
+{
+ if(UART.getc()=='/')
+ {
+ UART_gets(16); //моя функция на время
+ UART.printf("%c\r\n",str[0]);
+ switch (str[0]){
+ case 'p':{
+ pga280gain=str[1]; //присваиваем числовое значение команды взятое из символа цифры
+ pga280gain-=0x30;
+ ch=5;
+ pga280_setGAIN(pga280gain,ch);
+ ch=0;
+ break;}
+ case 'g': {
+ //запустить задачу чтения АЦП каждые 40 мс (25 герц)
+ adctask.attach(&readADC,0.04);
+ break;}
+ case's': {
+ adctask.detach();
+ break;}
+ case 'd':
+ //MBFlagRegister.DAC=1;
+ break;
+ case 'e':{
+ tempdata=pga280_readOneRegisterDevice(PGA280_ERROR_ADR,5);//чтение ошибок
+ printf("ERRORS %X\n",tempdata);
+ break;}
+ case 'r':{
+ //перезагрука
+ printf("System Reset\r\n");
+ NVIC_SystemReset();
+ break;}
+ default:
+ //MBFlagRegister.TMLS=0; //починка зависания (не работает)
+ break;
+ }
+ }
+}
+
+int main()
+{
+ SPI1_MasterInitMode(0);
+
+ //запустить задачу проверки команды по прерыванию УАРТ
+ UART.attach(&ComandCheck,Serial::RxIrq);
+
+ EN1=1;
+ ch=5;
+ //pga280_setAdress(ch);
+ pga280_ads1259_init(ch); //инициализировать АЦП по адресу на плате ТЭД-2 = 5 (4)
+ printf("\r\n");
+ tempdata=pga280_readOneRegisterDevice(PGA280_BUF_TIMEOUT_ADR,ch);
+ printf("Timeout %X\n",tempdata);
+ wait_ms(20);
+ pga280_setGAIN(GAIN_1_PGA280,ch);
+ pga280_setMUX(2,ch);
+ pga280gain=3; // gain=1 (0x03)
+ tempdata=pga280_readOneRegisterDevice(PGA280_ERROR_ADR,ch);//чтение ошибок
+ printf("Errors %X\n",tempdata);
+ /*Конец*/
+
+
+ while(1)
+ {
+
+ wait_ms(100);
+ }
+}
+
\ No newline at end of file