Re: 12F683 2 x PWM Outputs
Daryl
I bought Proteus and can now load your program but get 1 error on simulation which says.
"Not Built requires PBPW"
Any ideas?
Re: 12F683 2 x PWM Outputs
I think I had it pointing to PBPW at the time.
Proteus saves the compiler path in the .dsn file.
Go to ... Source > Add/Remove Source code files..
Change the "Code Generation Tool" drop-down box so it points to your installation. (PBPMPLAB)
Re: 12F683 2 x PWM Outputs
Nope same error :(
Can you post exactly whats in your source code boxes?
1 Attachment(s)
Re: 12F683 2 x PWM Outputs
Here's the way that one was setup. But you should change it to use COF instead of HEX and add the -K# command line option.
And make sure your compiler setup is working with a new design.
Attachment 5177
Re: 12F683 2 x PWM Outputs
Re: 12F683 2 x PWM Outputs
Well, you could certainly write a program that uses TMR0 to generate frequencies.
But SSPWM will not do it.
It needs a 16-bit timer to meet the published Frequency/Dutycycle range.
Re: 12F683 2 x PWM Outputs
I am a issue to my code.. It can't resolved. What can I do.. I'll show here my source code boxes then please you help me out .......
I hope this community members can help me.
Re: 12F683 2 x PWM Outputs
I do not want to make new thread so I will ask here:
Can someone help me with rewriting the code (I do not understand asm - please don't laugh at me:mad:) - I need single channel SPWM fixed 95% duty with 85 Hz from 12F683 to drive LEDs (and perhaps extend their life)?
Many thanks in advance!!!
Re: 12F683 2 x PWM Outputs
First, Im not going to laugh at you not understanding ASM, I don't either. but your on a forum for pick basic pro, so ASM is almost a moot point. What your wanting to do is only 1 line of code other than your pin setting statements. and is easily available in every pic basic pro manual, and instructional book out there. its probobly under the HPWM code, the 683 is a great chip for that exact code, as thats the same I am using for that purpose except im not driving leds.
You really should try doing a search before posting a question, ive seen this code in the forum, I know im bad about asking questions that are already out there too, but I do try to look up some of the answers first.
Also Dont use others posts to ask a question that doesnt really help that persons post get answered, the post here is how to drive 2 PWM from a 683 chip, as far as I know it cant be done, and it looks like they have went to another chip to solve this. this thread should be on its way to being a dead thread. However if someone keeps adding other info in it keeps it alive and will hinder people that are looking at the article for info, they dont find what their looking for. Go ahead and post a thread with your question, there may be someone out there that needs that direct question answered later on and your thread could help, where the tile of this one would not.
I will answer your question with a direct statement out of an instruction book
HPWM
HPWM Channel, Dutycycle, Frequency
Some PIC microcontrollers have one or more built-in circuits to generate pulse width–modulated
square-wave signals (PWM). For example, PIC16F877 has two PWM Channels. Channel 1 is
known as CCP1 (also PORTC.2) and Channel 2 is known as CCP2 (also PORTC.1).
Dutycycle can vary from 0 to 255 which corresponds to 0% (low all the time) to 100% (high all
the time), respectively. A value of 127 gives 50% duty cycle. The highest Frequency is 32,767 Hz,
and on microcontrollers with two channels, the Frequency must be the same on both channels.
The PWM signal is output from the specified pin continuously in the background while the program
executes other instructions.
In the following example, a 1 kHz, 50% duty cycle PWM signal is generated from Channel 1
(CCP1) of a PIC16F683 type microcontroller:
HPWM 1, 127, 1000
this is copied directly from 30 Projects Using PIC BASIC and PIC BASIC PRO
this book came out in 2006, and is available on Google Books for free.
it pretty much teaches you everything you need to know.
I
Re: 12F683 2 x PWM Outputs
Thank you very much for your answer!
Of course I tried HPWM and I use 30 Projects Using PIC BASIC and PIC BASIC PRO as my Bible in programming, but it cannot give such low frequency as 85 Hz.
Apologies again for posting in thread with other topic, and I know that is annoying to make first post with question… I searched the entire web for tips for that for a long time – and recently found DT SPWM (many thanks for that) where frequencies below 255 Hz are possible. I just didn’t find someone made it with 12F683…
Anyway probably I will find time this weekend to try the code in this thread without changes in PWM, something like that:
Code:
DEFINE OSC 8
SPWMpin var GPIO.5 ' Output Pin for SSPWM
INCLUDE "SSPWM.inc" ' include the SSPWM module
;----[Constants]------------------------------------------
;HPWMfreq CON 20000
Freq = 85 ' Set Frequency of SSPWM (word)
;----[Variables]------------------------------------------
;HPWMduty VAR BYTE
;LastHPWMduty VAR BYTE
SSPWMduty VAR BYTE
;----[Initialize]-----------------------------------------
OSCCON = %01110000 ' 8Mhz
;ANSEL = %000011 ' AN0 and AN1 ANALOG
DutyCycle = 10 ' Set Duty Cycle of SSPWM
gosub StartSPWM ' Start SSPWM @ Freq/DutyCycle
;HPWM 1, 127, HPWMfreq ' Start 20Khz PWM @ 50%
;----[Main Program Loop]---------------------------------
Main:
;ADCIN 0, HPWMduty
;ADCIN 1, SSPWMduty
;IF HPWMDuty != LastHPWMduty THEN
;LastHPWMduty = HPWMDuty
;HPWM 1, HPWMDuty, HPWMfreq
; ENDIF
;DutyCycle = SSPWMduty*80/256+10 ' scale SSPWM dutycycle
DutyCycle = 95 ' set 95% nominal SSPWM dutycycle
gosub SetSPWM ' Change SSPWM DutyCycle
GOTO Main
Maybe after all I will not need changes in ASM.
Re: 12F683 2 x PWM Outputs
Hi,
I copied the program into Microcode Studio and when I compile it I get
the following errors:
ERROR: Variable wsave3 position request 416 beyond RAM_END 191.
ERROR: Variable wsave2 position request 288 beyond RAM_END 191.
I Googled the errors and searched the forum but cant find an answer.
Please help.
Hebemabo
Re: 12F683 2 x PWM Outputs
Which program, exactly are you talking about? There are several ones in this thread - is it one of them?
And what PIC are you aiming to use and have you selected that particular one in MicrocodeStudio?
/Henrik.
Re: 12F683 2 x PWM Outputs
Hello Henrik , its the code just before my reply. The one by deodeo.
I am programming a 12F683 using PBPro , Microcode Studio , MPASM and Pickit2.
I have selected 12F683 in MicrocodeStudio.
Re: 12F683 2 x PWM Outputs
Just like DT's interrupt routines, you some times need to comment out a few lines in the include file
Look inside "SSPWM.inc"
Code:
' --- IF any of these three lines cause an error ?? Simply Comment them out to fix the problem ----
wsave1 var byte $A0 SYSTEM ' location for W if in bank1
wsave2 var byte $120 SYSTEM ' location for W if in bank2
wsave3 var byte $1A0 SYSTEM ' location for W if in bank3
' ------------------------------------------------------------------------------
Re: 12F683 2 x PWM Outputs
Thank you very much Mark.