Generate Clock

02 Jan 2011

Hi,

I'm new to mbed and try to create a clock signal on pin p7

First try:

DigitalInOut Clock(p7);

void main()
{
...
Clock.output();

while(1)
{
       Clock.write(0);
       wait_us(4);
       Clock.write(1);
       wait_us(4);
}

}

but there is no reaction on p7 to see with an oszi.

Second try:

void clocktick()
{
    Clock = !Clock;
}

void main()
{
    Ticker ticker;
    ticker.attach_us(clocktick, 4);    

    while(1)
    {
    ;
    }
}

But this has also no effect on p7.

Is something missing?

Thx

Update:

if I use DigtalOut it works! But why does DigtalInOut not work for that ???

02 Jan 2011

it works with onboard led

#include "mbed.h"
DigitalInOut Clock(LED1);
main()
{
Clock.output();
while(1)
 {
       Clock.write(0);
       wait_ms(500);
       Clock.write(1);
       wait_ms(500);
 }
}

also this works too:

#include "mbed.h"
DigitalInOut Clock(LED1);

void clocktick()
{
    Clock = !Clock;
}
 main()
{ Clock.output();
    Ticker ticker;
    ticker.attach(clocktick,1 );   

    while(1)
    {
    ;
    }
}

Except that I don't know what's behind "..." on first example and you forgot to set output on the second example .. nothing's wrong.

See that if your p7 is ok .. try another pin.

Anyway if you don't need input on this clock ... it may be more elegant to use pwm output instead for generating clock.

08 Jan 2011

Stefan Mueller wrote:

Hi,

I'm new to mbed and try to create a clock signal on pin p7

First try:

DigitalInOut Clock(p7);

void main()
{
...
Clock.output();

while(1)
{
       Clock.write(0);
       wait_us(4);
       Clock.write(1);
       wait_us(4);
}

}

but there is no reaction on p7 to see with an oszi.

Second try:

void clocktick()
{
    Clock = !Clock;
}

void main()
{
    Ticker ticker;
    ticker.attach_us(clocktick, 4);    

    while(1)
    {
    ;
    }
}

But this has also no effect on p7.

Is something missing?

Thx

Update:

if I use DigtalOut it works! But why does DigtalInOut not work for that ???

You probably need to set the ping to output-mode first:

Clock.output();

will probably do the trick Louis