little pwm - adc quest

THE_RB

Joined Feb 11, 2008
5,438
Actually there ARE 8 note spacings; A-G (then back to A is the 8th step). Then there are those sharps and flats thingies.

It's not musicians that are to blame it's those ridiculous piano players with their white "good" notes and black "bad" notes on their silly keyboards. It even influenced the way music is notated on paper which has been ridiculous since the dawn of written music.

Of course REAL musicians (like guitarists) know that there are exactly 12 perfectly spaced equal semitones, and we have neat little frets on our perfectly neat fretboards where all the REAL notes are made and can be transposed perfectly.

If it was up to me I would rename the 12 real notes A-L and be done with it. Sharps, flats, hmmf. What a bunch or morons. ;)
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
I am using timer0 to initiate conversion...

Now I am wondering which rate would be better? coz I am thinking....assuming smallest frequency 200Hz -> 5ms to complete its period...so if conversion is initiated every 1.024ms...the smallest frequency will never complete its period.! am I correct?
or it just doesn't matter?

I don't know if it makes sense but I hope it does!

Thanks!

[edited] Well I came uo with a solution that I don't really like but ima give it a try
 
Last edited:

Markd77

Joined Sep 7, 2009
2,806
It doesn't really matter if a few cycles go by in between ADC reads. 1ms in between moving the knob and hearing the result is fast enough. It will seem instantaneous.
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
I am actually extending the code to 32 s*o*u*n*d*s....but an attached is what I have for now...

Have a look at the code and see there's anything wrong or illogical...

[edited] I think I have a problem! only one sound and does not respond to pot.

what's wrong?

thanks

[attachment edited] but still not working
 

Attachments

Last edited:

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
I just edited my attachment but it still not working...only have one sound when i vary voltage with the pot.

any help?:(
 

Markd77

Joined Sep 7, 2009
2,806
Without simulating, I can't see anything obvious. As a first check I'd recommend putting a loop in main which sits there checking if resultl is greater than 16 and lights an LED if it is. That way you can see if the timer0 and ADC interrupts are working properly. I'm not sure why you are checking for timer2 overflows, is that necessary?
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
Thanks for your comment!

Would you please simulate it for me...Still dont know how to simulate and I can't see where I went wrong...but I'll check again and taking ur suggestion into consideration!
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
my idea was to allow each sound to complete at leasr one period!...that the answer to ur question about the timer2 overflow checking...

Im thinking now if it necessary...

Also do you mean ...while trying to blink that led I should ignore/comment the current 'prosound' function, right?

thanks
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
:D:D:D:D:D I figured out the problem!!!!!!!!!!!

It works now!!!!

I'll tell what the problem was i a minute!!

actually it was in the interrupt checking

[edited] but sometimes it stop working...
 
Last edited:

Markd77

Joined Sep 7, 2009
2,806
If the resultl is greater than the filled in part of the prosound table, that is going to cause problems. If you put "return" in for the unfilled part for testing that should help.
To reduce code size you can replace all the pssnd calls with a single function. Put the PR2 values in the table, CCPR1L is just PR2 shifted to the right, then you just have to set the prescaler according to the size of resultl.
 

shortbus

Joined Sep 30, 2009
10,045
I hope you guys don't mind a dumb question. Been following this thread, and the one thing from the very start that has been bothering me is - How does changing pulse width(PWM) change the frequency?

Isn't the pulse width completely different than the frequency? The PWM I'm familiar with is not frequency. Always thought PWM frequency was the "carrier" frequency. Please help an old dumb guy here. :)
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
If the resultl is greater than the filled in part of the prosound table, that is going to cause problems. If you put "return" in for the unfilled part for testing that should help.
Yes you are correct!

To reduce code size you can replace all the pssnd calls with a single function. Put the PR2 values in the table, CCPR1L is just PR2 shifted to the right, then you just have to set the prescaler according to the size of resultl.
Yes yes yes!!!

The code size is *ugly* I thinking of reducing it into a *single* one as you suggested!

T2CON is the same for all frequencies; CCPR1L is obtained from PR2

About CCP1CON! trying to see if it we can have one for all frequencies too!!

Most importantly, the *frequencies themselves* they sound ugly and in a *loop* manner...but I think I understand! its due to the way I initially chose them!

I'm thinking if choosing them in an *evenly spaced* manner would make it sound like a siren with 32 different sounds!!

thanks
 
Last edited:

Markd77

Joined Sep 7, 2009
2,806
I hope you guys don't mind a dumb question. Been following this thread, and the one thing from the very start that has been bothering me is - How does changing pulse width(PWM) change the frequency?

Isn't the pulse width completely different than the frequency? The PWM I'm familiar with is not frequency. Always thought PWM frequency was the "carrier" frequency. Please help an old dumb guy here. :)
Yes it's the frequency that is changing, the duty cycle stays the same. He's using the PWM module of the PIC to do it, and we've probably been a bit casual with the terminology.
 

Markd77

Joined Sep 7, 2009
2,806
Yes yes yes!!!
I'm thinking if choosing them in an *evenly spaced* manner would make it sound like a siren with 32 different sounds!!s
Maybe, to make them sound evenly spaced each note should be a fixed percentage higher than the last one. Try a few percentages in a spreadsheet until you find the one that gives the overall range you want.
 

ErnieM

Joined Apr 24, 2011
8,377
Maybe, to make them sound evenly spaced each note should be a fixed percentage higher than the last one. Try a few percentages in a spreadsheet until you find the one that gives the overall range you want.
If you look at a piano keyboard and count the keys from any key to before then next similar key (like the white key to the left of 3 black keys) you will find there are 12 keys or notes. The similar keys denote an octave, and an octave is a doubling of frequency.

Note a scale uses 8 notes as it ignores the 5 "sharps and flats" (the black keys) which is why it is called an octave. But there are evenly 12 notes in an octave interval.

They are spaced the 12th root of 2 apart, as the space to the 12th power is 2.

So each note is approximately 1.0594630943592952645618252949463 times higher in frequency then the previous one.


What do you think of these *evenly spaced* frequencies!!?

Would that generate 32 *different* s*o*u*n*d*s*??:)
Sorry, I don't read large portions of assembly. :D
 

Markd77

Joined Sep 7, 2009
2,806
The low notes would sound very widely spaced, and the higher ones close together.
Try this formula instead for a5 downwards:
=(A4 *$A$1)
and put 1.088 in cell A1, change if required, they will sound evenly spaced.
 
Top