Clear Filters
Clear Filters

How to simulate battery charge over time?

8 views (last 30 days)
Max on 14 Jun 2022
Answered: Javier Gazzarri on 20 Jan 2023
Hi! I am trying to make a model in simulink that simulates a battery electric vehicle. Basically, I have this data on household energy used from the grid and PV generation from a solar panel. This data covers an entire year.
Example: time(seconds) Load(W) PV_Generation(W)
0 300 250
60 269 300
120 280 310 ...
This data goes all the way up to 527040 seconds which is almost an entire year. In this model we are assuming the household has battery managment system where when the PV_generation is greater than the Load, then the power charges a battery which in turn charges a car.
My first question is how to implement this in simulink? There is a battery block but I can't figure out how to use it. If I was just coding normally I would just set up an if else statement but I am not sure how to do this in simulink. Is there an example online somewhere that I could base this off of?
My second question is if I wanted to charge the car at night, is there an easy way to convert or abstract time in hours from the model? I understand the when I set the model to simulate in 120 seconds it runs it over 120 seconds; but I need to run it over the course of a year and was wondering if there was an easy way to just say the car charges 10 kwH every night?
I am a beginner at simulink and would appreciate all the advice and help I could get. Thanks!

Answers (1)

Javier Gazzarri
Javier Gazzarri on 20 Jan 2023
Hello Max,
Thank you for your question.
The way I would implement your design is with a combination of Simscape Battery or Simscape Electrical (physical system) and Stateflow (state and temporal logic). With the Battery (Table-based) block from Simscape you design a circuit to combine the battery itself, the PV array, and the power converter. With Stateflow you set up the conditions for charge/discharge based on the logic you described above.
You can input the table into Stateflow, and the output will be the command to the converter that will determine the power flow.
Here are a few examples:
Please let me know how it goes.
Best regards,




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!