8 years, 5 months ago.

Using PWM varying period 58us and 100us

Hi Forum

I am new to micro controllers, so please excuse what could be a basic question.

I want to try to use my mbed to communicate to my model trains by generating a DCC signal (http://en.wikipedia.org/wiki/Digital_Command_Control). The DCC signal uses PWM to generate signal that encodes zero (100us) and ones (58us) by varying the PWM period.

I have started reading the PWM examples on mbed.com, but I cannot see how I can vary the period generate a one (58us) and zero (100us).

I have started to read the NPC document and found the MR0-MR7 counters.

But before trying this I would like advice on the best way to acheive what I want.

Thanks

Stuart

Hi Stuart, i am also working on a DCC Throttle with mbed but did not succeed generating a DCC Signal. Did you have more luck ?

posted by voy ager 25 Jun 2013

2 Answers

8 years, 5 months ago.

Which board are you using? But you will be better of using just a DigitalOut that you flip. If not much else is running on your board at the same time you can just use the normal mbed libs with for example TimeOut and DigitalOut. If it needs to be efficient you are most likely best off by using a seperate timer.

PWM is normally used to have a relative constant frequency over many periods. Sure sometimes the period can be changed in the application, but in DCC the period is changed everytime you want to transmit a different bit.

the mbed board with cortex m3.

I will have a look at the DigitalOut.

posted by Stuart Norris 08 Jun 2013
8 years, 3 months ago.

http://mbed.org/users/4180_1/notebook/controlling-a-model-railroad-using-mbed/ has some code examples that I just posted.