Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 17:38 05 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : PWM...explain to me like I'm a 5 year-old  

Author Message
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 787
Posted: 07:21am 10 Oct 2024
Copy link to clipboard 
Print this post

What precludes us from having a PWM like this?

It has been explained before but it went straight over my head  


 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6655
Posted: 09:36am 10 Oct 2024
Copy link to clipboard 
Print this post

The PWM system uses hardware modules on the RP chip. It's not all handled in firmware.

The RP has a number of "slices", 8 for the RP2040 and 12 for the RP2350. Each "slice" has a single clock divider, a single 16-bit counter and two outputs. Each "slice" can be enabled or disabled in software.

Although all GPIO pins can be used for PWM they have to be in pairs, one pair for each "slice". Thus the RP2350B, which has 48 GPIO pins, has 12 "slices" and can have 24 simultaneous PWM pins arranged as 12 pairs.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 787
Posted: 09:49am 10 Oct 2024
Copy link to clipboard 
Print this post

  Mixtel90 said  The PWM system uses hardware modules on the RP chip. It's not all handled in firmware.



Ah, I should have been more specific.

In the above table, it shows the option of 19.531KHz with 12bits resolution. This is great for driving H-Bridge + motor. But we only have ~10bits, no matter the frequency, right?
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9048
Posted: 10:14am 10 Oct 2024
Copy link to clipboard 
Print this post

  Quote  . But we only have ~10bits, no matter the frequency, right?


I don't know where this has come from. The number of bits depends on frequency. Above CPU speed / 65536 it will start to drop but below that it will be between 15 and 16 bits.




You can see here that with a CPU frequency of 252MHz I have just under 8 bits of resolution at 1MHz but nearly 16 at 1KHz

MM.INFO(PWM COUNT slice) gives the total counts being used to generate the frequency
MM.INFO(PWM DUTY slice,channel) gives the counts at which the output transitions

   int wrap=(CPU_Speed*1000)/frequency;
   if(duty1>=0.0)high1=(int)((MMFLOAT)CPU_Speed/frequency*duty1*10.0);
   if(duty2>=0.0)high2=(int)((MMFLOAT)CPU_Speed/frequency*duty2*10.0);
   while(wrap>65535){
       wrap>>=1;
       if(duty1>=0.0)high1>>=1;
       if(duty2>=0.0)high2>>=1;
       div<<=1;
   }
   if(div>256)error("Invalid frequency");
   wrap--;
   if(high1)high1--;
   if(high2)high2--;

Edited 2024-10-10 20:21 by matherp
 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 787
Posted: 11:05am 10 Oct 2024
Copy link to clipboard 
Print this post

Hi Pete.

But where you have 50% duty cycle = 31499, what if I want a smaller increment than 0.1%?

If the granularity is 0.1% then surely my effective range is 1000 (<10-bit)?
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9048
Posted: 11:08am 10 Oct 2024
Copy link to clipboard 
Print this post

What more do you want?

 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 787
Posted: 11:16am 10 Oct 2024
Copy link to clipboard 
Print this post

DOH!

I guess I was taking the one decimal as an indicator:




I thought my motor was running kinda great   Now I know why.
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024