BasicMicro - Forums

www.basicmicro.com
It is currently Sun May 20, 2012 11:10 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: HPWM help will be greatly appreciated
PostPosted: Fri Nov 13, 2009 9:28 pm 
Offline
Citizen

Joined: Fri Nov 13, 2009 9:07 pm
Posts: 19
Location: Antioch, CA
I am brand new to the BasicATOM so please overlook my ignorance.

I am attempting to run the sample code shown on pages 141 and 142 of the manula under the HPWM topic. It fails on the CCP2CON=0 line. I have searched the manual and this is the only place wher CCP2 or CCP@CON are mentioned. I am trying to understand what this is and how it works? Any and all help will be greatly appreciated.

_________________
James M. "Jim" Geidl, K6JMG
www.spinochio.com

No trees were harmed in the sending of this message; however, a large number of electrons were terribly inconvenienced.

//


Top
 Profile  
 
 Post subject: Re: HPWM help will be greatly appreciated
PostPosted: Sat Nov 14, 2009 2:34 am 
Offline
Master

Joined: Sun Aug 17, 2008 5:26 pm
Posts: 798
Location: CA bay Area
The compiler has been revamped in several ways and the manuals haven't always kept up. I posted a demo for HPWM in the Nano section, which should work for you too. Here is the post address:
http://forums.basicmicro.com/viewtopic.php?f=485&t=9127&p=41014&hilit=hpwm#p41014
Take care.

_________________
kenjj
http://blog.basicmicro.com/
http://kjennejohn.wordpress.com/


Top
 Profile  
 
 Post subject: Re: HPWM help will be greatly appreciated
PostPosted: Sat Nov 14, 2009 10:39 am 
Offline
Citizen

Joined: Fri Nov 13, 2009 9:07 pm
Posts: 19
Location: Antioch, CA
kenjj,

Thanks. I have done about what you have in your example to get my motors running but wanted to know what the ccp2 and ccp2con meant, if anything in the latest revs.

Your comments about the manuals makes me very very nervious. All I need is a device with outdated manuals and information!

_________________
James M. "Jim" Geidl, K6JMG
www.spinochio.com

No trees were harmed in the sending of this message; however, a large number of electrons were terribly inconvenienced.

//


Top
 Profile  
 
 Post subject: Re: HPWM help will be greatly appreciated
PostPosted: Sat Nov 14, 2009 2:26 pm 
Offline
Master

Joined: Sun Aug 17, 2008 5:26 pm
Posts: 798
Location: CA bay Area
Ahh, well, The CCP part means C(ount)C(ompare)P(WM, for Pulse Width Modulation). CCP2 and CCP2CON(trol) are the registers that control use and function of a set of registers that allow the processor to do clocking, count pulses, compare pulse numbers over a period of time, and generate pulses. All this happens on its own after the processor sets them up at the beginning to do the job. This leaves the processor free to do other things until an interrupt comes in and leads it to do something with these registers, like read the contents and restart or reset the values. There are two sets of these, CCP1 and CCP2. CCP1 is "enhanced". The PWM part is typically used to control motors and light or LED brightness. It generates signals of varying frequencies and pulse widths, which in turn determine the amount of power delivered.

Here is the URL to the PIC's data sheet:
http://www.engr.usask.ca/classes/EE/391/notes/PIC16F886.pdf
Go to page 125. The relevant section is over 25 pages, so pour a cup of coffee first.
Take care.

_________________
kenjj
http://blog.basicmicro.com/
http://kjennejohn.wordpress.com/


Top
 Profile  
 
 Post subject: Re: HPWM help will be greatly appreciated
PostPosted: Sat Nov 14, 2009 8:43 pm 
Offline
Citizen

Joined: Fri Nov 13, 2009 9:07 pm
Posts: 19
Location: Antioch, CA
Perhaps there are other things I need to know worse. :mrgreen:

_________________
James M. "Jim" Geidl, K6JMG
www.spinochio.com

No trees were harmed in the sending of this message; however, a large number of electrons were terribly inconvenienced.

//


Top
 Profile  
 
 Post subject: Re: HPWM help will be greatly appreciated
PostPosted: Sun Nov 15, 2009 11:53 am 
Offline
Citizen

Joined: Fri Nov 13, 2009 9:07 pm
Posts: 19
Location: Antioch, CA
Kenjj,


I tried your example and got the following errors:
Error: PWM TEST 2.BAS(LINE 6) : [TOKEN PER] : Redefining to Variable
Error: PWM TEST 2.BAS(LINE 7) : [TOKEN PER] : Redefining to Variable
Error: PWM TEST 2.BAS(LINE 10) : [TOKEN PER] : Redefining to Variable
Error: PWM TEST 2.BAS(LINE 16) : [TOKEN PER] : Redefining to Variable

