View Single Post
Old 09-09-2014, 06:45 PM   #1094 (permalink)
MPaulHolmes's Avatar
Join Date: Feb 2008
Location: Maricopa, AZ (sort of. Actually outside of town)
Posts: 3,832

Michael's Electric Beetle - '71 Volkswagen Superbeetle 500000
Thanks: 1,368
Thanked 1,201 Times in 765 Posts
Rotor flux angle code is now done!! And it's pretty fast and all C. I don't think I can improve upon it significantly. And I think I actually understand the computations (well, about 95% of it), which is good for debugging. Now the last major part of the code is the space vector modulation. I have to turn Va, Vb, and Vc into PWM duties. I actually already did it a couple years ago, but now I'll rewrite it, and check for errors.

For the last couple days I've been working in the evenings on computing RPM. It sounds pretty straightforward. Count the number of ticks of the encoder during some time interval. I'm using a resolution of [0,3200], where 3200 corresponds to 12000 RPM. That means, the slowest the motor post can spin is 1 revolution every 16 seconds. I had so many different attempts at the fastest possible RPM measuring method. I'm super happy with how it ended up. The ISR is run at 10KHz. The encoder has 2048 ticks per revolution (512 ticks * 4). So, all you have to do inside the ISR is:

	if (counter >= 78) {  // Compute rpm at 128 times a second.
		revPerSecond_times16 = POSCNT;
		POSCNT = 0;
		counter = 0;
kablammee! No subtractions, no divisions... So pretty. haha. POSCNT is something that's updated automatically. It's the encoder counter. Why 78? Well, 200rev/sec for 1/128 seconds = 200/128 revolutions = 3200 ticks of the encoder. 78 * 0.0001Sec is not actually 1/128. It's 1/128.2. So, this is about 99.9% accurate.

I need to solder those boards, and get the others shipped out! Sorry about the delay. I have excuses though. Our road became a river, and we couldn't drive for the last couple days...
kits and boards

Last edited by MPaulHolmes; 09-09-2014 at 06:53 PM..
  Reply With Quote
The Following User Says Thank You to MPaulHolmes For This Useful Post:
thingstodo (09-10-2014)