PDA

View Full Version : Dual PWM's using 12F683? Failure, Suggestions?



wdmagic
- 29th August 2014, 18:15
Ive got a project that has some issues, what the project is suppose to do is have 2 pots that control 2 FET's via Software or Hardware PWM's to control LED light strings.

Here is the results
Trial 1 - Get a single unit to work, both Software and hardware work fine as a single unit with code for only 1 being used, the software version can use about any chip with a adc converter.
Here is some code that was working with

DEFINE ADC_BITS 10 ' A/D number of bits
DEFINE ADC_CLOCK 1 ' Use A/D internal RC
DEFINE ADC_SAMPLEUS 50 ' Set sampling ti
TRISIO = %000101 ' AN0 & AN2 is Analog input
CNT VAR byte
POT1 VAR WORD
POT2 VAR WORD
CNT=0
AGAIN:
ADCIN 0, POT1 ' Read Channel 0 data
POT1 = POT1 / 256
if POT1 < 10 then POT1 = 0
ADCIN 2, POT2 ' Read Channel 0 data
POT2 = POT2 / 256
if POT2 < 10 then POT2 = 0

RUNNER:
if POT1 > CNT then
GPIO.1 = 1
ELSE
GPIO.1 = 0
endif
if POT2 > CNT then
GPIO.3 = 1
ELSE
GPIO.3 = 0
ENDIF
CNT = CNT + 1
if CNT > 255 then CNT = 0
if CNT = 0 then goto again
GOTO runner
end


Now this is the software version of PWM, its low tech and maybe theres another way better for software PWM.
----------------------------------
Here is my hardware version I am using a 12F683 for this one

DEFINE ADC_BITS 8 ' A/D number of bits
DEFINE ADC_CLOCK 1 ' Use A/D internal RC clock
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in us
ADCON0.7 = 0 ' Justify Result to 10 & 8 bit Side
CCP1CON = %00001100 ' Set ADC Port
RES1 Var Word ' A/D converter result

TRISIO = %00000010
AGAIN:
ADCIN 1, Res1 ' Read Channel 0 data
if res1 < 10 then res1 = 0 ' Low Auto Shutoff
HPWM 1, res1, 18000 ' PWM Pin, Setting, Frequency (20k Max)
pause 25
goto again
end


Again this one works fine by itself.
I did try to merge both into one chip and have both hardware and software but that didnt go so well, they interact with each other, im not sure why as the pins they use and code are seperate but it happens, and I erased the code that was messed up.

So what I would like is some sample code for dual PWMs that do not interfere with each other, I only have legacy 8bit processors right now (629, 675, 683, 4550) and although I do have a PicKit3 Available I am using pbp2.6 and mcs4. I will be getting PBP 3gold soon, perhaps in a couple of months and will have access to other chips then too.

So any ideas are welcome.

Acetronics2
- 29th August 2014, 19:30
Darrel's SSPWM , may be ???
http://www.pbpgroup.com/modules/wfsection/article.php?articleid=12

too late to thank him ... Halas. :o:o:o

Alain

mark_s
- 29th August 2014, 20:19
too late to thank him ... Halas. :o:o:o

Alain

Yes. But his spirit lives and we can thank him by keeping his work alive!

@WDMAGIC

Have a look at Darrel's MBAM routine. The example has three pwm outputs, controlling a RGB led. I experimented with it a
while back. You can change pulse width and rate with the adc. Only draw back, it only has 8 bits of resolution vs 10 bits using the
hpwm module. Dimming appeared smooth to my eyes.

http://www.picbasic.co.uk/forum/showthread.php?t=10564

