View Single Post
Old 10-08-2015, 06:46 PM   #2151 (permalink)
Permanent Apprentice
Join Date: Jul 2010
Location: norcal oosae
Posts: 523
Thanks: 351
Thanked 312 Times in 214 Posts
Paul - I've spent some time looking over and shuffling stuff around in sensorless.c

Mainly I've moved stuff around so it's easier to find. I totally agree this is merely a programming style thing. I like it because it makes things a bit easier to find later by someone else.

In general, it goes like this:

Include statements (include other programs, like uart.c)
Define variables
Define interrupts
Define functions
Code for interrupts
Code for functions (grouped by their tasks, like time delays, etc)
Code for Main

In doing that, I found some some definitions for things that didn't exist.. ( They were probably were deleted a while ago, but the define statements are still there.)

More importantly, I saw some stuff that could actually help the program:

1) In main, there's a bunch of stuff that could be put into functions, like general error checking and activating the contactors. That would clear up what main does.

2) The function that initializes the AtoD converter, PWM, and the QEI interface should be broken into separate functions. This would give each function a clear task as well as provide easier customization. For example, my resolver doesn't want the QEI interface.

3) Just about everything runs in the AtoD converter interrupt. This has a real potential of causing instability issues if another interrupt interrupts this interrupt. (gawd just saying that sounded confusing...) I propose breaking it up into the part that MUST get the AtoD values at a specific time, and then putting up some flag so that the other functions - for example the Clarke & Park transforms, getting rotor position, and so on are done immediately afterward, in their respective functions.

If you think these are worthwhile, let me know - I'll make it happen. This will hopefully make things easier for programmers and maybe prevent impossible to track problems. In the end, it should compile the same and the end user won't notice any difference.

- E*clipse

  Reply With Quote
The Following 2 Users Say Thank You to e*clipse For This Useful Post:
Thalass (10-09-2015), thingstodo (10-08-2015)