| | 444 | /** |
| | 445 | Set the divider A value. |
| | 446 | Contributed by TheStigg - http://www.makingthings.com/author/thestigg |
| | 447 | @param val The value (between 0 and 255) |
| | 448 | @return 0 on success. |
| | 449 | */ |
| | 450 | int PwmOut_SetDividerAValue(int val) |
| | 451 | { |
| | 452 | if( val < 0 || val > 255 ) |
| | 453 | return CONTROLLER_ERROR_ILLEGAL_PARAMETER_VALUE; |
| | 454 | |
| | 455 | int v = Pwm_GetDividerA(); |
| | 456 | |
| | 457 | //strip off the divider Value |
| | 458 | v &= 0x00000f00; |
| | 459 | |
| | 460 | //add on the new Value |
| | 461 | v |= val; |
| | 462 | |
| | 463 | return Pwm_SetDividerA( v ); |
| | 464 | } |
| | 465 | |
| | 466 | /** |
| | 467 | Read the divider A value. |
| | 468 | Contributed by TheStigg - http://www.makingthings.com/author/thestigg |
| | 469 | @return the divider A value (0 - 255) |
| | 470 | @see PwmOut_SetDividerAValue( ) |
| | 471 | */ |
| | 472 | int PwmOut_GetDividerAValue() |
| | 473 | { |
| | 474 | return ( Pwm_GetDividerA() & 0x000000ff ); |
| | 475 | } |
| | 476 | |
| | 477 | /** |
| | 478 | Set the divider A mux value. |
| | 479 | @param mux The mux value (between 0 and 10) |
| | 480 | Contributed by TheStigg - http://www.makingthings.com/author/thestigg |
| | 481 | @return 0 on success. |
| | 482 | */ |
| | 483 | int PwmOut_SetDividerAMux(int mux) |
| | 484 | { |
| | 485 | if( mux < 0 || mux > 10 ) |
| | 486 | return CONTROLLER_ERROR_ILLEGAL_PARAMETER_VALUE; |
| | 487 | |
| | 488 | int v = Pwm_GetDividerA(); |
| | 489 | |
| | 490 | //strip off the divider Value |
| | 491 | v &= 0x000000ff; |
| | 492 | |
| | 493 | //add on the new Value |
| | 494 | v |= ( mux << 8 ); |
| | 495 | |
| | 496 | return Pwm_SetDividerA( v ); |
| | 497 | } |
| | 498 | /** |
| | 499 | Read the divider A mux value. |
| | 500 | Contributed by TheStigg - http://www.makingthings.com/author/thestigg |
| | 501 | @return the divider A mux value (0 - 10) |
| | 502 | @see PwmOut_SetDividerAMux( ) |
| | 503 | */ |
| | 504 | int PwmOut_GetDividerAMux() |
| | 505 | { |
| | 506 | return ( ( Pwm_GetDividerA() >> 8 ) & 0x0000000f ); |
| | 507 | } |
| | 508 | |
| | 509 | /** |
| | 510 | Set the divider B value. |
| | 511 | Contributed by TheStigg - http://www.makingthings.com/author/thestigg |
| | 512 | @param val The value (between 0 and 255) |
| | 513 | @return 0 on success. |
| | 514 | */ |
| | 515 | int PwmOut_SetDividerBValue(int val) |
| | 516 | { |
| | 517 | if( val < 0 || val > 255 ) |
| | 518 | return CONTROLLER_ERROR_ILLEGAL_PARAMETER_VALUE; |
| | 519 | |
| | 520 | int v = Pwm_GetDividerB(); |
| | 521 | |
| | 522 | //strip off the divider Value |
| | 523 | v &= 0x00000f00; |
| | 524 | |
| | 525 | //add on the new Value |
| | 526 | v |= val; |
| | 527 | |
| | 528 | return Pwm_SetDividerA( v ); |
| | 529 | } |
| | 530 | |
| | 531 | /** |
| | 532 | Read the divider B value. |
| | 533 | Contributed by TheStigg - http://www.makingthings.com/author/thestigg |
| | 534 | @return the divider B value (0 - 255) |
| | 535 | @see PwmOut_SetDividerBValue( ) |
| | 536 | */ |
| | 537 | int PwmOut_GetDividerBValue() |
| | 538 | { |
| | 539 | return ( Pwm_GetDividerB() & 0x000000ff ); |
| | 540 | } |
| | 541 | |
| | 542 | /** |
| | 543 | Set the divider B mux value. |
| | 544 | @param mux The mux value (between 0 and 10) |
| | 545 | Contributed by TheStigg - http://www.makingthings.com/author/thestigg |
| | 546 | @return 0 on success. |
| | 547 | */ |
| | 548 | int PwmOut_SetDividerBMux(int mux) |
| | 549 | { |
| | 550 | if( mux < 0 || mux > 10 ) |
| | 551 | return CONTROLLER_ERROR_ILLEGAL_PARAMETER_VALUE; |
| | 552 | |
| | 553 | int v = Pwm_GetDividerB(); |
| | 554 | |
| | 555 | //strip off the divider Value |
| | 556 | v &= 0x000000ff; |
| | 557 | |
| | 558 | //add on the new Value |
| | 559 | v |= ( mux << 8 ); |
| | 560 | |
| | 561 | return Pwm_SetDividerB( v ); |
| | 562 | } |
| | 563 | |
| | 564 | /** |
| | 565 | Read the divider B mux value. |
| | 566 | Contributed by TheStigg - http://www.makingthings.com/author/thestigg |
| | 567 | @return the divider B mux value (0 - 10) |
| | 568 | @see PwmOut_SetDividerBMux( ) |
| | 569 | */ |
| | 570 | int PwmOut_GetDividerBMux() |
| | 571 | { |
| | 572 | return ( ( Pwm_GetDividerB() >> 8 ) & 0x0000000f ); |
| | 573 | } |
| | 574 | |
| | 575 | /** |
| | 576 | Set the alignment of a channel's waveform. |
| | 577 | Valid values are: |
| | 578 | - 0 = Left Aligned (default) |
| | 579 | - 1 = Center Aligned |
| | 580 | |
| | 581 | Contributed by TheStigg - http://www.makingthings.com/author/thestigg |
| | 582 | @param index The PWM channel (0-3) that you'd like to configure. |
| | 583 | @param val The alignment value, as described above. |
| | 584 | @return 0 on success. |
| | 585 | */ |
| | 586 | int PwmOut_SetWaveformAlignment(int index, int val) |
| | 587 | { |
| | 588 | if ( index < 0 || index > 3 ) |
| | 589 | return CONTROLLER_ERROR_ILLEGAL_INDEX; |
| | 590 | if ( val > 1 || val < 0 ) |
| | 591 | return CONTROLLER_ERROR_ILLEGAL_PARAMETER_VALUE; |
| | 592 | |
| | 593 | int currval = Pwm_GetWaveformProperties( index ) & 0x00000006; //Leave bits 2 & 3 alone |
| | 594 | currval |= val; |
| | 595 | return Pwm_SetWaveformProperties( index, currval ); |
| | 596 | } |
| | 597 | |
| | 598 | /** |
| | 599 | Read the configured waveform alignment for a given PWM channel. |
| | 600 | |
| | 601 | Contributed by TheStigg - http://www.makingthings.com/author/thestigg |
| | 602 | @param index The PWM channel (0-3) you'd like to read from. |
| | 603 | @return the waveform alignment - see PwmOut_SetWaveformAlignment( ) |
| | 604 | */ |
| | 605 | int PwmOut_GetWaveformAlignment( int index ) |
| | 606 | { |
| | 607 | int val = Pwm_GetWaveformProperties( index ); |
| | 608 | if ( val < 0 ) |
| | 609 | return val; |
| | 610 | |
| | 611 | return val & 0x00000001; |
| | 612 | } |
| | 613 | |
| | 614 | /** |
| | 615 | Set the Waveform Polarity for a PWM channel. |
| | 616 | Valid values are: |
| | 617 | - 0 = Start Waveform Low |
| | 618 | - 1 = Start Waveform High (default) |
| | 619 | |
| | 620 | Contributed by TheStigg - http://www.makingthings.com/author/thestigg |
| | 621 | @param index The PWM channel (0-3) that you'd like to configure. |
| | 622 | @param val The value, as described above. |
| | 623 | @return 0 on success. |
| | 624 | */ |
| | 625 | int PwmOut_SetWaveformPolarity(int index, int val) |
| | 626 | { |
| | 627 | if ( index < 0 || index > 3 ) |
| | 628 | return CONTROLLER_ERROR_ILLEGAL_INDEX; |
| | 629 | if ( val > 1 || val < 0 ) |
| | 630 | return CONTROLLER_ERROR_ILLEGAL_PARAMETER_VALUE; |
| | 631 | |
| | 632 | int currval = Pwm_GetWaveformProperties( index ) & 0x00000005; //Leave bits 3 & 1 alone |
| | 633 | currval |= (val << 1); |
| | 634 | return Pwm_SetWaveformProperties( index, currval ); |
| | 635 | } |
| | 636 | |
| | 637 | /** |
| | 638 | Read the waveform polarity for a given channel. |
| | 639 | |
| | 640 | Contributed by TheStigg - http://www.makingthings.com/author/thestigg |
| | 641 | @param index The PWM channel (0-3) that you'd like to read from. |
| | 642 | @return The configured polarity for that channel. |
| | 643 | @see PwmOut_SetWaveformPolarity( ) |
| | 644 | */ |
| | 645 | int PwmOut_GetWaveformPolarity( int index ) |
| | 646 | { |
| | 647 | int val = Pwm_GetWaveformProperties( index ); |
| | 648 | if ( val < 0 ) |
| | 649 | return val; |
| | 650 | |
| | 651 | return val & 0x00000002; |
| | 652 | } |
| | 653 | |
| | 654 | /** @} |
| | 655 | */ |
| | 656 | |
| | 727 | |
| | 728 | \section p_adjust Period adjustment of the PWM unit |
| | 729 | |
| | 730 | The below values allow you to adjust the period length to all possible values as supported |
| | 731 | by the physical limits of the Make Controller. Before altering the values, it is good to understand |
| | 732 | a little about the subsustem of the PWM module. Please see the general introduction in the \ref Pwm section. |
| | 733 | |
| | 734 | \subsection DividerBValue |
| | 735 | The \b dividerXValue property corresponds to the linear divider value within clock divider module X of the |
| | 736 | PWM Out. This value can be between 0 and 255, and linearly divides the clock that is fed into it. You can |
| | 737 | change the incomming clock value by altering the DividerAMux parameter. Higher linear divider values mean |
| | 738 | a longer period. |
| | 739 | |
| | 740 | Default value of DividerA is 4. Default value of DividerB is 0. |
| | 741 | |
| | 742 | \subsection divs DividerAMux & DividerBMux |
| | 743 | The \b dividerAMux and \b dividerBMux properties select the incoming clock value for divider module A or B (respectively) |
| | 744 | of the PWM Out. This value ranges between 0 and 10. This is similar to the clock source value, eg. a DividerAMux |
| | 745 | value of 5 = a clock rate of MasterClock/(2^5) |
| | 746 | |
| | 747 | Increasing this value will substantially increase the period of the PWM. Use the DividerXValue parameter |
| | 748 | to more finely tune the value of the period. |
| | 749 | |
| | 750 | Default value of MuxA is 4. Default value of MuxB is 0. |
| | 751 | |
| | 752 | \subsection ClockSource |
| | 753 | The \b clockSource property selects the incoming clock value for the specified PWM channel. A clock |
| | 754 | source of \b 0-10 represents the Master clock divided by 2 to the power of the Clock Source Value, eg. a clock |
| | 755 | source value of 5 = a clock rate of MasterClock/(2^5). A value of \b 11 sets the Clock source to be |
| | 756 | generated by clock Divider A. A value of \b 12 sets the Clock source to be generated by clock Divider B |
| | 757 | |
| | 758 | The default value is 11 (Divider A). |
| | 759 | |
| | 760 | \subsection WaveformAlignment |
| | 761 | The \b waveformAlignment property chooses whether the channel is left aligned or center aligned. |
| | 762 | The following values are valid: |
| | 763 | - 0 = Left aligned |
| | 764 | - 1 = Center aligned |
| | 765 | |
| | 766 | A left aligned channel counts up to the maximum duty cycle, then resets the counter. A center aligned |
| | 767 | channel counts up to the maximum duty cycle, then counts down to zero, etc. The default is left aligned. |
| | 768 | |
| | 769 | \subsection WaveformPolarity |
| | 770 | The \b polarity property chooses whether the channel begins its period high or low. The following values are valid: |
| | 771 | - 0 = Normal Polarity |
| | 772 | - 1 = Inverted Polarity |
| | 773 | |
| | 774 | Normal polarity starts low, then goes high. Inverted polarity starts high, then goes low. The default is inverted polarity. |