main.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. #include "hal.h"
  14. #include "ch.h"
  15. #define PERIOD 0x7FFF
  16. /**
  17. * @brief PWM configuration structure.
  18. */
  19. static PWMConfig pwm3cfg = {
  20. F_CPU, /* PWM frequency. */
  21. PERIOD, /* PWM period. */
  22. NULL, /* TODO: comment. */
  23. {
  24. {PWM_OUTPUT_ACTIVE_HIGH, NULL}, /* PWM channel 1 actived. */
  25. {PWM_OUTPUT_ACTIVE_HIGH, NULL}, /* PWM channel 2 actived. */
  26. {PWM_OUTPUT_ACTIVE_HIGH, NULL}, /* PWM channel 3 actived. */
  27. },
  28. };
  29. /**
  30. * Application entry point.
  31. */
  32. int main(void) {
  33. /*
  34. * System initializations.
  35. * - HAL initialization, this also initializes the configured device drivers
  36. * and performs the board-specific initializations.
  37. * - Kernel initialization, the main() function becomes a thread and the
  38. * RTOS is active.
  39. */
  40. halInit();
  41. chSysInit();
  42. /* PE3-5 are timer 3 pwm channel outputs. */
  43. palSetPadMode(IOPORT5, 3, PAL_MODE_OUTPUT_PUSHPULL);
  44. palSetPadMode(IOPORT5, 4, PAL_MODE_OUTPUT_PUSHPULL);
  45. palSetPadMode(IOPORT5, 5, PAL_MODE_OUTPUT_PUSHPULL);
  46. pwmStart(&PWMD3, &pwm3cfg);
  47. /* Channel 0 with 50% duty cycle, 1 with 25% and 2 with 75% */
  48. pwmEnableChannel(&PWMD3, 0, PERIOD >> 1);
  49. pwmEnableChannel(&PWMD3, 1, PERIOD >> 2);
  50. pwmEnableChannel(&PWMD3, 2, (PERIOD >> 2)*3);
  51. while (TRUE) {
  52. }
  53. }