{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    }
   },
   "outputs": [],
   "source": [
    "# define hostname\n",
    "HOSTNAME = \"192.168.1.100\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "\n",
    "pyrpl_folder = os.environ[\"pyrpl_path\"]\n",
    "sys.path.insert(0, pyrpl_folder)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pyrpl\n",
    "\n",
    "p = pyrpl.Pyrpl(\n",
    "    config=\"\",  # do not use a config file\n",
    "    hostname=HOSTNAME,\n",
    ")\n",
    "rp = p.redpitaya  # shortcut for the the redpitaya handler\n",
    "\n",
    "print(\n",
    "    rp.pwm0.__doc__\n",
    ")  # print the help, same is possible with \"rp.pwm0?\" in interactive python console\n",
    "# last line of help text is outdated and means to say: \"Currently, only pwm0 and pwm1 are available.\"\n",
    "\n",
    "print(\"Default inputs for pwm0/1: %s/%s\\n\" % (rp.pwm0.input, rp.pwm1.input))\n",
    "print(\"Input options for pwm0/1: \\n%s\" % rp.pwm0.input_options)\n",
    "rp.pwm0.input = \"pid0\"  # connect the output_signal of pid0 to pwm0 pin\n",
    "rp.pwm1.input = rp.asg0  # connect the output_signal of asg0 to pwm0 pin\n",
    "print(\"Current inputs for pwm0/1: %s/%s\\n\" % (rp.pwm0.input, rp.pwm1.input))\n",
    "\n",
    "# the pwm-module maps from the DSP signal voltages between +/-1V to the output voltages of the PWM pins from 0 to 1.8V.\n",
    "# we have a direct read-access to the current output voltages for all four PWM pins:\n",
    "print(\n",
    "    \"Current output voltages at the four PWM pins: \",\n",
    "    rp.ams.dac0,\n",
    "    rp.ams.dac1,\n",
    "    rp.ams.dac2,\n",
    "    rp.ams.dac3,\n",
    ")\n",
    "\n",
    "# we can set the static output voltage directly for the remaining pins dac2 and dac3 (those are not interfaced)\n",
    "rp.ams.dac2 = 0  # minimum possible value, everything smaller is clipped to 0\n",
    "rp.ams.dac3 = 1.8  # maximumum possible value, everything larger is clipped to 1.8\n",
    "print(\n",
    "    \"Current output voltages at the four PWM pins: \",\n",
    "    rp.ams.dac0,\n",
    "    rp.ams.dac1,\n",
    "    rp.ams.dac2,\n",
    "    rp.ams.dac3,\n",
    ")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython",
   "version": "3.10.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
