In order to successfully transmit IR codes you need to be able to generate a 38 KHz square wave (possibly 36 kHz for some devices) and then turn that square wave on and off at precise intervals.
All PWM on galileo is done via the cypress chip, so it's slow and the timing is non-deterministic. Therefore the approach I'd take is to select one of the PWM channels and set it running at 38 kHz. Then I'd select and deselect the MUX on the selected pin to generate the mark/space (on/off) timings.
I Can't test this for now, so its all theoretical.
Sorry for the delay in my response
So I think I have a better understanding of what needs to be done but I have a few more questions:
- How do I know the frequency of the PWM pins?
- Do all PWM pins have the same frequency?
- Is it possible to test what frequency is being outputted?
- Do I use digital write? Analogue write?
- If using the PWM I assume I would be use analogueWrite() function?
Here's what I'm thinking:
For the first part of the command pulse, the signal is on for 2mS and off for 28mS.
// Psudo code:
// Set Frequency - assuming 62.5KHz:
// (62.5 / 2) = 31250KHz
Let me know what you think and thanks again for the help!
Just to follow up on this:
I didn't use the PWM for this project, I chose to use the GPIO 2 pin set up with pinMode(OUTPUT_FAST) to create a 477KHz clock.
Using this clock I created a 38KHz square wave and generate the required pulse train needed to send the command to my camera.
I borrowed a Saleae Logic Analyzer (which is a fantastic piece of gear!) and got the following results.
GPIO output using pinMode(OUTPUT_FAST):
Square wave used to create 38.4KHz carrier wave:
The following communities post is very helpful:
Here is a full blog post about it:
I've gone through the example code given in the above post by deckard026354 and graphed the output of each.
I'll update this thread with my results and give a full write up in the blog above.
I borrowed a Saleae Logic Analyzer (which is a fantastic piece of gear!)
Indeed it is, apart from the silly name. There is a new version of their software 'Logic' coming out tomorrow too.
I'm intrigued... how did you create the 477 kHz Clock, and how did you then divide that down to 38.4 kHz?
What will you use to switch on/off the 38.4 kHz carrier?
I've created a blog post about creating the clock pulse:
I intend to do a complete write up on the build process.
I may even be able to port this to other makes of SLR cameras.
I read your blog post - nice work, some great stuff there!
I think that the output frequency will suffer from a bit of good old fashioned jitter though, as the timing is non-deterministic.
That's because the galileo Sketch does not have exclusive access to the CPU, so the cpu may well (and in fact does!) suspend your thread to do other things many times a second.
The priority of your thread and it's timing cannot be calculated or determined, or relied on. The kernel may adjust your process's priority and schedule at any time.
I wonder why you didn't just make use of PWM to drive a fixed frequency signal without any chance of jitter?
For the purpose of this project, reliability shouldn't be an issue - I'll only be sending a pulse train to capture a picture.
With regards to the PWM, I'm having a lot of trouble finding out how to program them correctly from the Arduino IDE.
But you've raised an interesting point: In more timing sensitive projects, should you be programming from the Arduino IDE, or directly controlling the GPIO / PWM in the Linux environment?
You can do both!
Since everything in Linux (pretty much) has a file interface you can use basic system() commands to do just about anything linux from within Arduino sketches.
You can set up PWM period and duty cycle, route the MUX to the correct pin and start/stop the PWM all from within Arduino, or directly from Linux.
I've got this running now and created a blog post about it here:
Using the GPIO information above, I was able to:
- Create a 38.4KHz clock pulse.
- Toggle the clock on and off to create a binary signal.
- Recreate the full command signal:
I written the code in such a way, it should be easily portable to any other cameras, the command pulses are in the link in my OP.