You can now measure the rotation speed from the interval between index pulses.

This commit is contained in:
David Given
2018-09-29 16:37:04 +02:00
parent 026842b8a4
commit c174e5cafe
7 changed files with 84 additions and 6 deletions

View File

@@ -1998,6 +1998,32 @@
</CyGuid_2f73275c-45bf-46ba-b3b1-00a2fe0c8dd8>
<filters />
</CyGuid_ebc4f06d-207f-49c2-a540-72acf4adabc0>
<CyGuid_ebc4f06d-207f-49c2-a540-72acf4adabc0 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtFolderSerialize" version="3">
<CyGuid_2f73275c-45bf-46ba-b3b1-00a2fe0c8dd8 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtBaseContainerSerialize" version="1">
<CyGuid_31768f72-0253-412b-af77-e7dba74d1330 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtItemSerialize" version="2" name="INDEX_IRQ" persistent="">
<Hidden v="False" />
</CyGuid_31768f72-0253-412b-af77-e7dba74d1330>
<CyGuid_0820c2e7-528d-4137-9a08-97257b946089 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtItemListSerialize" version="2">
<dependencies>
<CyGuid_8b8ab257-35d3-4473-b57b-36315200b38b type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtFileSerialize" version="3" xml_contents_version="1">
<CyGuid_31768f72-0253-412b-af77-e7dba74d1330 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtItemSerialize" version="2" name="INDEX_IRQ.c" persistent="Generated_Source\PSoC5\INDEX_IRQ.c">
<Hidden v="False" />
</CyGuid_31768f72-0253-412b-af77-e7dba74d1330>
<build_action v="SOURCE_C;CortexM3;;;" />
<PropertyDeltas />
</CyGuid_8b8ab257-35d3-4473-b57b-36315200b38b>
<CyGuid_8b8ab257-35d3-4473-b57b-36315200b38b type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtFileSerialize" version="3" xml_contents_version="1">
<CyGuid_31768f72-0253-412b-af77-e7dba74d1330 type_name="CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtItemSerialize" version="2" name="INDEX_IRQ.h" persistent="Generated_Source\PSoC5\INDEX_IRQ.h">
<Hidden v="False" />
</CyGuid_31768f72-0253-412b-af77-e7dba74d1330>
<build_action v="HEADER;;;;" />
<PropertyDeltas />
</CyGuid_8b8ab257-35d3-4473-b57b-36315200b38b>
</dependencies>
</CyGuid_0820c2e7-528d-4137-9a08-97257b946089>
</CyGuid_2f73275c-45bf-46ba-b3b1-00a2fe0c8dd8>
<filters />
</CyGuid_ebc4f06d-207f-49c2-a540-72acf4adabc0>
</dependencies>
</CyGuid_0820c2e7-528d-4137-9a08-97257b946089>
</CyGuid_2f73275c-45bf-46ba-b3b1-00a2fe0c8dd8>

View File

Binary file not shown.

View File

@@ -19,6 +19,7 @@ static bool motor_on = false;
static uint32_t motor_on_time = 0;
static bool homed = false;
static int current_track = 0;
static volatile bool index_irq = false;
#if 0
static uint8_t td[BUFFER_COUNT];
@@ -36,6 +37,11 @@ static void system_timer_cb(void)
CyGlobalIntEnable;
}
CY_ISR(index_irq_cb)
{
index_irq = true;
}
static void start_motor(void)
{
if (!motor_on)
@@ -162,6 +168,27 @@ static void cmd_seek(struct seek_frame* f)
send_reply(&r);
}
static void cmd_measure_speed(struct any_frame* f)
{
start_motor();
UART_PutString("wait for index\n");
index_irq = false;
while (!index_irq)
;
index_irq = false;
int start_clock = clock;
UART_PutString("wait for another index\n");
while (!index_irq)
;
int end_clock = clock;
UART_PutString("done\n");
DECLARE_REPLY_FRAME(struct speed_frame, F_FRAME_MEASURE_SPEED_REPLY);
r.period_ms = end_clock - start_clock;
send_reply((struct any_frame*) &r);
}
static void handle_command(void)
{
static uint8_t input_buffer[FRAME_SIZE];
@@ -178,6 +205,10 @@ static void handle_command(void)
case F_FRAME_SEEK_CMD:
cmd_seek((struct seek_frame*) f);
break;
case F_FRAME_MEASURE_SPEED_CMD:
cmd_measure_speed(f);
break;
default:
send_error(F_ERROR_BAD_COMMAND);
@@ -189,6 +220,7 @@ int main(void)
CyGlobalIntEnable;
CySysTickStart();
CySysTickSetCallback(4, system_timer_cb);
INDEX_IRQ_StartEx(&index_irq_cb);
UART_Start();
USBFS_Start(0, USBFS_DWR_VDDD_OPERATION);
//USBFS_CDC_Init();

View File

@@ -20,5 +20,6 @@ extern void usb_cmd_recv(void* ptr, int len);
extern int usb_get_version(void);
extern void usb_seek(int track);
extern int usb_measure_speed(void);
#endif

4
main.c
View File

@@ -47,7 +47,9 @@ int main(int argc, char* const* argv)
int v = usb_get_version();
printf("FluxEngine version %d\n", v);
usb_seek(40);
int period_ms = usb_measure_speed();
printf("Rotational period is %d ms (%f rpm)\n", period_ms, 60000.0/period_ms);
#if 0
parse_options(argc, argv);

View File

@@ -25,11 +25,13 @@ enum
enum
{
F_FRAME_ERROR = 0,
F_FRAME_GET_VERSION_CMD,
F_FRAME_GET_VERSION_REPLY,
F_FRAME_SEEK_CMD,
F_FRAME_SEEK_REPLY,
F_FRAME_ERROR = 0, /* any_frame */
F_FRAME_GET_VERSION_CMD, /* any_frame */
F_FRAME_GET_VERSION_REPLY, /* version_frame */
F_FRAME_SEEK_CMD, /* seek_frame */
F_FRAME_SEEK_REPLY, /* any_frame */
F_FRAME_MEASURE_SPEED_CMD, /* any_frame */
F_FRAME_MEASURE_SPEED_REPLY, /* speed_frame */
};
enum
@@ -67,4 +69,10 @@ struct seek_frame
uint8_t track;
};
struct speed_frame
{
struct frame_header f;
uint16_t period_ms;
};
#endif

9
usb.c
View File

@@ -88,3 +88,12 @@ void usb_seek(int track)
usb_cmd_send(&f, f.f.size);
await_reply(F_FRAME_SEEK_REPLY);
}
int usb_measure_speed(void)
{
struct any_frame f = { .f = {.type = F_FRAME_MEASURE_SPEED_CMD, .size = sizeof(f)} };
usb_cmd_send(&f, f.f.size);
struct speed_frame* r = await_reply(F_FRAME_MEASURE_SPEED_REPLY);
return r->period_ms;
}