wdmagic
- 30th August 2014, 01:07
Darrels Passed , I didnt know :(

I found that link to the sspwm right after I posted, will give it a try. wish i could find a 8pin package with 2 hpwm's

Acetronics2
- 30th August 2014, 10:00
Try to get one of those ...
http://ww1.microchip.com/downloads/en/DeviceDoc/40001723C.pdf

alain

midali
- 30th August 2014, 11:00
Exist a way to compile 12f1571/1572 with PBP ?

wdmagic
- 19th September 2015, 22:24
I'm Back! ok its been awhile, work has bogged me down along with training someone in VB, also I just got sidetracked. But I'm much better now :) I ordered some of the 12f1572 's but since its been so long I've lost them and need to order more, I do have a PicKit3, hovever i need to order PBP3. I was going to order the Gold but I cant seem to find my discount link. there is a link that gives you $30 - 50 off but its been so long I've changed PC's and lost the link Can Anyone provide? anything cheaper than the list price would be good. thanks. Did I mention how hard it is to start this back up after a year of not programming and losing code notes! hehe. make backups!

Dave
- 21st September 2015, 12:09
Midali, PBP 3.0 will compile for 12F1571/12F1572.

midali
- 23rd September 2015, 21:23
Thx Dave for your attention,
I saw that PBP update have 12F157x compiler.

Scampy
- 1st October 2015, 17:40
Ive got a project that has some issues, what the project is suppose to do is have 2 pots that control 2 FET's via Software or Hardware PWM's to control LED light strings.

So any ideas are welcome.

How about using a PCA9685 PWM chip to controll the LEDS. OK 16 channels may be overkill, but I use one in a project that controlled the LEDs over my marine reef tank. In my case I can program the ramp up and down periods for each of four channels, with 0 to 4095 steps which makes for smooth dimming. I'm sure it would be easy to use an AtoD option for a POT to give the PWM range rather than a simple time loop.

Also, if you are looking at controlling strings of high power LEDs then a simple way is to use Meanwell LDD drivers. These are constant current devices between 300mA and 1500ma, and can be used with 6v - 50v power supplies.

wdmagic
- 14th October 2015, 00:21
thanks for the ideas, I'm dead set right now with only using microchip pics to do controlling, as I have a surplus of these. I did break down and buy the full version of pbp 3 gold, and so far its awesome, I also have a pickit 3. I'm messing around with it tonight using a 12f1572 was wondering if there was a way similar to a IRQ (interrupt) to detect a change in the ADC input? that way i could just call up the code when someone turned a knob.

wdmagic
- 17th October 2015, 00:51
OK I got it to work using a 12F1572. I wanted to post my code and see if anyone can spot something I need to clean up or rework. please note a small problem i ran into noted after code. DEFINE OSC 4 DEFINE ADC_BITS 8 ' A/D number of bits DEFINE ADC_CLOCK 1 ' Use A/D internal RC clock DEFINE ADC_SAMPLEUS 50 ' Set sampling time in us 50 ADCON0.7 = 0 ' Justify Result to 10 & 8 bit Side RES1 Var byte ' A/D converter result RES0 VAR BYTE AGAIN: ADCIN 2, Res0 ' Read Channel 3 data ADCIN 3, Res1 ' Read Channel 3 data if res1 < 10 then res1 = 0 ' Low Auto Shutoff if res0 < 10 then res0 = 0 ' Low Auto Shutoff HPWM 2, res0, 10000 ' PWM Pin, Setting, Frequency (20k Max) HPWM 1, res1, 10000 ' PWM Pin, Setting, Frequency (20k Max) pause 5 goto again ----------------- sorry not in code block, my page doesnt show those options. ok the problem i ran into is that the 12f1572 is supposed to be capable of running up to 32mhz using internal clock I thought it read. however if i change the define to 32, then it slowwwws way down, also even when set to 4mhz i had to make my pause at the end 5, where it used to be 100 with older chips? any ideas on how i can specify a higher internal clock freq, and why i have to use such a low pause (if i use a 100 my leds flash, with a 5 they change fairly smoothly.)

richard
- 17th October 2015, 01:22
Note that "DEFINE OSC" doesn't set or change the actual clock frequency. It only
tells PBP what to expect. The actual frequency is set by selecting a crystal,
changing the device configuration, setting registers in your program, or (most
commonly) a combination of all of these.



you need to set the OSCCON reg appropriately and the PLL config too to use the 32mhz clock