Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente | |||
materiel:rpi:pwm:accueil [2018/01/18 06:58] chenjianwei [2D et 3D PRIMITIVES] |
materiel:rpi:pwm:accueil [2018/01/18 13:02] (Version actuelle) resonance ancienne révision (2016/12/05 18:48) restaurée |
||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | http:// | + | ====== RPI - PWM ====== |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
- | http:// | + | |
+ | {{ youtube> | ||
+ | * A : there is one hardware PWM output on the RPi, connected to P1-12 (GPIO18). | ||
+ | * B+ : This solution works only for one PWM output (GPIO18). I thinks it is because WiringPi is designed for previous version of raspberry pi (Model B+ has new PWMs on GPIO12, GPIO13 and GPIO19). | ||
+ | * Maximum 16mA per IO pin (sink or source) with the total current from all pins not exceeding 51mA (true for Model B so presumably true for Model B+ but not confirmed as full schematic not yet available). See a detailed explanation here. | ||
+ | * The maximum permitted current draw from the 3.3 V pins is 50 mA. Maximum permitted current draw from the 5 V pin is the USB input current (usually 1 A) minus any current draw from the rest of the board.[15] | ||
+ | * Model A: 1000 mA - 500 mA -> max current draw: 500 mA | ||
+ | * Model B: 1000 mA - 700 mA -> max current draw: 300 mA | ||
+ | * The PWM pin available on the GPIO header is shared with the Audio system | ||
+ | {{: | ||
+ | < | ||
+ | Basically there are two ways to create PWM: | ||
+ | * **Hardware PWM** | ||
+ | * very fast (max. possible frequency / period) | ||
+ | * software independent, | ||
+ | * clean signal | ||
+ | * BUT: not all pins might support HW PWM | ||
+ | * **Software PWM** | ||
+ | * each I/O pin can be used for SW PWM | ||
+ | * BUT: software controlled timing has to be implemented, | ||
+ | In other words: **HW PWM is clearly prefered**! | ||
+ | But unfortunately there is only one HW PWM pin (#18) available on the Rasperry Pis GPIO header (also its shared with the Audio system. That means that you can’t use PWM or Servo output and play audio through the 3.5mm jack at the same time). (http:// | ||
+ | < | ||
+ | There is one downside however: it does not come with as many PWM pins. Only one is offered and that is not enough when you want to drive external peripherals like servos, rgb leds, or anything else that requires more than a on/off signal. | ||
+ | One solution that I have seen people use is to plug an Arduino to the Raspberry Pi (through USB) but it increases seriously the cost of the package and seems a little overkill. I think it only makes sense if you are just building a quick prototype. | ||
+ | I did not want to go down that road because I want to keep the complexity and the costs down.Another solution is to use an I2C or SPI device that will be controlled from the Raspberry Pi and will generate a PWM signal to control the LED driver. I think this would be the best option but I had none of those available and being currently in Dakar (Sénégal), | ||
+ | < | ||
+ | **When might Software PWM be suitable?** | ||
- | ===== 2D et 3D PRIMITIVES ===== | + | If you want to flash a bunch of LEDs with different human visible cadences (10's of hertz) with soft real-time response requirements then the software loop could handle as many PWM's as you have GPIO pins. |
- | Cercle, carré, rectangle, sphère, cylindre, tore, cone, ... | + | |
- | {{.:primitives.png}} | + | **When might Hardware PWM be suitable? |
+ | |||
+ | If you want to control a servo motor with hard real-time response requirements then you will need to use the Hardware PWM. Even then you may have problems ensuring a real-time response for the servo loop which ties encoder input to PWM output. A stable servo loop need to read encoders at a regular rate (low jitter), write out revised PWM output values at a regular rate and the latency between these should be fixed (low jitter overall) or you will have to undertune your motor to prevent it becoming unstable under load. This is hard to do with a multi-tasking operating system without low level support. | ||
+ | |||
+ | **What if I need multiple hardware PWM outputs? | ||
+ | |||
+ | If you need to run multiple servo loops, then you are probably going to need to offload them to another device to ensure hard real-time performance, | ||