PDA

View Full Version : SERIN and PWM on 12f615



jowan512
- 20th November 2011, 16:39
Hi,
I'm new to PicBasicPro but it works great for the simple stuff I want to do.
I have a lot of PIC12f615's left over from an old LED project and want to re-use them.
My intention it so create a load of LED RGB nodes, that can attach to a main communication bus, and be indivdually controlled from one source.

I have got SERIN2 working successfully, well, I dont really understand all the arguments yet. But I can send serial from another device and turn and LED on and off when I want.

I have also got PWM to work well, I can fade an LED up and down, so now, i need to combine the two!

The main problem I have is that the PWM command goes, PIN; DUTY; CYCLE and the CYCLE seems to be the length that the PWM is on for. What I want is for the PWM to be constantly on and IF data is sucessfully recived through SERIN2 and it is a number, set the PWM to that value, there for I could control the PWM via another device. But ... in my experiements.

Tnis is how I thought it would work but it does not.

----------------

DEFINE OSC 4
output 4

ANSEL = 0 ' disable A/D converter

Command var byte ' variable to receive data into
pwmval var WORD

InputData var byte
PulseWidth var byte

loop:

serin2 2,41356,0, nodata, [inputData]

pulseWidth = inputData

nodata:

pwm 4,pulseWidth,1

goto loop

end

--------------------

the reason for this is, as far as I have read, the routine in nodata: will get executed when there is nothing coming in, and ideally I want that to execture a PWM and go back to listening for serial, so the CYCLE is 1. and also the 3 argument in SERIN2 is the wait ? length ? so really I dont want it to wait at all.
If anyone could help me that would be great, all I want to do is change the PWM of and LED though SERIN21

thanks - j

Charles Linquis
- 20th November 2011, 21:26
You will have to use hardware pwm. I suggest you read the chip datasheet and set up the registers manually. I'm not a fan of PBPs HPWM.

jowan512
- 21st November 2011, 09:25
so the command PWM is 'software PWM' ?
as far as I can tell a bug limitation of the command is that it is only on for CYCLE.

can HPWM be set to go in the background whilst other loops are executed ?

it's a shame as soft PWM works pretty well for LEDs

Charles Linquis
- 21st November 2011, 13:15
The "PWM" command is bit banged.

And of course HPWM will run in the background. PBPs HPWM command will probably be perfect for running LEDs.