Use IQS62X sensor and move motor by detected angle
Dependencies: DRV8830 IQS62x IQSDisplayTerminal UIT_ACM1602NI mbed
Fork of Nucleo_ACM1602_I2C_DC by
Revision 5:2b9614aa1171, committed 2017-09-21
- Comitter:
- 8mona
- Date:
- Thu Sep 21 11:27:10 2017 +0000
- Parent:
- 4:83f7df775d46
- Child:
- 6:e3afb1390167
- Commit message:
- Add S curve direction
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/IQS624_Init/IQS624_Init.cpp Thu Sep 21 11:27:10 2017 +0000
@@ -0,0 +1,60 @@
+#include "IQS62x.h"
+
+// Function to configure/initialize the IQS624
+// Uses the configuration data provided in "IQS624_Init.h"
+// The file "IQS624_Init.h" can be created/exported by the Azoteq software tools
+// The included version of "IQS624_Init.h" is a robust demo configuration
+// More info on IQS624: http://www.azoteq.com/products/proxfusion/iqs624?mbed
+
+#include "IQS624_Init.h"
+
+void IQS62xIO::configure() {
+
+/* Change the Prox Sensor Settings */
+/* Memory Map Position 0x40 - 0x49 */
+ writeRegister( 0x40, PXS_SETTINGS_0 );
+ writeRegister( 0x41, PXS_SETTINGS_1 );
+ writeRegister( 0x42, PXS_SETTINGS_2 );
+ writeRegister( 0x43, PXS_SETTINGS_3 );
+ writeRegister( 0x44, PXS_SETTINGS_4 );
+ writeRegister( 0x45, PXS_SETTINGS_5 );
+ writeRegister( 0x46, PXS_SETTINGS_6 );
+ writeRegister( 0x47, PXS_SETTINGS_7 );
+ writeRegister( 0x48, PXS_SETTINGS_8 );
+ writeRegister( 0x49, PXS_SETTINGS_9 );
+
+/* Change the Prox UI Settings */
+/* Memory Map Position 0x50 - 0x54 */
+ writeRegister( 0x50, PXS_UI_SETTINGS_0 );
+ writeRegister( 0x51, PXS_UI_SETTINGS_1 );
+ writeRegister( 0x52, PXS_UI_SETTINGS_2 );
+ writeRegister( 0x53, PXS_UI_SETTINGS_3 );
+ writeRegister( 0x54, PXS_UI_SETTINGS_4 );
+
+/* Change the HALL Sensor Settings */
+/* Memory Map Position 0x70 - 0x7A */
+ writeRegister( 0x70, HALL_SETTINGS_0 );
+ writeRegister( 0x71, HALL_SETTINGS_1 );
+ writeRegister( 0x72, HALL_SETTINGS_2 );
+ writeRegister( 0x73, HALL_SETTINGS_3 );
+ writeRegister( 0x74, HALL_SETTINGS_4 );
+ writeRegister( 0x75, HALL_SETTINGS_5 );
+ writeRegister( 0x76, HALL_SETTINGS_6 );
+ writeRegister( 0x77, HALL_SETTINGS_7 );
+ writeRegister( 0x78, HALL_SETTINGS_8 );
+ writeRegister( 0x79, HALL_SETTINGS_9 );
+ writeRegister( 0x7a, HALL_SETTINGS_10 );
+
+/* Change the Device & PMU Settings */
+/* Memory Map Position 0xD0 - 0xD7 */
+ writeRegister( 0xd0, SYSTEM_SETTINGS );
+ writeRegister( 0xd1, ACTIVE_CHS );
+ writeRegister( 0xd2, PMU_SETTINGS );
+ writeRegister( 0xd3, REPORT_RATES_TIMINGS_0 );
+ writeRegister( 0xd4, REPORT_RATES_TIMINGS_1 );
+ writeRegister( 0xd5, REPORT_RATES_TIMINGS_2 );
+ writeRegister( 0xd6, REPORT_RATES_TIMINGS_3 );
+ // NO 0xd7 in data sheet.... writeRegister( 0xd7, REPORT_RATES_TIMINGS_4 );
+
+}
+// end of IQS624_Init.cpp
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/IQS624_Init/IQS624_Init.h Thu Sep 21 11:27:10 2017 +0000 @@ -0,0 +1,57 @@ +/* +* This file contains all the necessary settings for the IQS624 and this file can +* be changed from the GUI or edited here +* File: IQS624_init.h +* Author: Azoteq +*/ + +#ifndef IQS624_INIT_H +#define IQS624_INIT_H + +/* Change the Prox Sensor Settings */ +/* Memory Map Position 0x40 - 0x49 */ +#define PXS_SETTINGS_0 0x01 +#define PXS_SETTINGS_1 0x02 +#define PXS_SETTINGS_2 0x5A +#define PXS_SETTINGS_3 0x18 +#define PXS_SETTINGS_4 0xD0 +#define PXS_SETTINGS_5 0x00 +#define PXS_SETTINGS_6 0xE6 +#define PXS_SETTINGS_7 0x9A +#define PXS_SETTINGS_8 0x81 +#define PXS_SETTINGS_9 0x05 + +/* Change the Prox UI Settings */ +/* Memory Map Position 0x50 - 0x54 */ +#define PXS_UI_SETTINGS_0 0x14 +#define PXS_UI_SETTINGS_1 0x20 +#define PXS_UI_SETTINGS_2 0x14 +#define PXS_UI_SETTINGS_3 0x20 +#define PXS_UI_SETTINGS_4 0x28 + +/* Change the HALL Sensor Settings */ +/* Memory Map Position 0x70 - 0x7A */ +#define HALL_SETTINGS_0 0x04 +#define HALL_SETTINGS_1 0x03 +#define HALL_SETTINGS_2 0x93 +#define HALL_SETTINGS_3 0x93 +#define HALL_SETTINGS_4 0xAC +#define HALL_SETTINGS_5 0xA1 +#define HALL_SETTINGS_6 0x0A +#define HALL_SETTINGS_7 0x09 +#define HALL_SETTINGS_8 0x46 +#define HALL_SETTINGS_9 0x70 +#define HALL_SETTINGS_10 0xE5 + +/* Change the Device & PMU Settings */ +/* Memory Map Position 0xD0 - 0xD7 */ +#define SYSTEM_SETTINGS 0x08 +#define ACTIVE_CHS 0x3F +#define PMU_SETTINGS 0x03 +#define REPORT_RATES_TIMINGS_0 0x10 +#define REPORT_RATES_TIMINGS_1 0x64 +#define REPORT_RATES_TIMINGS_2 0x0A +#define REPORT_RATES_TIMINGS_3 0x14 +#define REPORT_RATES_TIMINGS_4 0x07 + +#endif /* IQS624_INIT_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/IQS62x.lib Thu Sep 21 11:27:10 2017 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/Azoteq/code/IQS62x/#f0675a3150c7
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/IQSDisplayTerminal.lib Thu Sep 21 11:27:10 2017 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/Azoteq/code/IQSDisplayTerminal/#a68c51f5d364
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/deviceType.h Thu Sep 21 11:27:10 2017 +0000 @@ -0,0 +1,5 @@ +// the device type, not used at the moment, but we have it +#define DEVICE_TYPE_IQS624 1 + +// used by IQS62x lib when we want to override the simple configure() function +#define OVERRIDE_CONFIGURE 1 \ No newline at end of file
--- a/main.cpp Tue Sep 05 15:05:38 2017 +0000
+++ b/main.cpp Thu Sep 21 11:27:10 2017 +0000
@@ -6,23 +6,37 @@
#include "ACM1602NI.hpp"
#include "DRV8830.h"
+#include "IQS62x.h"
+#include "IQSdisplayTerminal.h"
+
+
+//IQS62xDisplay terminal; // class to display IQS62x registers on a terminal
+IQS62xIO iqs62x; // class for basic IQS62x block read and write
//Cycle
-#define ON_DURATION 8*2 //On time [*100ms]
-#define SWITCH_PERIOD 30*2 //Cycle time[*100ms]
-#define WAIT_DELAY 5*2 //Delay time [*100ms]
-#define TOTAL_TIMES 30000 //total times n
+#define UP_DURATION 14 //On time [*100ms]
+#define WAIT_DELAY 10 //Delay time [*100ms]
+#define DOWN_DURATION 8 //Down time [*50ms]
+#define SWITCH_PERIOD 50 //Cycle time[*50ms]
+#define TOTAL_TIMES 30000 //total times n
#define ACCEL_SIZE 6
-#define DECEL_SIZE 8
+#define DECEL_SIZE 6
-const float spd_table[] = {1.0,0.7,0.5};
-const float vol_accel[ACCEL_SIZE] = {0,0.3,0.6,0.8,0.95,1};
-const float vol_decel[DECEL_SIZE] = {1,0.9,0.75,0.55,0.4,0.25,0.15,0};
+
+const float spd_table[] = {1.0,0.9,0.8};
+//const float vol_accel[ACCEL_SIZE] = {0,0.3,0.6,0.8,0.95,1};
+const float vol_decel[DECEL_SIZE] = {1,0.75,0.4,0.15,0.05,0};
+const float vol_accel[ACCEL_SIZE] = {0,0.5,0.8,1,1,1};
+//const float vol_decel[DECEL_SIZE] = {1,0.75,0.15,-1,-0.2,0};
+
+const float donw_ratio=0.85;
+
static int sp_index=0;
using namespace Mikami;
+void ShowLCD(char * buffer, int startbyte, int endbyte); // for wheel output
Acm1602Ni lcd_; // Default, OK
@@ -42,6 +56,17 @@
// Display elapsed time in minutes and seconds
+
+
+void ShowLCD(char * buffer, int startbyte, int endbyte)
+{
+ for (int i=startbyte; i<=endbyte; i++) {
+ lcd_.WriteValue("%02x ", buffer[i]); // print out in black & white
+ }
+}
+
+
+
void TimerIsr()
{
@@ -51,7 +76,7 @@
div_t d_Cycle = div (k, SWITCH_PERIOD);
//for Current time
- div_t d_sec = div(k,600); //60s * 10n
+ div_t d_sec = div(k,600*2); //60s * 10n
int t_min = d_sec.quot;
div_t d_min = div(t_min,60); //1min=60s
int t_hr = d_min.quot;
@@ -64,9 +89,9 @@
//Motor activation
- static int mode = 1;
- if(WAIT_DELAY <= d_Cycle.rem && d_Cycle.rem < (WAIT_DELAY+ON_DURATION) )
+ //Up Movement
+ if(WAIT_DELAY <= d_Cycle.rem && d_Cycle.rem < (WAIT_DELAY+UP_DURATION) )
{
int accel_index = d_Cycle.rem - WAIT_DELAY;
if (accel_index < ACCEL_SIZE)
@@ -82,10 +107,11 @@
}
- else if ( (WAIT_DELAY+ON_DURATION)<= d_Cycle.rem && d_Cycle.rem <(2*WAIT_DELAY+ON_DURATION) )
+ //UP..stop
+ else if ( (WAIT_DELAY+UP_DURATION)<= d_Cycle.rem && d_Cycle.rem <(2*WAIT_DELAY+UP_DURATION) )
{
//wait_ms(20);
- int accel_index = d_Cycle.rem - (WAIT_DELAY+ON_DURATION);
+ int accel_index = d_Cycle.rem - (WAIT_DELAY+UP_DURATION);
if (accel_index< DECEL_SIZE)
{
motor_speed=vol_decel[accel_index] * spd_table[sp_index];
@@ -97,28 +123,32 @@
strcpy(ctext,"OFF");
}
- else if ( (2*WAIT_DELAY+ON_DURATION) <= d_Cycle.rem && d_Cycle.rem <(2*WAIT_DELAY+2* ON_DURATION) )
+
+ //down..Start
+ else if ( (2*WAIT_DELAY+UP_DURATION) <= d_Cycle.rem && d_Cycle.rem <(2*WAIT_DELAY+UP_DURATION+DOWN_DURATION) )
{
- int accel_index = d_Cycle.rem - (2*WAIT_DELAY+ON_DURATION);
+ int accel_index = d_Cycle.rem - (2*WAIT_DELAY+UP_DURATION);
if (accel_index < ACCEL_SIZE)
{
- motor_speed= - vol_accel[accel_index] * spd_table[sp_index];
+ motor_speed= - vol_accel[accel_index] * spd_table[sp_index]*donw_ratio;
}
else
{
- motor_speed= -spd_table[sp_index];
+ motor_speed= -spd_table[sp_index]*donw_ratio;
}
strcpy(ctext," CW");
//ctext="CW";
}
- else if ( (2*WAIT_DELAY+2* ON_DURATION) <= d_Cycle.rem )
+
+ //down..stop
+ else if ( (2*WAIT_DELAY+UP_DURATION+DOWN_DURATION) <= d_Cycle.rem )
{
//wait_ms(20);
- int accel_index = d_Cycle.rem - ((2*WAIT_DELAY+2* ON_DURATION));
+ int accel_index = d_Cycle.rem - ((2*WAIT_DELAY+UP_DURATION+DOWN_DURATION));
if (accel_index< DECEL_SIZE)
{
- motor_speed= -vol_decel[accel_index] * spd_table[sp_index];
+ motor_speed= -vol_decel[accel_index] * spd_table[sp_index]*donw_ratio;
}
else
{
@@ -144,10 +174,12 @@
//1 Row
//lcd_.WriteStringXY("#",0,0);
- lcd_.WriteValueXY("%1.1f", motor_speed, 0,0);
- lcd_.WriteValue("%5d/", d_Cycle.quot);
- lcd_.WriteValue("%0d",TOTAL_TIMES);
- lcd_.WriteValue("V%0d",motor_speed);
+
+
+ lcd_.WriteValueXY("%5d/", d_Cycle.quot,0,0);
+ lcd_.WriteValue("%0dM",TOTAL_TIMES);
+ lcd_.WriteValue("%1.2f", motor_speed);
+ //lcd_.WriteValue("V%0d",motor_speed);
//2 Row
@@ -158,6 +190,7 @@
lcd_.WriteValue("%02dm", df_min.rem);
+
k++;
}
@@ -188,11 +221,10 @@
int main()
{
+
//motor.speed(0);
- // Check error and reset
+ // Check error and reset
-
-
//LCD_cont=0;
//if (lcd_.IsConnected()) printf("\r\nConnected");
//else printf("\r\nDisconnected");
@@ -201,6 +233,9 @@
//timer_.attach(&TimerIsr, 0.1);
button1.fall(&flip);
+ iqs62x.configure(); // configure the ICD
+
+
bool status = motor.status();
if (status & DRV8830_F_FAULT){
motor.reset();
@@ -208,6 +243,10 @@
while (true) {
motor.speed(motor_speed);
- }
+ //iqs62x.readIqsRegisters(0,NUMBER_OF_REGISTERS); // read all the registers
+ //ShowLCD(iqs62x.registers,0x80,0x8f);
+ wait(1);
+ }
+
}
