Maybe the Next Release

Bill z

Member
Recently I wrote a 08M2 program using the Picaxe Editor that would do 1 of 3 things depending on voltage supplied to pin C.3. Picaxe editor doesn’t have an option to allow for anything except on and off even though the 08M2 will allow and respond to various input voltages. If the editor does have such a feature, me being new to using it, couldn't find it.

A simple slide bar icon would work to enhance this great editor.

Also, I was trying to test the pwmduty command but the C.2 only shows one brightness. Maybe various shades of yellow, oranges to red would work for brightness.

Moved to Active Forum ec
 
Last edited by a moderator:

AllyCat

Senior Member
Hi,
Recently I wrote a 08M2 program using the Picaxe Editor that would do 1 of 3 things depending on voltage supplied to pin C.3. Picaxe editor doesn’t have an option to allow for anything except on and off even though the 08M2 will allow and respond to various input voltages.
Leg4 (c.3) on the base PIC for the 08M2 is a "Digital Input Only" pin (because it's primarily a Master Reset / Programming Input) so there's no way that the PE can read an ADC level on that pin. What you could do is connect the pin to either ground or to the supply rail (preferably via a low-valued resistor for safety) or via a high-valued resistor (around 100k) to ground (to indicate the 3rd state). Then, if the program detects a Low (0), it enables the internal "Weak Pullup Resistor" (PULLUP 8) and if the input changes to a "1", then the external resistor must be a high value (the internal weak pullup is about 30k). Then disable the WPU with a PULLUP 0 (or OFF).

Alternatively, it is possible to read an ADC value on the "Output Only" Leg 7 (pin C.0) of the 08/14M2s, by using the READDAC command. But beware that that pin will always default to an active Output (not Tri-stated like other pins) when the Program starts, until the program sets it as an input.

Cheers, Alan.
 

Bill z

Member
AllyCat,

Thanks for the quick reply.

Yes, my bad about variable voltage on C.3. That was a hasty written message. I was using a reverse LED to monitor light where the LED anode connected to C.4 and cathode connected to C.3. This does work somewhat when connected. Voltage does change and is seen but the editor doesn't have a way to simulate

What about the second point where PWM could be displayed on the editor Digital display simulator some way using colors or brightness.
 

Flenser

Senior Member
Bill,

I'm familiar with the technique of using a LED as a light sensor. You can use a normal input pin to do this. It does not need to be an ADC pin.

I have posted a project with example code that does this: Using a LED as a Light Sensor - Example Program and I see now that a couple of other members have posted to my project their code that do a variation on this.

A normal pin does detect the voltage but it it only detects one voltage level. If the voltage is above this level the input value is a "1" and if it is below this level the input value is a "0". The trick to using a normal input pin is to measure how long it takes for the input value to drop from a "1" to a "0".
i.e. to measure a time duration value instead of an ADC voltage value and using that measured value to identify the difference in the brightness of the light shining on the LED.

PE cannot simulate how long it takes the voltage in the LED to drop so I'm not aware of any way you could simulate in PE the time it takes the LED internal diode to discharge through the input pin resistance.
 

AllyCat

Senior Member
Hi,

Yes, that's also been discussed in another of the OP's threads.
What about the second point where PWM could be displayed on the editor Digital display simulator some way using colors or brightness.
Oh dear, where to start. I'm certainly not a Windows system programmer, so can't say if it would be even possible, but often the "Colour Palette" is quite limited. The PWM hardware output has 1024 possible "levels", so even if using a "logarithmic" brightness scale you'd need 10 levels (one for each significant bit). The Font Editor appears to have about 140 "arbitrary" colours, so I think you might struggle to find a logical sequence of even 10 "brightness" levels.

But controlling the brightness of a LED is only one (quite trivial) application of many that might use PWM. Fundamentally it's a pulse output so the frequency might be just as important as the duty cycle (or more so), for example as an Audio (tone) generator if a loudspeaker were attached instead of a LED. Also, the "simulator" normally runs much slower than "real time", so it would be more logical for the pin to "flash" than to "dim". And of course the PICaxe PIN (which is being simulated) doesn't itself emit light (just a voltage / current), it doesn't even output an analogue (variable) level, unless you add a low-pass filter.

Finally, the PWMOUT / DUTY commands set up a (background) hardware function, which continues independently of the program itself, even after the program might have stopped (or perhaps crashed). However, the PE "Simulator" is a (program) software emulator, AFAIK it doesn't simulate ANY of the Special Function Registers (SFRs) of which the PWM control registers are just a subset. But even if (some of) those registers were emulated in the software (and there are plenty that might be quite useful), that still would not affect how the pins are actually driven by any of the hardware modules on the chip.

Cheers, Alan.
 
Top