occam-pi

Exploration: PWM in Software – Part II

Posted in PWM, arduino, occam-pi on October 19th, 2009 by Radu – Be the first to comment

The last implementation proved to be very slow, so an obvious improvement was to eliminate the ticker; i.e. the dependence on the clock for synchronization. By removing the ticker process we ensure that PWM will run as fast as the virtual machine is. Here is the updated diagram:

PWM in Software (No Clock)

PWM in Software (No Clock)

When tested, this implementation runs quite a bit faster – the LED actually gives an impression of dimming. But upon plugging a speaker into the same pin we get a definite “buzzing” noice, when the desired effect is more like a nice sound. Hence, still not fast enough. It is therefore time to read the Arduino data sheet and find out how to do it in hardware.

Exploration: PWM in Software – Part I

Posted in PWM, arduino, occam-pi on October 19th, 2009 by Radu – Be the first to comment

In this post I will be referring to Pulse Width Modulation as PWM, which you can read about more here.

Since before I started working on this project I did not know anything about PWM, I did a bit of reading on-line and without getting into too much technical detail I started coding it as it first came to mind. The graph below is what I came up with.

PWM in Software

PWM in Software

The diagram abobe shows five parallel processes:

  • ticker controls the rate at which sine, and saw and control operate. It also dictates the rate at which control operates, although not necessary;
  • saw and sine are just two oscillating functions, the difference being that sine has a constant increment, while saw has its increment dependent on the level you want to do PWM; since they have different increment / decrement rates, they intersect at rates dependent on the level you pass to saw;
  • control reads the values from saw and sine and if they crossed sends a signal to switch;
  • switch upon receiving a signal flips the power on or off.

This implementation, even though very ugly, does what it is supposed to do, almost. By almost I mean it modulates the pulse, but the modulation is not fast enough to give an impression of dimming an LED. That is, the LED appears to just blink at a fast rate, but to actually achieve PWM as it is supposed to be, we would need a much faster virtual machine.

Stepping Onto The Platform

Posted in arduino, occam-pi on September 28th, 2009 by Radu – Be the first to comment

As the title might suggest, this post is about me getting familiar with the Occam concurrent programming language and the Arduino.

Occam runs on the Arduino by means of the Transterpreter VM. So my first little project was to get the development environment set up, get the code to cross-compile, and write a little blink program that would cause an LED to…, well, blink. Here is a process diagram:

PROC blinkNot a terribly complicated exercise, but got my feet wet. So, tick is being awakened by the system every ms milliseconds at which point it sends a signal to toggle. Upon receiving it’s signal, toggle flips the level it has on record and sends it to led. Then led just does a digital write on the pin it monitors. This is the magic of blink.