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.
Fork of mbed_adns9800 by
Revision 2:899aa692d83f, committed 2017-01-11
- Comitter:
- DimpleB05
- Date:
- Wed Jan 11 07:51:10 2017 +0000
- Parent:
- 1:b6f857ea3ce2
- Child:
- 3:ca2c09c6fb48
- Commit message:
- velocitysensor_code_change;
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Jan 09 16:07:00 2017 +0000
+++ b/main.cpp Wed Jan 11 07:51:10 2017 +0000
@@ -6,7 +6,10 @@
DigitalOut ledPin(LED1);
ADNS9800 adns(p11,p12,p13,p10);
Serial pc(USBTX, USBRX);
-int dx, dy, movementFlag, recFlag;
+
+int dx, dy;
+
+int movementFlag, recFlag;
Ticker tmr;
uint32_t time_start, time_now, time_elapsed;
@@ -31,7 +34,8 @@
{
int motion, obs;
adns.read_burst(&motion, &obs, &dx, &dy);
- if(recFlag == 1 && (dx > 0 || dy > 0))
+ // if(recFlag == 1 && (dx > 0 || dy > 0))
+ if(recFlag == 1)
{
time_now = us_ticker_read();
time_elapsed = time_now - time_start;
@@ -41,6 +45,8 @@
}
}
+
+
void start_rec()
{
recFlag = 1;
@@ -55,16 +61,64 @@
}
void format_and_send()
+ {
+
+/*/int outPkt_x, outPkt_y;
+
+ if(dx & 0x8000)
+ {
+ dx = (dx^0xFFFF) + 1;
+ outPkt_x= 0x40 | (dx & 0x3F); // negative
+ }
+ else
+ {
+ outPkt_x = dx & 0x3F;
+ }
+
+ if(dy & 0x8000)
+ {
+ dy = (dy^0xFFFF) + 1;
+ outPkt_y = 0x40 | (dy & 0x3F);
+ }
+ else
+ {
+ outPkt_y = dy & 0x3F;
+ }
+ pc.printf("Valuex= %d, Valuey = %d\r\n", outPkt_x, outPkt_y);*/
+ int outPkt_x;
+ if(dx & 0x8000)
+ {
+ dx = (dx^0xFFFF) + 1; //2's complement
+ outPkt_x= 0x40 | (dx & 0x3F); // negative
+ }
+ else
+ {
+ outPkt_x = dx & 0x3F;
+ }
+ /*if (dx &0x8000)
+ {
+ dx = -1 * ((dx ^ 0xff) + 1);
+ }
+ else
+ {
+ outPkt_x = dx;
+ }*/
+ pc.printf("Valuex=%d\r\n", outPkt_x);
+}
+
+
+/*
+void format_and_send()
{
// follow LSA's packet format
- /*
+
* Data format from microblaze to PC:
* 100000TT_0TTTTTTT_0TTTTTTT_0PXXXXXX_0PYYYYYY
* Where T = delta timestamp, P = polarity, X = delta x, Y = delta y
* Only first byte has MSB set
* timestamp in 100us per increment
* dx = 0(P)XXXXXX where 2nd bit is polarity
- */
+
uint8_t outPkt[5];
time_elapsed = time_elapsed / 100;
@@ -73,37 +127,29 @@
outPkt[1] = ((time_elapsed >> 7) & 0x0000007F);
outPkt[2] = (time_elapsed & 0x0000007F);
- if(dx & 0x8000)
- {
- dx = (dx^0xFFFF) + 1;
- outPkt[3] = 0x40 | (dx & 0x3F); // negative
- }
- else
- {
- outPkt[3] = dx & 0x3F;
- }
- if(dy & 0x8000)
- {
- dy = (dy^0xFFFF) + 1;
- outPkt[4] = 0x40 | (dy & 0x3F);
- }
- else
- {
- outPkt[4] = dy & 0x3F;
- }
-
- // send packet
- for (int i=0; i<5; i++)
- {
+
+ if(dy & 0x8000) {
+ dy = (dy^0xFFFF) + 1;
+ outPkt[4] = 0x40 | (dy & 0x3F);
+ } else {
+ outPkt[4] = dy & 0x3F;
+ }
+
+ // send packet
+ for (int i=0; i<5; i++) {
pc.putc(outPkt[i]);
- }
+ }
}
+*/
+
+
int main() {
gndPin = 0; // lazy to connect to true ground pin
movementFlag = 0;
- recFlag = 0;
+ //recFlag = 0;
+ recFlag = 1;
pc.baud(115200);
pc.printf("ADNS9800 test\r\n");
@@ -116,10 +162,11 @@
pc.printf("Sensor initialized\r\n");
// for sync with FPGA
- pulse.rise(&start_rec);
- pulse.fall(&stop_rec);
-
- tmr.attach_us(&read_motion, 1000); // timer interrupt to read registers
+ //pulse.rise(&start_rec);
+ //pulse.fall(&stop_rec);
+ // current 1000
+ //tmr.attach_us(&read_motion, 100000); // timer interrupt to read registers, 2nd value time between calls in micro-seconds
+ tmr.attach (&read_motion, 0.01); // replace it with 0.01 to execute 100 tasks in one second
while(1) {
