Skip to content

Commit 2f8d499

Browse files
committed
First version of diagnostic working
To be verified the strange behavior of the read potentiometer which does not work always
1 parent 883cd6f commit 2f8d499

File tree

9 files changed

+547
-82
lines changed

9 files changed

+547
-82
lines changed

extras/functions_generator_firmware/SKr3_waves/SKr3_waves.ino

Lines changed: 236 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,75 @@
2424
#include "analogWave.h"
2525
#include "scheduler.h"
2626

27-
27+
/* ########################################################################## */
2828
/* __________________________ CONFIGURATION DEFINES _________________________ */
29+
/* ########################################################################## */
2930
#define USE_CHAT_AT
3031
#define USE_TIMER
3132
#define USE_DEBUG_CODE
3233

33-
34+
/* ########################################################################## */
3435
/* _____________________________ OTHERS DEFINES _____________________________ */
35-
36+
/* ########################################################################## */
3637
#define ANRES 9
3738
#define RES 100
3839
#define SERIAL_AT Serial
3940

41+
/* ########################################################################## */
42+
/* ____________________________GLOBAL VARIABLES _____________________________ */
43+
/* ########################################################################## */
44+
45+
46+
47+
// Firmware version
48+
uint8_t version[2]={0,6};
49+
50+
char command=0;
51+
byte data[6];
52+
53+
uint16_t wave[RES];
54+
55+
LedGauge frequency_1(FQ_1, 10, 10, ROW_A_1, ROW_A_2, ROW_A_3, COL_A_1, COL_A_2, COL_A_3);
56+
LedGauge frequency_2(FQ_2, 10, 10, ROW_B_1, ROW_B_2, ROW_B_3, COL_B_1, COL_B_2, COL_B_3, true);
57+
58+
LedRange range(FQ_R, ROW_C_1, ROW_C_2, ROW_C_3, COL_C_1, COL_C_2);
59+
60+
analogWave wave1(DAC,wave,RES,0);
61+
analogWave wave2(DAC2,wave,RES,0);
62+
63+
int previous_frequency_1 = 10;
64+
int previous_frequency_2 = 10;
65+
int freq1 = 10;
66+
int freq2 = 10;
67+
68+
int previous_phase_1 = 0;
69+
int previous_phase_2 = 0;
70+
71+
int phase1 = 0;
72+
int phase2 = 0;
73+
74+
const float step = ADC_RES/float(RES);
75+
const float phase_to_deg = 180/float(RES);
76+
77+
bool test_flag = false;
78+
unsigned long time_rephase;
79+
int rephase;
80+
81+
/* ########################################################################## */
82+
/* ________CHAT AT___________________________________________________________ */
83+
/* ########################################################################## */
84+
85+
#ifdef USE_CHAT_AT
86+
87+
#include "chATWrapper.h"
88+
static CAtWrapper at(&SERIAL_AT);
89+
90+
91+
#endif //USE_CHAT_AT
92+
93+
/* ########################################################################## */
4094
/* ________TIMER_____________________________________________________________ */
95+
/* ########################################################################## */
4196

4297
#ifdef USE_TIMER
4398
#include "FspTimer.h"
@@ -46,6 +101,75 @@
46101
static FspTimer timer;
47102
static bool elapsed = false;
48103

