I've been going through all the sine code making sure I understand it. I am currently confused by the value PwmGeneration::slipIncr.
It appears that this contains the number of increments of rotation for the current value of slip. However, slip is signed, and will definitely be negative during regen. However slipIncr is unsigned. Is this a bug? It works but I'm not sure if it works by accident, or whether I'm missing some intended behaviour here?
Any input from Johannes or anyone else who really understand this code would be appreciated.
Thanks, and sorry for my current flood of posts, I'm really getting my teeth into this
PwmGeneration::slipIncr unsigned [SOLVED]
- johu
- Site Admin
- Posts: 5789
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 157 times
- Been thanked: 1023 times
- Contact:
Re: PwmGeneration::slipIncr unsigned
I'd say it works half by accident as all calculations are modulo 2¹⁶ . So -1 becomes 65535. Say you have a motor angle of 30000 then subtracting -1 makes it 29999 and adding 65535 modulo 2¹⁶ also 29999.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
- catphish
- Posts: 955
- Joined: Fri Oct 08, 2021 11:02 pm
- Location: Dorset, UK
- Has thanked: 94 times
- Been thanked: 179 times
Re: PwmGeneration::slipIncr unsigned [SOLVED]
Thanks!
I thought that might be the case. It certainly appears to work. If it was just adding and subtracting the unsigned ints I wouldn't have worried too much as overflow is expected and useful, but there's also a multiplication on it. I guess this works, but it makes me uncomfortable.
Code: Select all
slipAngle += dir * slipIncr;