micromite pwm commands


Author Message
foxleyboy
Newbie

Joined: 09/06/2019
Location: United Kingdom
Posts: 20
Posted: 05:23pm 09 Jun 2024      

I want to use gp16 (pin21) as pwm. With SETPIN gp16, PWM I can set PWM, 0, 1000, 50 to get 1KHz 50% duty cycle OK. But when I try to stop it with PWM 0, OFF it tells me I ERROR pin not set for the PWM, 0, 1000, 50 instruction. However I have already seen the 1KHz signal on my scope before I introduced the PWM 0, OFF instruction.
So what am I doing that is not right?
Many thanks for any help.
Roy

phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 1903
Posted: 09:56pm 09 Jun 2024      

I don't see that problem on RC5 but do get other odd things with PWM error handling.
> option list
PicoMite MMBasic Version 5.09.00RC5
OPTION FLASH SIZE 16777216
OPTION CPUSPEED  420000 'KHz

> SETPIN gp16, PWM
> PWM 0, 1000, 50
> PWM 0, OFF
> SETPIN gp0, PWM
> PWM 0, 1000, 50
> SETPIN gp16, PWM
Error: Invalid address - resetting


Invalid clock speed - reset to default
> option list
PicoMite MMBasic Version 5.09.00RC5
OPTION FLASH SIZE 16777216

> OPTION CPUSPEED  420000
> SETPIN gp16, PWM
> SETPIN gp0, PWM
Error : Already Set to pin -9067575637245427710
> PWM 0, 1000, 50
> PWM 0, OFF
>

foxleyboy
Newbie

Joined: 09/06/2019
Location: United Kingdom
Posts: 20
Posted: 03:18pm 11 Jun 2024      

Hi Guru, Thanks for your reply. It seems to confirm that it does not behave as per picomite manual. I will keep trying various things and if I cant get it to work then will have to move on and try some sort of work-around, like adding a hardware oscillator.
I already do have PWM on gp28 and it works but its driving a servo and I never try to stop it with a PWM 6, OFF
Roy

matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8674
Posted: 03:49pm 11 Jun 2024      

The above bug is fixed in the latest download

foxleyboy
Newbie

Joined: 09/06/2019
Location: United Kingdom
Posts: 20
Posted: 03:42pm 12 Jun 2024      

Hi matherp
Many thanks for this info. I will update my system in the next day or so and try again.
Roy

foxleyboy
Newbie

Joined: 09/06/2019
Location: United Kingdom
Posts: 20
Posted: 04:45pm 14 Jun 2024      

Hi matherp
I have downloaded and installed the latest version which seems to be V5.08.00.uf2
downloaded from the ref as per micromite user manual http://geoffg.net/picomite.html

But still have problems.
I have

setpin gp16, pwm
pwm 0, 1000, 50

this runs until the following line is executed

pwm 0, off

and then it gives an error message

pwm 0, 1000, 50
error : pin not set for pwm

Note gp16 is not used for anything else.

Have I downloaded the latest version?

Many thanks
Roy

Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3791
Posted: 05:58pm 14 Jun 2024      

When you stop the pwm, the pin is also disconnected, very handy if you want to re-purpose the pin.

So after pwm 0,off
You must again
Setpin gp16,pwm
PWM 0,1000,50

Alternatively you can keep the pwm running at 0% duty cycle
PWM 0,1000,0

Then the pwm keeps connected to gp16


Volhout
Edited 2024-06-15 04:02 by Volhout

foxleyboy
Newbie

Joined: 09/06/2019
Location: United Kingdom
Posts: 20
Posted: 06:31pm 14 Jun 2024      

Hi Volhout certainly setting it to a zero duty cycle works.
Many thanks
Roy

matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8674
Posted: 06:45pm 14 Jun 2024      

  Quote  When you stop the pwm, the pin is also disconnected


This is the same for all I/O modes : I2C, SPI, PWM, UART
When you close the usage the pins are released back to unallocated

This is how it is intended so as Volhout says if you set the PWM to OFF you will need to SETPIN the pins again to re-use for PWM

foxleyboy
Newbie

Joined: 09/06/2019
Location: United Kingdom
Posts: 20
Posted: 08:07am 15 Jun 2024      

Thanks guys, Now tested both methods and it all works.
Maybe there should be something about this in the picomite user manual? Perhaps where the 'commands' are listed and defined? Certainly have not spotted it anywhere myself. Just a thought?

Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6012
Posted: 08:30am 15 Jun 2024      

For SETPIN in the PWM section it says:
  Quote  Allocate pin to PWMnx. n and x are optional.
'n' is the PWM number (0 to 7) and 'x' and is the channel (A or B)
The setpin can be changed until the PWM command is issued. At that point
the pin becomes locked to PWM until PWMn,OFF is issued.


Although it's not specifically stated that the pin is released, it does make sense. After a while you start to assume this sort of thing as the manual can't really show every variation of every command.