104+
/* -------------------------------------------------------------------------- */
105+
void task10ms() {
106+
/* -------------------------------------------------------------------------- */
107+
frequency_1.refresh();
108+
frequency_2.refresh();
109+
range.update();
110+
111+
freq1=frequency_1.getGaugeValue()*range.getRange1();
112+
freq2=frequency_2.getGaugeValue()*range.getRange2();
113+
}
114+
115+
/* -------------------------------------------------------------------------- */
116+
void task15ms() {
117+
/* -------------------------------------------------------------------------- */
118+
phase1=analogRead(PH_1)/step;
119+
if (phase1>(RES+10)){
120+
phase1=0;
121+
}
122+
123+
phase2=analogRead(PH_2)/step;
124+
if (phase2>RES){
125+
phase2=0;
126+
}
127+
128+
if (freq1!=previous_frequency_1){
129+
wave1.freq(freq1);
130+
previous_frequency_1=freq1;
131+
wave1.sync(wave2);
132+
}
133+
134+
if (freq2!=previous_frequency_2){
135+
wave2.freq(freq2);
136+
previous_frequency_2=freq2;
137+
wave2.sync(wave1);
138+
}
139+
}
140+
141+
/* -------------------------------------------------------------------------- */
142+
void task20ms() {
143+
/* -------------------------------------------------------------------------- */
144+
#ifdef USE_CHAT_AT
145+
at.run();
146+
#endif
147+
}
148+
149+
150+
/* -------------------------------------------------------------------------- */
151+
void task500ms() {
152+
/* -------------------------------------------------------------------------- */
153+
if (phase1!=previous_phase_1){
154+
wave1.offset(phase1/2);
155+
previous_phase_1=phase1;
156+
if (phase2==0){
157+
wave1.sync(wave2);
158+
}
159+
}
160+
if (phase2!=previous_phase_2){
161+
wave2.offset(phase2/2);
162+
previous_phase_2=phase2;
163+
if (phase1==0){
164+
wave2.sync(wave1);
165+
}
166+
}
167+
}
168+
169+
170+
171+
172+
49173
/* -------------------------------------------------------------------------- */
50174
void timer_callback(timer_callback_args_t *arg) {
51175
/* -------------------------------------------------------------------------- */
@@ -63,7 +187,7 @@ void set_up_timer() {
63187
if(num >= 0) {
64188
Serial.print("Timer Available ");
65189
Serial.println(type);
66-
timer.begin(TIMER_MODE_PERIODIC, type, num, 1,50 , timer_callback);
190+
timer.begin(TIMER_MODE_PERIODIC, type, num, 1000,50 , timer_callback);
67191
timer.setup_overflow_irq();
68192
if(timer.open()) {
69193
Serial.println("FspTimer opened");
@@ -72,6 +196,12 @@ void set_up_timer() {
72196
Serial.println("FspTimer started");
73197
}
74198
}
199+
200+
CScheduler::getInstance().add(task10ms,TASK_10ms);
201+
CScheduler::getInstance().add(task15ms,TASK_15ms);
202+
CScheduler::getInstance().add(task20ms,TASK_20ms);
203+
CScheduler::getInstance().add(task500ms,TASK_500ms);
204+
75205
}
76206

77207
/* -------------------------------------------------------------------------- */
@@ -84,51 +214,9 @@ bool is_tick_elapsed() {
84214
return false;
85215
}
86216

87-
#endif
88217

89-
/* ________CHAT AT___________________________________________________________ */
90-
91-
#ifdef USE_CHAT_AT
92-
#include "chATWrapper.h"
93-
static CAtWrapper at(&SERIAL_AT);
94-
95-
#endif
96-
97-
98-
// Firmware version
99-
uint8_t version[2]={0,6};
100-
101-
char command=0;
102-
byte data[6];
103-
104-
uint16_t wave[RES];
105-
106-
LedGauge frequency_1(FQ_1, 10, 10, ROW_A_1, ROW_A_2, ROW_A_3, COL_A_1, COL_A_2, COL_A_3);
107-
LedGauge frequency_2(FQ_2, 10, 10, ROW_B_1, ROW_B_2, ROW_B_3, COL_B_1, COL_B_2, COL_B_3, true);
108-
109-
LedRange range(FQ_R, ROW_C_1, ROW_C_2, ROW_C_3, COL_C_1, COL_C_2);
110-
111-
analogWave wave1(DAC,wave,RES,0);
112-
analogWave wave2(DAC2,wave,RES,0);
113-
114-
int previous_frequency_1 = 10;
115-
int previous_frequency_2 = 10;
116-
int freq1 = 10;
117-
int freq2 = 10;
118-
119-
int previous_phase_1 = 0;
120-
int previous_phase_2 = 0;
121-
122-
int phase1 = 0;
123-
int phase2 = 0;
124-
125-
const float step = ADC_RES/float(RES);
126-
const float phase_to_deg = 180/float(RES);
127-
128-
bool test_flag = false;
129-
unsigned long time_rephase;
130-
int rephase;
131218

219+
#endif //USE_TIMER
132220

133221

134222
// This function loads an wave array with a sinewave using RES samples.
@@ -216,6 +304,59 @@ void setup() {
216304
#endif
217305
}
218306

307+
/* -------------------------------------------------------------------------- */
308+
void all_led_on() {
309+
/* -------------------------------------------------------------------------- */
310+
311+
for(int i = 0; i < 6;i++) {
312+
range.set(i);
313+
}
314+
315+
for(int i = 0; i < 18; i++) {
316+
if(i < 9) {
317+
frequency_1.set(i);
318+
}
319+
else if(i < 18) {
320+
frequency_2.set(i - 9);
321+
}
322+
}
323+
}
324+
325+
/* -------------------------------------------------------------------------- */
326+
void led_f1() {
327+
/* -------------------------------------------------------------------------- */
328+
range.set(1,1,1,0,0);
329+
frequency_2.set(1,1,1,0,0,0);
330+
for(int i = 0; i < 9; i++) {
331+
frequency_1.set(i);
332+
}
333+
}
334+
335+
/* -------------------------------------------------------------------------- */
336+
void led_f2() {
337+
/* -------------------------------------------------------------------------- */
338+
range.set(1,1,1,0,0);
339+
frequency_1.set(1,1,1,0,0,0);
340+
for(int i = 0; i < 9; i++) {
341+
frequency_2.set(i);
342+
}
343+
}
344+
345+
/* -------------------------------------------------------------------------- */
346+
void led_r() {
347+
/* -------------------------------------------------------------------------- */
348+
frequency_1.set(1,1,1,0,0,0);
349+
frequency_2.set(1,1,1,0,0,0);
350+
for(int i = 0; i < 6; i++) {
351+
range.set(i);
352+
}
353+
}
354+
355+
356+
357+
358+
359+
219360

220361
/* _______________________________LOOP_______________________________________ */
221362

@@ -226,6 +367,50 @@ void loop() {
226367
#ifdef USE_DEBUG_CODE
227368
//Serial.println("Msin loop running");
228369
#endif
370+
371+
372+
#ifdef USE_TIMER
373+
AppSt_t st = at.getStatus();
374+
375+
if(st == APP_NORMAL) {
376+
CScheduler::getInstance().run();
377+
}
378+
else {
379+
if(st == APP_DIAGNOSTIC_LED_ON) {
380+
all_led_on();
381+
}
382+
else if(st == APP_DIAGNOSTIC_LED_ON_F1) {
383+
led_f1();
384+
}
385+
else if(st == APP_DIAGNOSTIC_LED_ON_F2) {
386+
led_f2();
387+
}
388+
else if(st == APP_DIAGNOSTIC_LED_ON_R) {
389+
led_r();
390+
}
391+
float f1 = at.getF1();
392+
if(f1 != 0.0) {
393+
wave1.freq(f1);
394+
at.resetF1();
395+
}
396+
float f2 = at.getF2();
397+
if(f2 != 0.0) {
398+
wave2.freq(f2);
399+
at.resetF2();
400+
}
401+
float a1 = at.getA1();
402+
if(a1 > 0.0) {
403+
wave1.amplitude(a1);
404+
at.resetA1();
405+
}
406+
float a2 = at.getA2();
407+
if(a2 > 0.0) {
408+
wave2.amplitude(a2);
409+
at.resetA2();
410+
}
411+
at.run();
412+
}
413+
#else
229414

230415

231416
frequency_1.refresh();
@@ -275,9 +460,10 @@ void loop() {
275460
time_rephase=millis();
276461
}
277462

278-
#ifdef USE_CHAT_AT
279-
at.run();
463+
delay(1);
280464
#endif
281465

282-
delay(1);
466+
467+
468+
283469
}

extras/functions_generator_firmware/SKr3_waves/chATWrapper.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "chATWrapper.h"
22
#include "chAt_cmds.h"
3+
#include "pin_def.h"
4+
35

46

57

@@ -12,7 +14,7 @@ int CAtWrapper::run() {
1214

1315

1416
/* -------------------------------------------------------------------------- */
15-
CAtWrapper::CAtWrapper(arduino::HardwareSerial *s) : mode(0) {
17+
CAtWrapper::CAtWrapper(arduino::HardwareSerial *s) {
1618
/* -------------------------------------------------------------------------- */
1719
/* set up serial */
1820
serial = s;
@@ -44,4 +46,4 @@ CAtWrapper::CAtWrapper(arduino::HardwareSerial *s) : mode(0) {
4446

4547
add_cmds();
4648

47-
}
49+
}

0 commit comments

Comments
 (0)