how to output the PWM on a specific pin on port

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
zenzehar
Posts: 21
Joined: Sat Nov 01, 2008 4:00 pm

how to output the PWM on a specific pin on port

Post 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

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: how to output the PWM on a specific pin on port

Post 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.

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times

Re: how to output the PWM on a specific pin on port

Post 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.

Post Reply