[Microbit-Python] Which pins can cope with a 35 micro second pwm?

Andrew Stacey loopspace at mathforge.org
Tue Feb 14 16:11:41 EST 2017


Thanks.

I've hooked up a microbit to a Lego Mindstorms RCX2.0 block via one of 
the sensor ports.  The RCX brick reads the voltage across the port.  It 
can read between 0V and 5V, split into 1024 segments.  By switching the 
voltage on a pin, I can switch between two values.  I had hoped that by 
using PWM, I could get values in between, but for that to work then the 
switching period on the microbit would have to be faster than the 
sampling period of the RCX, and that is about 3ms.

(I'm not convinced that this would work anyway, and throwing a low pass 
filter into the circuit might be the proper answer, but in trying it I 
came across the fact that pin1.set_analog_period_microseconds() wouldn't 
take a value lower than 1000 so thought I'd ask about it.)

Andrew

On 14/02/2017 20:36, Mark Shannon wrote:
> Hi Andrew,
>
> For PWM there is only one period. All the pins use the same period, but
> their duty cycles can differ. This is a hardware limit (there aren't
> enough clocks to do otherwise). You can use any of the pins with PWM.
>
> The minimum PWM period is 256µs. It is longer than the DAL variant, as
> we use the internal clock for the audio module (needed for speech).
> I can't remember why exactly why 256? I suspect that it is short enough
> for music and long enough to be reliable.
> How low a period do you need? 256µs isn't very long.
>
> Cheers,
> Mark.
>
> On 14/02/17 18:29, Andrew Stacey wrote:
>> I'm not quite clear from the docs which pins can cope with the minimum
>> pwm speed.  I just tried with pin1 and couldn't set it below 1000
>> microseconds, but I notice from the relevant doc page
>> (https://microbit-micropython.readthedocs.io/en/latest/pin.html) that
>> only some pins are listed as "analog" (3,4,10).  Is it only those that
>> can go down to 35?
>>
>> Thanks,
>> Andrew
>> _______________________________________________
>> Microbit mailing list
>> Microbit at python.org
>> https://mail.python.org/mailman/listinfo/microbit
> _______________________________________________
> Microbit mailing list
> Microbit at python.org
> https://mail.python.org/mailman/listinfo/microbit



More information about the Microbit mailing list