Page 1 of 1
how to output the PWM on a specific pin on port
Posted: Wed Nov 26, 2008 9:13 am
by zenzehar
i just want how to make the PWM pulses to be outputed to specific pin of port for example to portA.1 .... the simulations of PWM works perfect and i have no problems at running it ... i want just to output or save it in a variable in order to be able to output it ... best regards
Re: how to output the PWM on a specific pin on port
Posted: Wed Nov 26, 2008 10:01 am
by Benj
Hello
PWM is a hardware function and uses CCP pins. These should be marked on the chip diagram in Flowcode. CCP1 is PWM channel 1 and CCP2 is PWM channel 2. If you wish to output PWM to any old pin you will have to do it by toggling the state of the pin in software. Using a timer interrupt could come in quite handy for doing this.
Re: how to output the PWM on a specific pin on port
Posted: Wed Nov 26, 2008 10:16 am
by Sean
Unfortunately PWM functions can not be freely allocated to port pins because they are generated by hardware peripherals within the microcontrollers that are hard-wired to specific pins. This is the case for most of the peripheral functions (ADCs, UARTS, SPI, I2C etc.). It is possible to recreate most of these functions, except for the ADCs, using software and timers (bit-banging), and allocate them to any I/O. This usually requires significant amounts of extra code and provided inferior performance. As an example, the Flowcode I2C component has a bit-banged software option that can be freely allocated but is slower than the hardware equivalent.
If you only require a low PWM frequency, it is possible to generate it using the Flowcode output and delay icons in a loop. But this loop would need to execute constantly and predictably (minimum of timing variations caused by other operations). The hardware PWM runs constantly, and accurately, without software attention.
Timer interrupts are another option, with improved performance and reduced software overhead, but this is a more advanced topic.