PWM-reconfigure not working on target

Moderator: Benj

Nigel_K
Flowcode v5 User
Posts: 8
Joined: Thu Aug 29, 2013 3:43 pm
Has thanked: 4 times
Contact:

PWM-reconfigure not working on target

Postby Nigel_K » Thu Aug 29, 2013 7:27 pm

To realize a feasibility study by rapid prototyping, I wanted to create a selection-menu to switch between two different PWM-frequencies before the original application starts working. So it is a reconfiguration of the PWM on-chip module while the target is running (initializing). Concerning the program itself with simulated PWM-graphs everything works fine. But on the running target I figured out (by the use of an oscilloscope) that the PWM-frequency doesn't get changed. It stays always the same like the one that is set up on the property-menu of the PWM-part on the panel...
The component macro for PWM-parts owns a function that's called "ChangePeriod" that I'm using for reconfiguring.
Currently I'm using an Explorer 16 board (revision 5) for prototyping with a PIC24FJ128GA010 microcontroller – just for information. See the attached example and try it out on a running target...
Could you please help to solve this issue?! I'd be glad to get a statement soon. :)
Attachments
PWM_reconfigure.fcf_pic16
(41.5 KiB) Downloaded 196 times

kersing
Valued Contributor
Valued Contributor
Posts: 1873
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 530 times
Been thanked: 1040 times
Contact:

Re: PWM-reconfigure not working on target

Postby kersing » Thu Aug 29, 2013 9:22 pm

In your code you set the new period before calling enable on the channels. The enable call sets the PWM to the values specified in the component properties effectively overwriting your new values. (The enable macro effectively calls SetPeriod with the values from the properties)
Change the order of the calls and you should be OK.
These users thanked the author kersing for the post (total 3):
Nigel_K (Sat Aug 31, 2013 3:25 pm) • medelec35 (Sat Aug 31, 2013 5:19 pm) • Benj (Mon Sep 02, 2013 9:30 am)
Rating: 16.67%
 
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

Nigel_K
Flowcode v5 User
Posts: 8
Joined: Thu Aug 29, 2013 3:43 pm
Has thanked: 4 times
Contact:

Re: PWM-reconfigure not working on target

Postby Nigel_K » Sat Aug 31, 2013 3:25 pm

Ahhhh ok - I didn't know about that behaviour. For my "logical" understanding it should normally be <<configure>> before <<enable>>. :o
I switched the order as recommended and it works as you said! - Thanks for the quick answer and your explanations concerning the "background". :)