100 likes | 229 Views
This guide provides detailed instructions on configuring the simple output compare modes for the dsPIC30F4011/4012 microcontrollers using MikroC. It outlines the various Output Compare Match modes available, including the methods to generate single and continuous output pulses. By understanding the OCxCON settings and the associated OCxR register configurations, users can effectively control the I/O pin states based on timer comparisons. Ideal for embedded systems developers, this resource is designed to streamline the implementation of output control features in your projects.
E N D
Download Links • MPLAB IDE • dsPIC30F4011/4012 Data Sheet • dsPIC30F Family Reference Manual • MikroC • MikroC Manual • MikroC Quick Reference
13.2 Simple Output Compare Match Mode When control bits, OCM<2:O> (OCxCON<2:O>) 001, 010 or 011, the selected output compare channel is configured for one of three simple Output Compare Match modes: Compare forces I/O pin low Compare forces I/O pin high Compare toggles I/O pin The OCxR register is used in these modes. The OCxR register is loaded with a value and is compared to the selected incrementing timer count. When a compare occurs, one of these Compare Match modes occurs. If the counter resets to zero before reaching the value in OCxR, the state of the OCx pin remains unchanged.
13.3.1 SINGLE OUTPUT PULSE MODE / CONTINUOUS OUTPUT PULSE MODE For the user to configure the module for the generation of a single output pulse, the following steps are required (assuming timer is off): Determine instruction cycle time TcY. Calculate desired pulse width value based on TcY. Calculate time to start pulse from timer start value of Ox0000. Write pulse width start and stop times into OCxR and OCxRS Compare registers (x denotes channel 1, 2 N). Set Timer Period register to value equal to, or greater than, value in OCxRS Compare register. Set OCM<2:O> 100. Enable timer, TON (TxCON<15>) 1. To initiate another single pulse, issue another write to set OCM<2:O> 100. / Set OCM<2:O> 101.
5 MHz Oscillator • void main() • { • T2CON=0x8000; • PR2 = 3; • OC1R = 0; • OC1RS = 2; • OC1CON=0x2005; • }
40 kHz Oscillator • void main() • { • T2CON=0x8000; • PR2 = 499; • OC1R = 0; • OC1RS = 250; • OC1CON=0x2005; • }