[{"element_type":"text","content":"\n        \u003cp\u003eWith CircuitPython 8.x.x the new \u003cstrong\u003ecyw43\u003c/strong\u003e library was introduced.\u0026nbsp; The CYW43 supports controlling the power and efficiency of the CYW43439A0 WiFi chip on the Raspberry Pi Pico W microcontroller and other microcontrollers.\u0026nbsp; The pins controlling 3 minor functions were transferred to the CYW43439A0 because Raspberry Pi Pico had used all the RP2040 pins.\u0026nbsp; So the CYW43439A0 WiFi module had to be shoehorned between the RP2040 and the green LED, SMPS_MODE, and VBUS_SENSE functions.\u0026nbsp; These three functions and the CYW43439A0 will be discussed here.\u003c/p\u003e\n\u003cp\u003eThere are four sections to the new cyw43 internal library.\u0026nbsp; This is new to CircuitPython starting with version 8.0.0.\u0026nbsp; The features that \u003cstrong\u003eimport cyw43\u003c/strong\u003e will give you access to are:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003eCYW43439A WiFi power management\u003c/li\u003e\n\u003cli\u003eAccess to and control of the onboard \u003cstrong\u003eGreen LED\u003c/strong\u003e\n\u003c/li\u003e\n\u003cli\u003eAccess to and control of the \u003cstrong\u003eSMPS_MODE\u003c/strong\u003e option (PFM, PWM)\u003c/li\u003e\n\u003cli\u003eAccess to whether power is being supplied by way of the USB port by reading \u003cstrong\u003eVBUS_SENSE\u003c/strong\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eFour WiFi power management modes are predefined with the following:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\n\u003cstrong\u003ePM_STANDARD, 0xa11142\u003c/strong\u003e: Is the standard power management mode. It enables power management and sets the power conservation timer to 200ms, 0x14.\u003c/li\u003e\n\u003cli\u003e\n\u003cstrong\u003ePM_AGGRESSIVE, 0xa11c82\u003c/strong\u003e: It enables power management and sets the power conservation timer to 2000ms, 0xc8. This mode provides optimal power usage at the cost of performance.\u003c/li\u003e\n\u003cli\u003e\n\u003cstrong\u003ePM_PERFORMANCE, 0x111022\u003c/strong\u003e: It enables power management and sets the power conservation timer to 20ms, 0x02. This mode uses more power to increase performance.\u003c/li\u003e\n\u003cli\u003e\n\u003cstrong\u003ePM_DISABLED, 0xa11140\u003c/strong\u003e: Power management is disabled in this mode.\u0026nbsp; The power management timer is set to 200ms, 0x14.\u0026nbsp; \u003cstrong\u003eNote\u003c/strong\u003e: CircuitPython sets this mode at power on and reset because it provides the best connectivity reliability.\u003c/li\u003e\n\u003cli\u003e\n\u003cstrong\u003eAlternate Power Settings\u003c/strong\u003e: There does not seem to be a standard name for what each means.\u0026nbsp; These are from the MicroPython documentation.\u003cbr\u003e\u0026nbsp; PM_NONE = 0x000010 # Like PM_DISABLED above\u003cbr\u003e\u0026nbsp; PM_POWERSAVE = 0x000011 # More power savings than PM_PERFORMANCE above\u003cbr\u003e\u0026nbsp; PM_PERFORMANCE = 0xA11142 # Same as PM_STANDARD above\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eTo see what each bit of the 12 bit word does, check the first document referenced at the end of this document.\u003c/p\u003e\n\u003cp\u003eThe following code snippet shows how to set the mode to the STANDARD mode.\u003c/p\u003e\n\u003cp\u003e\u003ccode\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp; try:\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; import cyw43\u0026nbsp; # Also tests for Raspberry Pi Pico W\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e\u0026nbsp;\u0026nbsp; \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;cyw43.set_power_management(cyw43.PM_STANDARD)\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp; except ImportError:\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp; cyw43 = None\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp; print(hex(cyw43.get_power_management())) # Will show the HEX value.\u003c/code\u003e\u003c/p\u003e\n\u003cp\u003eThe challenge for the designers of the Raspberry Pi Pico W to add WiFi services they needed to repurpose three feature pins.\u0026nbsp; The green LED, SMPS_MODE, and VBUS_SENSE control lines are used.\u0026nbsp; To access them on the Pico W, the following code snippets may help you.\u003c/p\u003e\n\u003cp\u003eTo drive the green LED we must now go through the WiFi module.\u0026nbsp; Fortunately, board.LED does that for us.\u003c/p\u003e\n\u003cp\u003e\u003ccode\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp; # Green LED, WL_GPIO0, CYW0\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp; GreenLED = digitalio.DigitalInOut(board.LED)\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp; GreenLED.direction = digitalio.Direction.OUTPUT\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp;\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp; GreenLED.value = True # Turn green LED ON\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp; GreenLED.value = False # Turn green LED OFF\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp; print('Green LED ', GreenLED.value) # Test for green LED state\u003c/code\u003e\u003c/p\u003e\n\u003cp\u003eSMPS_MODE sets the way the power management chip converts the supplied power to the 3.3 volts the RP2040 MCU and other devices require.\u0026nbsp; SMPS_MODE controls the PS (Power Save) pin on the RT6150 buck/boost power manager.\u0026nbsp;\u003c/p\u003e\n\u003cp\u003eWhen PS is low (0) (the default on Pico) the regulator is in Pulse Frequency Modulation (PFM) mode, which, at light and moderate loads, saves considerable power by only turning on the switching MOSFETs occasionally to keep the output capacitor topped up.\u0026nbsp; PFM outputs a constant wave shape but at different frequencies depending on the load.\u0026nbsp; Higher load \u0026gt;\u0026gt; higher frequency.\u0026nbsp; An inductor is used to store power between the HIGHs to smooth out the ripple introduced by turning the power converter MOSFETs ON and OFF.\u003c/p\u003e\n\u003cp\u003eSetting PS high (1) forces the regulator into Pulse Width Modulation (PWM) mode.\u0026nbsp; PWM mode forces the SMPS to switch continuously, which reduces the output ripple considerably at light loads (which can be good for some use cases) but at the expense of much worse efficiency.\u0026nbsp; PWM outputs a constant frequency with a varying portion of HIGH versus LOW states.\u0026nbsp; With a higher current demand, the output will increase the duration of the HIGH state and reduce the duration of the LOW state.\u0026nbsp; An inductor is used to store power between HIGH states to smooth out the 3.3 volts sent to the circuits.\u0026nbsp; Improved ripple is achieved, but worse efficiency at light loads will occur.\u0026nbsp; It may improve Analog to Digital Conversion and other stability critical operations.\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003eNote:\u003c/strong\u003e Under heavy load conditions the switcher will be in PWM mode irrespective of the PS pin state.\u003c/p\u003e\n\u003cp\u003e\u003ccode\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp; # SMPS_MODE, WL_GPIO1, CYW1, 0=PFM Mode (Default, Best Efficiency),\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e\u0026nbsp;\u0026nbsp; \u0026nbsp;# 1=PWM Mode (Improved ripple, worse efficiency at light loads)\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp; SMPS = digitalio.DigitalInOut(board.SMPS_MODE)\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp; SMPS.direction = digitalio.Direction.OUTPUT\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp; SMPS.value = False # PFM Mode, most efficient\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp; print('SMPS_MODE ', SMPS.value)\u003c/code\u003e\u003c/p\u003e\n\u003cp\u003eBy reading the value from VBUS_SENSE you can determine if power is being supplied through the USB connector.\u0026nbsp; If the value is \u003cstrong\u003eTrue (1)\u003c/strong\u003e power is being provided from the USB connector.\u0026nbsp; If it is \u003cstrong\u003eFalse (0)\u003c/strong\u003e power is coming from some other source.\u0026nbsp; It may be ~2.0 volts to 5.5 volts applied to the VSYS pin or 3.3 volts applied to the 3V3 pin.\u0026nbsp; Applying 3.3 volts to the 3V3 pin is not advised unless it is exceptionally well regulated.\u0026nbsp; Momentary startup overvoltage spikes can be lethal to your MCU.\u0026nbsp; If power is applied to VSYS an onboard diode connected between VBUS and VSYS prevents back feeding power to the PC USB port.\u003c/p\u003e\n\u003cp\u003e\u003ccode\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp; # VBUS_SENSE, WL_GPIO2, CYW2\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp; # True = we have power from USB\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp; # False = power via VSYS or 3V3\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp; VBUS = digitalio.DigitalInOut(board.VBUS_SENSE)\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp; VBUS.direction = digitalio.Direction.INPUT\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp; print('VBUS_SENSE', VBUS.value)\u003c/code\u003e\u003c/p\u003e\n\u003cp\u003eSource documents:\u003c/p\u003e\n\u003cp\u003e\u003ca href=\"https://docs.circuitpython.org/en/latest/shared-bindings/cyw43/index.html\"\u003ehttps://docs.circuitpython.org/en/latest/shared-bindings/cyw43/index.html\u003c/a\u003e\u003c/p\u003e\n\u003cp\u003e\u003ca href=\"https://datasheets.raspberrypi.com/picow/pico-w-product-brief.pdf\"\u003ehttps://datasheets.raspberrypi.com/picow/pico-w-product-brief.pdf\u003c/a\u003e\u003c/p\u003e\n\u003cp\u003e\u0026nbsp;\u003c/p\u003e\n      ","metadata":{}}]