Zombieverter PWM settup for dummies

Topics relating to the ZombieVerter VCU
Post Reply
User avatar
J0hannes
Posts: 112
Joined: Sat Nov 11, 2023 10:29 am
Location: Finland
Has thanked: 15 times
Been thanked: 127 times

Zombieverter PWM settup for dummies

Post by J0hannes »

Ok, so I'm looking at testing pump speed control with Tim3 and got confused and lonely trying to understand how these parameters actually work.

- PWM Control
100 Tim3_Presc 1 72000 719 Only used if CP Spoof and GS450h Oil pump output is not used
101 Tim3_Period 1 100000 7200 Only used if CP Spoof and GS450h Oil pump output is not used
102 Tim3_1_OC 1 100000 3600 Only used if CP Spoof and GS450h Oil pump output is not used
103 Tim3_2_OC 1 100000 3600 Only used if CP Spoof and GS450h Oil pump output is not used
104 Tim3_3_OC 1 100000 3600 Only used if CP Spoof and GS450h Oil pump output is not used

Soo after some searching this was closest to an explanation I was able to find, but really left me wondering.
royhen99 wrote: Thu Jan 30, 2025 10:18 pm Really easy to get the correct frequency. The clock is 72MHz so need total division of 36000000, e.g. 9000 x 4000.
set Tim3_Presc to 8999, and Tim3_Period to 3999. Duty cycle is controlled with Tim3_x_OC, where x is 1 to 3. 1000 gives 25% duty cycle, 2000 gives 50%, 3000 75% etc.
Dug through some STM32 application notes (AN4019, AN4776) and stared at Zombieverter source code and maybe I got this :idea:

So If I understand it correctly, this royhen99 example is setting a 2Hz update period for Tesla pump, correct?

Looking at the application notes got me thinking about how to go through this so it would be understandable.

We want to have 2Hz PWM frequency, which can be used to calculate the needed params TIM3_Presc and Tim3_Period
  • Prescaler is used to set counter clock frequency, this is arbitrary, but you'll probably want the counter to run at kHz level say 100kHz.
    System core clock for STM32 used in Zombieverter is 72MHz
    Tim3_presc = (System core clock/counter frequency)-1 --> (72 000 000 / 100 000)-1 = 719
  • PWM Period can now be calculated
    Tim3_Period = (Counter frequency / PWM period)-1 --> (100 000/ 2)-1 = 49999
  • Now we can decide the duty % and apply. Lets try 30%
    Tim3_X_OC = duty % * PWM period --> 0,3* 50 000 = 15000
  • The the duty % adjustment for PWM outputs work if they aren't assigned for another use (i.e. CP spoof)
    Tim3_1_OC = duty % on PWM 1
    Tim3_2_OC = duty % on PWM 2
    Tim3_3_OC = duty % on PWM 3
On royhen99 example counter clock is 8kHz, but otherwise the math works.

Did I get this right? :)
User avatar
tom91
Posts: 2360
Joined: Fri Mar 01, 2019 9:15 pm
Location: Bristol
Has thanked: 204 times
Been thanked: 556 times

Re: Zombieverter PWM settup for dummies

Post by tom91 »

J0hannes wrote: Tue May 20, 2025 9:05 pm Did I get this right?
get a scope out and verify it ;) or even just an okay multimeter. I struggled to do the math until Roy suggested how to set it up and thats now how the Zombie is setup.
J0hannes wrote: Tue May 20, 2025 9:05 pm The the duty % adjustment for PWM outputs work if they aren't assigned for another use (i.e. CP spoof)
No, if any PWM output is used for a dedicated output the frequency (so divider and period) for all 3 are fixed. But yes you can adjust pwm

To get 1kHz it currently does:

Code: Select all

timer_set_period(TIM3, 3999);
        timer_set_oc_value(TIM3, TIM_OC1, 1);//No duty set here
        timer_set_oc_value(TIM3, TIM_OC2, 1);//No duty set here
        timer_set_oc_value(TIM3, TIM_OC3, 1);//No duty set here
        timer_set_prescaler(TIM3,17);
So duty is %x40 to set it.
Creator of SimpBMS
Founder Volt Influx https://www.voltinflux.com/
Webstore: https://citini.com/
Post Reply