Show Posts
Pages: [1]
1  Development / Other Software Development / Re: PWM frequency library on: September 24, 2012, 04:31:29 pm
Quote
if I do a pwmWrite(10, 2000), I get a Duty cycle of 81.6% in this logic analyzer

That's because the acceptable range for pwmWrite() is 0 - 255, or one unsigned 8 bit integer. You are truncating that int many times over with that second parameter and getting a junk duty cycle as a result.
pwmWrite() parameters are meant to mimic analogWrite() parameters. If you need more resolution, use pwmWriteHR(). It is described earlier in this thread.

This fix should solve your frequency issues, I still have no answer for the test program resolution issue. My Mega, my Uno, and Atmel studio simulators have no problem with it.

The latest version of the library as of this post is v .05. You can download it here:
https://code.google.com/p/arduino-pwm-frequency-library/downloads/list

Ahh, yeah I was thinking about that while I was at work. Forgot to use the HR version. Didn't realize it was 0-255 for lower resolution frequencies as well. I'll try it out and add some results here in a bit.

Thanks again for your efforts.

Update:
Still have the 0 resolution problem on Timer2, and after looking at your code I assume there has to be some offset mismatch specific to this nano for some reason. No big deal though since I am getting the output I need: http://i.imgur.com/iwFcl.png . Both signals behaving as expected.
2  Development / Other Software Development / Re: PWM frequency library on: September 23, 2012, 10:24:56 pm
Yay integer division!
...ehem

I found the bug, I will publish the patch tomorrow afternoon after I have more time to test it.
All 8 bit timers will be set to higher than expected frequencies when set to high frequencies (go figure). I haven't actually checked myself, but according to rothnic the threshold is somewhere between 15KHz and 16KHz.
Due to the nature of the this particular bug, it should not affect PWM duty, only frequency.
Again, I have no idea what is causing that bad resolution reading, my Mega and Uno have no trouble with it.

Sounds good.

Right now I have the 2kHz frequency working ok, but there is an issue with the duty cycle. This is on the 16bit Timer, so with it set at 2kHz it returns 4000 from the Timer1_GetTop call. But, if I do a pwmWrite(10, 2000), I get a Duty cycle of 81.6% in this logic analyzer. This makes me doubt the hardware a bit.

I guess in the end I can get it working with a little trial and error, worst case. Looks like pwmWrite(10, 5000) gets me pretty close to 50%.
3  Development / Other Software Development / Re: PWM frequency library on: September 23, 2012, 08:21:44 pm
I was able to reproduce the frequency errors for timer 2 and timer 1 (55555 when set to 20000 and 31620 and 15.7K) in Atmel Studio. Sounds like a truncation issue. I was not able to reproduce the resolution errors. I ran the code test code on my Uno and Atmel Studio it looks clean.

I might have something tomorrow afternoon (east coast USA time) for the frequency problem, I will keep looking into the resolution problem.

Thanks, yeah not sure what is going on with the resolution reporting. I'll keep messing with it.

I did find a nice little free logic analyzer that hooks up to an arduino to test this stuff out. I confirmed that I'm seeing 2kHz on Timer1(Pin 10), and 55.556kHz on Timer2(Pin 3). http://i.imgur.com/aRGS8.png

If anyone comes across this and wants to check their PWM signals out, try this: http://letsmakerobots.com/node/31422 . I'm running it no problems with my Mega, but needed to use version 0.9.5 of the analyzer for it to work with the Arduino plugin.
4  Development / Other Software Development / Re: PWM frequency library on: September 23, 2012, 12:30:07 pm
This library looks to be a huge help, really appreciate the time. It really is silly that something doesn't exist like this with the stock set of libraries.

I have one issue I'm having getting started with it, that I could use some help on. I'm using a Nano v3, so basically the same thing as an Uno. Pins 5 and 6 associated with Timer 0, Pins 9 and 10 associated with Timer 1, Pins 3 and 11 associated with Timer 2.

I'm building a circuit that will manually control a Honda Insight's hybrid system. This is controlled by 3 control lines, with 2 of them being PWM signals with varying duty cycles. 1 needs to be 20kHz, and the other 2kHz. Therefor, the plan is to use Timer 1 and Timer 2.

When looking for a successful Frequency setting on the Timers, I believe I need to use Pins 10 and 3 on the respective timers. If I use 11 instead of 3, I do not get success for setting the frequency. The issue comes when I make the call to check the resolution of each pin.

Pin 10 (set at 20kHz) returns a resolution of 8.65
Pin 3 (set at 2kHz) returns a resolution of 0.00

If I reverse the pins:

Pin 10 (2kHz) returns a resolution 11.97
Pin 3 (20kHz) returns a resolution of 0.00

What would cause the 0 resolution on Timer 2?

EDIT:
Just checked and Timer 2 provides a frequency of 55555Hz after setting it at 20kHz. I played around with it and when setting it around 15kHz, it outputs almost correctly, except it returns slightly higher than set. Whenever I set it any higher than 15.7kHz, it starts reporting over double of what the set value is. For example, at 15.7kHz, it returns 31620Hz.

A pastebin of the output from your resolution example, with the pin changed to pin 3 and output from Timer2: http://pastebin.com/8vgj6ZBn

I was able to get your frequency method to report 20k, by setting this up manually:

Code:
  TCCR2A = _BV(COM2A0) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20);
  TCCR2B = _BV(WGM22) | _BV(CS21);
  OCR2A = 50;
  OCR2B = 25;

The resolution is still reported as 0, but reports possible duties of 51.
5  Forum 2005-2010 (read only) / Troubleshooting / Re: Vista "Error getting the Arduino data folder. on: February 25, 2009, 11:59:30 pm
I'm having this same problem with 32bit Vista. Tried as admin, in xp mode, and versions 0013 and 0012.

As quickly as I post this I finally figure it out.

Open in your arduino-00## folder, the preferences file in a text editor. Then find the line settings.path.fallback=data, and comment it out. On the line above, uncomment settings.path=data, and make it look like the following:

settings.path=c:\Users\*User*\AppData\Local\Arduino
Pages: [1]