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: TS_DISCO_F746NG mbed Servo LCD_DISCO_F746NG BSP_DISCO_F746NG QSPI_DISCO_F746NG AsyncSerial FastPWM
Revision 8:5945d506a872, committed 2018-05-09
- Comitter:
- JonFreeman
- Date:
- Wed May 09 17:09:18 2018 +0000
- Parent:
- 7:3b1f44cd4735
- Child:
- 9:644867052318
- Commit message:
- Removed custom sin and cos code, this was originally here because library sin and cos caused display breakup, now cured it seems
Changed in this revision
--- a/costab.cpp Wed May 09 15:42:43 2018 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,65 +0,0 @@
-#include "mbed.h"
-/*
-Purpose of this file is to provide sin and cos functions. Yes, C++ has these already, but using inbuilt sin and cos on
-DISCO-F746NG causes display to flicker! Interrupt getting missed or whatever, these look-up functions solve the flicker !
-*/
-static const double HALF_PI = 2.0 * atan(1.0);
-static const double TWO_PI = 8.0 * atan(1.0);
-
-double jcos (double angle) {
-//At costabgen with 180 points
-static const double costab[] = {
-+1.000000, +0.999962, +0.999848, +0.999657, +0.999391, +0.999048, +0.998630, +0.998135,
-+0.997564, +0.996917, +0.996195, +0.995396, +0.994522, +0.993572, +0.992546, +0.991445,
-+0.990268, +0.989016, +0.987688, +0.986286, +0.984808, +0.983255, +0.981627, +0.979925,
-+0.978148, +0.976296, +0.974370, +0.972370, +0.970296, +0.968148, +0.965926, +0.963630,
-+0.961262, +0.958820, +0.956305, +0.953717, +0.951057, +0.948324, +0.945519, +0.942641,
-+0.939693, +0.936672, +0.933580, +0.930418, +0.927184, +0.923880, +0.920505, +0.917060,
-+0.913545, +0.909961, +0.906308, +0.902585, +0.898794, +0.894934, +0.891007, +0.887011,
-+0.882948, +0.878817, +0.874620, +0.870356, +0.866025, +0.861629, +0.857167, +0.852640,
-+0.848048, +0.843391, +0.838671, +0.833886, +0.829038, +0.824126, +0.819152, +0.814116,
-+0.809017, +0.803857, +0.798636, +0.793353, +0.788011, +0.782608, +0.777146, +0.771625,
-+0.766044, +0.760406, +0.754710, +0.748956, +0.743145, +0.737277, +0.731354, +0.725374,
-+0.719340, +0.713250, +0.707107, +0.700909, +0.694658, +0.688355, +0.681998, +0.675590,
-+0.669131, +0.662620, +0.656059, +0.649448, +0.642788, +0.636078, +0.629320, +0.622515,
-+0.615661, +0.608761, +0.601815, +0.594823, +0.587785, +0.580703, +0.573576, +0.566406,
-+0.559193, +0.551937, +0.544639, +0.537300, +0.529919, +0.522499, +0.515038, +0.507538,
-+0.500000, +0.492424, +0.484810, +0.477159, +0.469472, +0.461749, +0.453990, +0.446198,
-+0.438371, +0.430511, +0.422618, +0.414693, +0.406737, +0.398749, +0.390731, +0.382683,
-+0.374607, +0.366501, +0.358368, +0.350207, +0.342020, +0.333807, +0.325568, +0.317305,
-+0.309017, +0.300706, +0.292372, +0.284015, +0.275637, +0.267238, +0.258819, +0.250380,
-+0.241922, +0.233445, +0.224951, +0.216440, +0.207912, +0.199368, +0.190809, +0.182236,
-+0.173648, +0.165048, +0.156434, +0.147809, +0.139173, +0.130526, +0.121869, +0.113203,
-+0.104528, +0.095846, +0.087156, +0.078459, +0.069756, +0.061049, +0.052336, +0.043619,
-+0.034899, +0.026177, +0.017452, +0.008727, +0.000000, 0.0 } ;
-//End of costab
- const int costab_points_i = (sizeof(costab) / sizeof(double)) - 1;
- const double costab_points_d = (double) costab_points_i;
- bool isneg = false;
- int offset;
- while (angle > TWO_PI) angle -= TWO_PI;
- while (angle < 0.0) angle += TWO_PI;
- // now got 0.0 <= angle <= 2PI
- offset = (int)(angle * costab_points_d / HALF_PI); // ang2 is 0.0 <= ang2 <= 2.0 * PI
- if (offset > 3 * costab_points_i) { // quadrant = 3;
- offset = (4 * costab_points_i) - offset - 1;
- }
- else if (offset > 2 * costab_points_i) { // quadrant = 2;
- offset -= 2 * costab_points_i;
- isneg = true;
- }
- else if (offset > 1 * costab_points_i) { // quadrant = 1;
- offset = (2 * costab_points_i) - offset - 1;
- isneg = true;
- } // else quadrant = 0;
- if (offset < 0) offset = 0;
- if (offset > costab_points_i) offset = costab_points_i;
- if (isneg) return - costab[offset];
- else return costab[offset];
-}
-
-double jsin (double angle) {
- return -jcos (angle + HALF_PI);
-}
-
-
--- a/graphics.cpp Wed May 09 15:42:43 2018 +0000
+++ b/graphics.cpp Wed May 09 17:09:18 2018 +0000
@@ -33,9 +33,10 @@
// Uses our own generated sine and cosines from lookup table. For some unexplained reason, using inbuilt sin and cos fns cause display flicker !
-extern double jcos (double angle); // Used in DrawNeedle, plain sin and cos functions cause display flicker !!
-extern double jsin (double angle);
-
+//extern double jcos (double angle); // Used in DrawNeedle, plain sin and cos functions cause display flicker !!
+//extern double jsin (double angle);
+#define jcos cos
+#define jsin sin
/*void costabgen (int points) {
double angle = 0.0;
while (angle < 2.1 * PI) {
--- a/main.cpp Wed May 09 15:42:43 2018 +0000
+++ b/main.cpp Wed May 09 17:09:18 2018 +0000
@@ -22,7 +22,7 @@
#include "TS_DISCO_F746NG.h"
#include "LCD_DISCO_F746NG.h"
#include <cctype>
-#include <cerrno>
+//#include <cerrno>
LCD_DISCO_F746NG lcd;
TS_DISCO_F746NG touch_screen;
@@ -339,7 +339,6 @@
int main()
{
- errno = 0;
int qtr_sec = 0, seconds = 0, minutes = 0;
double electrical_power_Watt = 0.0;
ky_bd kybd_a, kybd_b;
@@ -347,24 +346,20 @@
memset (&kybd_b, 0, sizeof(kybd_b));
pc.baud (9600);
com.baud (19200);
- pc.printf ("\r\n\n\nLoco_TS_2018 Loco Controller starting, testing qspi mem, errno %d\r\n", errno);
+ pc.printf ("\r\n\n\nLoco_TS_2018 Loco Controller starting, testing qspi mem\r\n");
// ir.baud (1200);
- pc.printf ("Ln 352 errno %d\r\n", errno);
I_sink1 = 0; // turn outputs off
I_sink2 = 0; // lamp right
- pc.printf ("Ln 355 errno %d\r\n", errno);
I_sink3 = 0; // lamp left
I_sink4 = 0;
I_sink5 = 0;
- pc.printf ("Ln 358 errno %d\r\n", errno);
// spareio_d8.mode (PullUp); now output driving throttle servo
// spareio_d9.mode (PullUp);
spareio_d10.mode(PullUp);
Ticker tick250us;
- pc.printf ("Ln 365 errno %d\r\n", errno);
// Setup User Interrupt Vectors
tick250us.attach_us (&ISR_current_reader, 250); // count 125 of these to trig 31.25ms
// tick32ms.attach_us (&ISR_tick_32ms, 32001);
@@ -376,9 +371,7 @@
extern int ask_QSPI_OK () ;
extern bool qspimemcheck () ;
extern int qspiinit () ;
- pc.printf ("Before ask_QSPI_OK errno %d\r\n", errno);
int qspi_ok = ask_QSPI_OK ();
- pc.printf ("After ask_QSPI_OK errno %d\r\n", errno);
//extern int qspieraseblock (uint32_t addr) ;
//extern int qspiwr (uint8_t* src, uint32_t addr) ;
//extern int qspiwr (uint8_t* src, uint32_t addr, uint32_t len) ;
@@ -403,7 +396,6 @@
// pc.printf("\n\nQSPI demo started\r\n");
// Check initialization
- pc.printf ("errno %d, qspi mem ", errno);
if (qspiinit() != qspi_ok)
error("Initialization FAILED\r\n");
else
@@ -446,7 +438,6 @@
*/
//bool odometer_update (uint32_t pulsetot, uint16_t pow, uint16_t volt) ; // Hall pulse total updated once per sec and saved in blocks of 4096 bytes on QSPI onboard memory
- pc.printf ("End of qspi setup, errno %d\r\n", errno);
#endif
if (f_r_switch) {