I see what you mean about the manuals too. No complaints here on that. Your
answer is exactly what I needed.
As for the DO-LOOP calling the HWPWM: There will be usage many times where I do
indeed need exactly what HWPWM does, that being spit out continuous streams.
There will be just as many times where I need the exact opposite. As long as it
works and doesn't hurt the chips I'm fine.
Thanks again for your comments.
John
PS
I will make a PDF out of the ZIP I sent you and post it with your answer. All
the code willbe expanded so people can just cut and paste. Give me a few days on
that as I will be out.
HWPWM with different cycle times
-
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: HWPWM with different cycle times
> As for the DO-LOOP calling the HWPWM: There will be usage many times where I
do indeed need exactly what HWPWM does, that being spit out continuous streams.
There will be just as many times where I need the exact opposite. As long as it
works and doesn't hurt the chips I'm fine.
>
One reason I don't suggest calling HWPWM with the same parameters as a prior
call is that the TC (counter) register is set to 0 each time, so you will
probably affect the pulse train of PWM when calling with the same value. In
your program you were potentially calling the HWPWM faster than the cycletime,
in which case the PWM might never complete a pulse.
The TC has to be set to 0, otherwise if its greater than the MR (match) then
you'll have a very long pulse, until the TC wraps around to 0.
do indeed need exactly what HWPWM does, that being spit out continuous streams.
There will be just as many times where I need the exact opposite. As long as it
works and doesn't hurt the chips I'm fine.
>
One reason I don't suggest calling HWPWM with the same parameters as a prior
call is that the TC (counter) register is set to 0 each time, so you will
probably affect the pulse train of PWM when calling with the same value. In
your program you were potentially calling the HWPWM faster than the cycletime,
in which case the PWM might never complete a pulse.
The TC has to be set to 0, otherwise if its greater than the MR (match) then
you'll have a very long pulse, until the TC wraps around to 0.
-
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: HWPWM with different cycle times
Thanks Bruce,
I downloaded your new version of HWPWM.bas, got two frequencies to work, but
could not get third.
no work HWPWM126(cycletime1, high1, high2, high6)
worked HWPWM578(cycletime2, high5, high7, high8)
worked HWPWM34 (cycletime3, high3, high4)
The easiest way to fix.
In line 204. The code should be changed from
T2_MR0 = cycle2-1
to
T2_MR3 = cycle2-1
HWPWM126(cycletime1, high1, high2, high6)
is really
HWPWM126(cycletime2, high1, high2, high6)
and
worked HWPWM578(cycletime2, high5, high7, high8)
is really
worked HWPWM578(cycletime1, high5, high7, high8)
Thanks again
Gordon
I downloaded your new version of HWPWM.bas, got two frequencies to work, but
could not get third.
no work HWPWM126(cycletime1, high1, high2, high6)
worked HWPWM578(cycletime2, high5, high7, high8)
worked HWPWM34 (cycletime3, high3, high4)
The easiest way to fix.
In line 204. The code should be changed from
T2_MR0 = cycle2-1
to
T2_MR3 = cycle2-1
HWPWM126(cycletime1, high1, high2, high6)
is really
HWPWM126(cycletime2, high1, high2, high6)
and
worked HWPWM578(cycletime2, high5, high7, high8)
is really
worked HWPWM578(cycletime1, high5, high7, high8)
Thanks again
Gordon
-
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: HWPWM with different cycle times
>My problem is that the PWM never turns fully off. I want zero current at the
power transistor when the PWM% = 0.
The way the HWPWM BASIC library call works is it turns on the match at 0 and
turns it off at the width. This gives all values of 1 to the cycle time.
Are there other options, probably, but you would need to dig into the details of
the Timer/Counter hardware as defined in the NXP User Manual.
If it were something I needed the code to do, the simplest would be to make 0 a
special case, and when seen in the code, that pin would be turned back into a
GPIO (by programming the Pin Control Block) and setting that pin low
----------------- original question ----------------
Little help needed on a programming aspect
will this code
PWM_Times_R1[0] = -1;
PWM_Times_R1[1] = 1000-(Rotor_Speed_1[Current_Pitch]*4);
PWM_Times_R1[2] = 1000-(Rotor_Speed_2[Current_Pitch]*4);
HWPWM (1000, 3, PWM_Times_R1);
My problem is that the PWM never turns fully off. I want zero current at the
power transistor when the PWM% = 0. While I have a full range of control right
now, it seems necessary to completely turn off the PWM...when it needs to stop
can I re-call HWPWM using zero as the cycle time or another trick?
power transistor when the PWM% = 0.
The way the HWPWM BASIC library call works is it turns on the match at 0 and
turns it off at the width. This gives all values of 1 to the cycle time.
Are there other options, probably, but you would need to dig into the details of
the Timer/Counter hardware as defined in the NXP User Manual.
If it were something I needed the code to do, the simplest would be to make 0 a
special case, and when seen in the code, that pin would be turned back into a
GPIO (by programming the Pin Control Block) and setting that pin low
----------------- original question ----------------
Little help needed on a programming aspect
will this code
PWM_Times_R1[0] = -1;
PWM_Times_R1[1] = 1000-(Rotor_Speed_1[Current_Pitch]*4);
PWM_Times_R1[2] = 1000-(Rotor_Speed_2[Current_Pitch]*4);
HWPWM (1000, 3, PWM_Times_R1);
My problem is that the PWM never turns fully off. I want zero current at the
power transistor when the PWM% = 0. While I have a full range of control right
now, it seems necessary to completely turn off the PWM...when it needs to stop
can I re-call HWPWM using zero as the cycle time or another trick?
-
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: HWPWM with different cycle times
That helps a bit, but in this case Im using an inverting driver, 3.3V is full
off. Is there a way to make that pin go HI in response to a variable (PWM% = 0).
It is reading 3.27 Volts vs 3.3, so I know its the signal is going low at least
once a cycle. I have the circuit driving a 200W bulb, works fine but HWPWM will
not go fully to 3.3V. Is there a simple call to make that pin go HI on the ADC?
Im thinking of using an IO pin W/ diode to force 3.3 V to the mosfet driver
chip, which will turn the power off completely.
off. Is there a way to make that pin go HI in response to a variable (PWM% = 0).
It is reading 3.27 Volts vs 3.3, so I know its the signal is going low at least
once a cycle. I have the circuit driving a 200W bulb, works fine but HWPWM will
not go fully to 3.3V. Is there a simple call to make that pin go HI on the ADC?
Im thinking of using an IO pin W/ diode to force 3.3 V to the mosfet driver
chip, which will turn the power off completely.
-
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: HWPWM with different cycle times
> That helps a bit, but in this case Im using an inverting driver, 3.3V is full
off. Is there a way to make that pin go HI in response to a variable (PWM% = 0).
HWPWM is using the MAT outputs
to do that it enables MAT rather than GPIO with the PCB_PINSEL
thats what this statement does
PCB_PINSEL0 = PCB_PINSEL0 or &H00080000 'IO(0)
so if you want that pin to be low all the time, sometime before calling HWPWM
IO(0) = 0 ' which sets direction and the pin low
and in HWPWM.lib
if hightime=0 then
PCB_PINSEL0 = PCB_PINSEL and &HFFF3FFFF
return
endif
what that does is when HWPWM is called with a 0 hightime is to go back to a GPIO
and the pin will be low
Details on this are in the user manual
off. Is there a way to make that pin go HI in response to a variable (PWM% = 0).
HWPWM is using the MAT outputs
to do that it enables MAT rather than GPIO with the PCB_PINSEL
thats what this statement does
PCB_PINSEL0 = PCB_PINSEL0 or &H00080000 'IO(0)
so if you want that pin to be low all the time, sometime before calling HWPWM
IO(0) = 0 ' which sets direction and the pin low
and in HWPWM.lib
if hightime=0 then
PCB_PINSEL0 = PCB_PINSEL and &HFFF3FFFF
return
endif
what that does is when HWPWM is called with a 0 hightime is to go back to a GPIO
and the pin will be low
Details on this are in the user manual
-
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: HWPWM with different cycle times
>from the help line
>Can you tell me how to switch the duty cycles on the pwm channels at around 4
khz (max), with the channels themselves running ~ 20 khz with variable pwm? Is
this achievable with the HWPWM library function? Seems like the pwm resets take
quite a bit of time. This is for a BDC stepper motor 200 kw ive been designing
for EV applications.
Take a look at the HWPWM.bas source file in the BASIClib directory
As there is no such thing as one size fits all, you should feel free to modify
this file as needed.
Each call does the complete setup of a channel, but all you want to do is to
change the duty cycle, which is one of the MR registers. You can write that
directly rather than calling the HWPWM.
Note that this change will may not take effect until the next cycle, because the
hardware functions as an equal comparison (not < or >), details on this in the
user manual.
>Can you tell me how to switch the duty cycles on the pwm channels at around 4
khz (max), with the channels themselves running ~ 20 khz with variable pwm? Is
this achievable with the HWPWM library function? Seems like the pwm resets take
quite a bit of time. This is for a BDC stepper motor 200 kw ive been designing
for EV applications.
Take a look at the HWPWM.bas source file in the BASIClib directory
As there is no such thing as one size fits all, you should feel free to modify
this file as needed.
Each call does the complete setup of a channel, but all you want to do is to
change the duty cycle, which is one of the MR registers. You can write that
directly rather than calling the HWPWM.
Note that this change will may not take effect until the next cycle, because the
hardware functions as an equal comparison (not < or >), details on this in the
user manual.
-
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: HWPWM with different cycle times
>2. I would like to use the HWPWM command to directly control an H-bridge or
motor controller. Is is reasonable to update the duty cycle at each iteration of
the control loop (I'm aiming for about 100-500 Hz control loop with a 10-20 KHz
PWM frequency on the hardware PWM) or is it bad practice to update the duty
cycle of the HWPWM function so frequently?
You can update it as much as you wish, just make sure when you update the MATCH
register is greater than the current COUNT. Otherwise you'll have to wait for
the counter to roll over.
motor controller. Is is reasonable to update the duty cycle at each iteration of
the control loop (I'm aiming for about 100-500 Hz control loop with a 10-20 KHz
PWM frequency on the hardware PWM) or is it bad practice to update the duty
cycle of the HWPWM function so frequently?
You can update it as much as you wish, just make sure when you update the MATCH
register is greater than the current COUNT. Otherwise you'll have to wait for
the counter to roll over.