For reference, line 1 in my test is the following line from your code sample:

sel1 con 10 ; this is the first hardware pwm channel. This is on P10. "0" works too.

_________________
James M. "Jim" Geidl, K6JMG
www.spinochio.com

No trees were harmed in the sending of this message; however, a large number of electrons were terribly inconvenienced.

//


Top
 Profile  
 
 Post subject: Re: HPWM help will be greatly appreciated
PostPosted: Sun Nov 15, 2009 6:11 pm 
Offline
Master

Joined: Sun Aug 17, 2008 5:26 pm
Posts: 798
Location: CA bay Area
This was double-posted. Please don't do that. It got answered by KurtE in another place, and so people will miss the answer when it comes.
KurtE pointed out that "per" is a reserved word and so the compiler won't accept it at build or program time. I corrected this in the demo code in the Nano section and it now works, except for a problem discovered with the Nano18.
My bad. I should have tested the original code before posting it, even though it came from working code with different variable names.
Take care.

_________________
kenjj
http://blog.basicmicro.com/
http://kjennejohn.wordpress.com/


Top
 Profile  
 
 Post subject: Re: HPWM help will be greatly appreciated
PostPosted: Sun Nov 15, 2009 6:33 pm 
Offline
Citizen

Joined: Fri Nov 13, 2009 9:07 pm
Posts: 19
Location: Antioch, CA
Sorry, I didn't realize that both posting were on the same forum. I made the suggested changes and it works fine now.

Thanks,

_________________
James M. "Jim" Geidl, K6JMG
www.spinochio.com

No trees were harmed in the sending of this message; however, a large number of electrons were terribly inconvenienced.

//


Top
 Profile  
 
 Post subject: Re: HPWM help will be greatly appreciated
PostPosted: Sun Nov 15, 2009 9:10 pm 
Offline
Citizen

Joined: Fri Nov 13, 2009 9:07 pm
Posts: 19
Location: Antioch, CA
kenjj,

Sorry you got yourself into this yet? :-)

Another question. I am using an AtomPro. The manual states that the clock is 16MHz. Using this number if have done the following calculations and am unsure how you arrive at the 83KHz signal that you state in the line of code here:

for per_iod = 100 to 9100 step 500 ; set period value in FOR-NEXT loop, starts with 83KHz signal

1 / 16000000 = 0.0000000625 period
0.0000000625 * 100 = 0.00000625 ;the 100 here is the starting point in your code for the FOR loop
1 / 0.00000625 = 160KHz

Where am I going wrong here?

Thanks

_________________
James M. "Jim" Geidl, K6JMG
www.spinochio.com

No trees were harmed in the sending of this message; however, a large number of electrons were terribly inconvenienced.

//


Top
 Profile  
 
 Post subject: Re: HPWM help will be greatly appreciated
PostPosted: Sun Nov 15, 2009 10:10 pm 
Offline
Master

Joined: Sun Aug 17, 2008 5:26 pm
Posts: 798
Location: CA bay Area
You're not wrong. That value holds true if you're using a period value of 100 with any Nano, which runs at 8MHz, which the code was written for originally. And there is the problem with Studio's universal code. The code runs on any Atom part, but the values given and achieved can differ between devices. The standard Basic Atom runs at 20MHz, for both interperter chips and modules. 24-pin and 28-pin Pro modules run at 16MHz, while the Pro40 module runs at 20MHz.
Which is why the Universal manual needs to come out. But I no longer have the inside contact I once enjoyed to find out when that will happen. So you'll have to start an email campaign to convince them to follow through. Or to start a seperate Atom/Nano manual. Or lean on Andrew at AdvancedMicroCircuits(.com) to finish his Nano book.
Or yah'll can post questions here and get answers willy nilly, where needed, as needed.
Or I could do an HPWM tutorial that covered ALL the Atom types. Except the forums aren't doing uploads just now.
Pfft.
BTW, if the Nano's 8MHz clock was right on, and the HPWM algorithm was absolutely correct, and the frequency counter on my o-scope was perfect, the period value of 100 would produce an 80KHz output. But I get either 83KHz or 78KHz, depending on sweep speed. Your output may vary.
Later.

_________________
kenjj
http://blog.basicmicro.com/
http://kjennejohn.wordpress.com/


Top
 Profile  
 
 Post subject: Re: HPWM help will be greatly appreciated
PostPosted: Mon Nov 16, 2009 9:05 am 
Offline
Citizen

Joined: Fri Nov 13, 2009 9:07 pm
Posts: 19
Location: Antioch, CA
Kenjj,

Perfect! Makes complete sense now.

Thanks

_________________
James M. "Jim" Geidl, K6JMG
www.spinochio.com

No trees were harmed in the sending of this message; however, a large number of electrons were terribly inconvenienced.

//


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO