Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 17:02 05 May 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : PWM command

Author Message
Lee3
Regular Member

Joined: 17/09/2014
Location: Australia
Posts: 57
Posted: 01:46am 25 Sep 2014
Copy link to clipboard 
Print this post

I've been experimenting/fiddling with my micromite now I have a working serial terminal....

I could use the PWM command at the command line without a prob.
ie PWM 1,250,50
would run an LED at pin 4 at 50%

if I entered the same in the editor and saved/run - nothing would happen.

I'm not really sure what is happening there, I assume I'm missing something....

Lee
 
cosmic frog
Senior Member

Joined: 09/02/2012
Location: United Kingdom
Posts: 278
Posted: 03:44am 25 Sep 2014
Copy link to clipboard 
Print this post

Setpin 4,dout
 
hitsware
Guru

Joined: 23/11/2012
Location: United States
Posts: 535
Posted: 10:00am 25 Sep 2014
Copy link to clipboard 
Print this post

  cosmic frog said   Setpin 4,dout

Not needed. PWM command does that automatically.

@ Lee
I've found that sometimes a PWM STOP is needed before
a PWM command will take effect.Edited by hitsware 2014-09-26
 
cosmic frog
Senior Member

Joined: 09/02/2012
Location: United Kingdom
Posts: 278
Posted: 10:43am 25 Sep 2014
Copy link to clipboard 
Print this post

  hitsware said  
  cosmic frog said   Setpin 4,dout

Not needed. PWM command does that automatically.



Well it won't work on mine without it!

Dave.
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 01:58pm 25 Sep 2014
Copy link to clipboard 
Print this post

Something else must be going on here. The PWM output keeps running when a program ends and it does not need a SETPIN or a PWM STOP command.

I tried entering PWM 1,250,50 in the editor, saved it, then entered RUN and the output kept running.

Geoff
Geoff Graham - http://geoffg.net
 
hitsware
Guru

Joined: 23/11/2012
Location: United States
Posts: 535
Posted: 03:26pm 25 Sep 2014
Copy link to clipboard 
Print this post

> The PWM output keeps running when a program ends

It quits when you switch to edit ...

> and it does not need a SETPIN

Right

> or a PWM STOP command.

If you try to change frequency while running then
AT TIMES !
It will stutter or not output
UNLESS !
A PWM STOP is issued before the change ...

What would be nice is if the MicroMite PWMs would run as
smooth as the TONEs on the MaxiMite ......
I.E. capable of a smooth sweep without extraneous noise
Not bad though ! Edited by hitsware 2014-09-27
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 03:49pm 25 Sep 2014
Copy link to clipboard 
Print this post

> It quits when you switch to edit ...
Yes, that is because the editor needs all the memory in the chip.

  Quote  If you try to change frequency while running then
AT TIMES !
It will stutter or not output
UNLESS !
A PWM STOP is issued before the change ...


That should not happen and it works fine for me. A change in frequency will never be as smooth as the TONE command which uses a frequency synthesiser in software whereas the PWM uses the MX150's hardware.

Geoff
Geoff Graham - http://geoffg.net
 
hitsware
Guru

Joined: 23/11/2012
Location: United States
Posts: 535
Posted: 04:27pm 25 Sep 2014
Copy link to clipboard 
Print this post


@ bottom add :
DATA 8,6,9,6, 2,4,3,4

If you take the PWM 1, STOP out of the 5th
line down you'll hear what I mean ( I think )
It is an intermittent thing and the PWMs are
pretty busy ... Edited by hitsware 2014-09-27
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5914
Posted: 08:37pm 25 Sep 2014
Copy link to clipboard 
Print this post

Try putting a pause instead of the PWM stop.

It is easier for others to test your code if you paste it as text instead of the image.

With TeraTerm, you use ALT-C instead of the usual ctrl_C to copy.

Jim


VK7JH
MMedit   MMBasic Help
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2794
Posted: 08:52pm 25 Sep 2014
Copy link to clipboard 
Print this post

  TassyJim said  With TeraTerm, you use ALT-C instead of the usual ctrl_C to copy.

Wow, I never ever knew that. Thanks Jim for that useful bit of info!
For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
cosmic frog
Senior Member

Joined: 09/02/2012
Location: United Kingdom
Posts: 278
Posted: 12:14am 26 Sep 2014
Copy link to clipboard 
Print this post

Ok, just tried this again to make sure.
In the editor I have-

PWM 1,950,50

I get nothing from the speaker and nothing on my multimeter.

If I have this in the editor-

Setpin 4,dout
PWM 1,950,50

I can hear a beeeep sound and the multimeter shows around 1.5volts

Even if I type in PWM 1,950,50 directly and not in the editor I get nothing.
I am using a Pic32mx170 and the latest firmware.

Dave.
 
Lee3
Regular Member

Joined: 17/09/2014
Location: Australia
Posts: 57
Posted: 01:04am 26 Sep 2014
Copy link to clipboard 
Print this post

I just tested a small program:


for t=100 to 1 step -1
PWM 1,250,t
pause 500
next t


does nothing - except flash a cursor on screen for 50s

if I prefix that code with


setpin 4,dout


it works, giving a gradually fading LED over 50s....

This is with Pic32MX170, 4.5D firmware.
 
cosmic frog
Senior Member

Joined: 09/02/2012
Location: United Kingdom
Posts: 278
Posted: 01:50am 26 Sep 2014
Copy link to clipboard 
Print this post

Ok, I've just tried again with a Pic32mx150 and it works as it should.
So this maybe a bug in the mx170 firmware.

Dave.
 
hitsware
Guru

Joined: 23/11/2012
Location: United States
Posts: 535
Posted: 07:09am 26 Sep 2014
Copy link to clipboard 
Print this post

> Try putting a pause instead of the PWM stop.

That would be musically awkward .

> It is easier for others to test your code
> if you paste it as text instead of the image.

Yea. I forgot I was on XP
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9066
Posted: 01:39pm 26 Sep 2014
Copy link to clipboard 
Print this post

Houston, we have a bug. (agreeing with Dave, in that there is a bug with PWM in the 170 firmware perhaps?)Edited by Grogster 2014-09-27
Smoke makes things work. When the smoke gets out, it stops!
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5914
Posted: 03:12pm 26 Sep 2014
Copy link to clipboard 
Print this post

  hitsware said   > Try putting a pause instead of the PWM stop.

That would be musically awkward .

> It is easier for others to test your code
> if you paste it as text instead of the image.

Yea. I forgot I was on XP


The PWM STOP command (like all commands) takes time to execute.
I suggest that a short PAUSE will be worth trying.
Start with a few milliseconds and gradually reduce the time between tests.

The PWM will continue in the background during the pause so the only effect of the pause will be to slow the rate of change down.

I could try it myself but it is your ears that need to hear the changes, my ears are not worth using when it comes to "music"

Jim

VK7JH
MMedit   MMBasic Help
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5914
Posted: 04:27pm 26 Sep 2014
Copy link to clipboard 
Print this post

I have found time to test the code but only on a MX170 chip.
Because of the apparent but with the PWM on the MX170, I have had to run the code with the PWM STOP commands rem'ed out.

So far I have not seen any problems on the CRO but this is something that probably needs audio to listen to.

There are plenty of PAUSE statements already so I think the problem may be elsewhere.

I know you gave the circuit you are using but I cannot find the post.

This is the code as I used it. I changed mid: to middle: because MID is too close to a keyword for my liking.
OPEN "com1:3000" AS #1
DIM c(29), m(3)
FOR x = 0 TO 29 : READ c(x) : NEXT x
FOR x = 0 TO 3 : READ m(x) : NEXT x
SETPIN 4, DOUT
SETPIN 26, DOUT
DO
FOR x = 0 TO 29
'PWM 1, STOP
PWM 1, 44*c(x), 1, 1
FOR y = 0 TO 3
r = INT(RND*3)+1 : f = c(x)*m(y)*5.5
IF y = 2 THEN PRINT #1, CHR$(85);
ON r GOSUB bass, middle, high
NEXT y
NEXT x
LOOP

bass:
PWM 2, f, 33,76
PAUSE 200
'PWM 2, STOP
PAUSE 50
RETURN

middle:
PWM 2, 2*f, 10,20
PAUSE 125
'PWM 2, STOP
PAUSE 125
RETURN

high:
PWM 2, 4*f, 5,30
PAUSE 50
'PWM 2, STOP
PAUSE 200
RETURN

DATA 5,6,9,5, 5,6,9,9, 5,6,9,5, 4,9,5,5
DATA 4,5,9,9, 4,5,9,9, 4,5,9,9, 4,9
DATA 8,6,9,6, 2,4,3,4


I will try it on a MX150 chip later.

Jim

VK7JH
MMedit   MMBasic Help
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 05:37pm 26 Sep 2014
Copy link to clipboard 
Print this post

  cosmic frog said   Ok, just tried this again to make sure.
In the editor I have-

PWM 1,950,50

I get nothing from the speaker and nothing on my multimeter.

If I have this in the editor-

Setpin 4,dout
PWM 1,950,50

I can hear a beeeep sound and the multimeter shows around 1.5volts

Even if I type in PWM 1,950,50 directly and not in the editor I get nothing.
I am using a Pic32mx170 and the latest firmware.

Dave.

Thanks Dave,

While the MX150 and MX170 chips should be the same (except for memory) it appears that this is not so. It seems that the MX170 PWM hardware on the chip requires that the PWM output pin be specifically set to an output.

Until I get out another version the workaround (on the MX170 chips only) is to add a SETPIN for each PWM output.

Geoff
Geoff Graham - http://geoffg.net
 
hitsware
Guru

Joined: 23/11/2012
Location: United States
Posts: 535
Posted: 04:12am 27 Sep 2014
Copy link to clipboard 
Print this post

> So far I have not seen any problems on the CRO but this
> is something that probably needs audio to listen to.

For sure. Listening to these things is infinitely more
reveiling than a scope .
Here's a simpler snippet that shows the problem nicely.
( Listen with the 'PWM 1, stop' reminded vs active )


Do
PWM 1, stop
n=Int(Rnd*400)+100
PWM 1,n,50,50
Pause 400
Loop


> I know you gave the circuit you are using but I cannot
> find the post.

All PWM pins tied to a common point ( audio out ) through 15 k Ohm
COM pin tied to the same point through 3.3 k Ohm
The values are not important at all. Just the ratios.
( The COM pin gives only a short burst that needs
amplitude to be perceptably loud enough )

> I changed mid: to middle: because MID is too close to a
> keyword for my liking.

Good idea .... I'll follow suit . Edited by hitsware 2014-09-28
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024