SX48 PWM Problem
Heya Guys
I tried the example from the help file on PWM, and I get the an erro saying TrisB is not defined. Any Ideas?
I tried the example from the help file on PWM, and I get the an erro saying TrisB is not defined. Any Ideas?
Somebody said...
'
' Program Description
'
'
' Uses PWM through an RC network to create an analog voltage.
'
' Device Settings
'
DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ 4_000_000
ID "PWM"
'
' IO Pins
'
DAC VAR RB.0 ' output to RC network
'
' Variables
'
angle VAR Byte
duty VAR Byte
tmpB1 VAR Byte
tmpB2 VAR Byte
' =========================================================================
PROGRAM Start
' =========================================================================
'
' Subroutine Declarations
'
SIN SUB 1 ' returns sine of angle
COS SUB 1 ' returns cosine of angle
'
' Program Code
'
Start:
DO
FOR angle = 0 TO 255 ' sweep through angles
duty = SIN angle ' get sine of angel
duty = duty + 127 ' bias to 2.5 v
PWM DAC, duty, 1 ' charge RC network
NEXT
LOOP
'
' Subroutine Code
'
' Use: value = SIN angle
' -- "value" returned as signed byte (-127 to 127)
' -- angle is expressed in Brads (0 - 255)
SIN:
tmpB1 = __PARAM1 ' get angle
tmpB2 = tmpB1 ' make copy
IF tmpB2.6 = 1 THEN ' in 2nd or 4th quadrant?
tmpB1 = 0 - tmpB1 ' yes, move to 1st/3rd
ENDIF
tmpB1.7 = 0 ' reduce to 1st quadrant
READ SineTable + tmpB1, tmpB1 ' read sine
IF tmpB2.7 = 1 THEN ' was angle in 3rd/4th?
tmpB1 = 0 - tmpB1 ' yes, adjust
ENDIF
RETURN tmpB1
'
' Use: value = COS angle
' -- "value" returned as signed byte (-127 to 127)
' -- angle is expressed in Brads (0 - 255)
COS:
tmpB1 = __PARAM1 + $40 ' get angle (adjust phase)
tmpB1 = SIN tmpB1 ' call sine table
RETURN tmpB1
' =========================================================================
' User Data
' =========================================================================
SineTable:
DATA 000, 003, 006, 009, 012, 016, 019, 022
DATA 025, 028, 031, 034, 037, 040, 043, 046
DATA 049, 051, 054, 057, 060, 063, 065, 068
DATA 071, 073, 076, 078, 081, 083, 085, 088
DATA 090, 092, 094, 096, 098, 100, 102, 104
DATA 106, 107, 109, 111, 112, 113, 115, 116
DATA 117, 118, 120, 121, 122, 122, 123, 124
DATA 125, 125, 126, 126, 126, 127, 127, 127
DATA 127
Comments
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Teacher: What is the difference between ignorance and apathy ?
Student: I don't know and I don't care
Teacher: Correct !
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.hittconsulting.com
·
it still does not mentions tris_b in the example from the manual however
Anyone advise?
Sorry to be a pain
Thanks
DJH
- Sparks
Newest version, downloaded 2 days ago [noparse]:([/noparse]
Got it working now, was a bug with the ide, copied the code, restarted pasted and it worked.
Now I cannot get it to simply dim an led now [noparse]:([/noparse]
regardless of duty being 10 or 250, led is same brightness, is any extra circuitry required? as with the picaxe, you just use an led, and a resistor.
DJH
You have: PWM DAC, duty, 1 ' charge RC network
RB.0 will PWM for 1ms.· That's not long enough to see anything.· Are you figuring it's going to stay at the charged voltage so that you can base your brightness on it?· That won't work like that.· You can vary brightness as long as the pin is (actively) PWM'ing, but the cap in the LP filter will drain straight away once the PWM stops.· I'm thinking that you'll have to use an op-amp, as a sample & hold.
PWM Pin, Duty, Duration
Post Edited (PJ Allen) : 7/12/2007 11:45:13 PM GMT
I did try just pwm with a duty between 1 and 255 and the duration as 1000
the led comes on but thats it no variance in brightness, always the same brightness regardless of duty.
Also can this not be done with just a reisitor and led as on the picaxe series of chips (basically a pic chip with a bootloader)
Thanks
DJH
· You need to create the simplest program that demonstrates the problem.
· If you just want PWM then there is no reason that "PWM pin, value, duration" won't work. value and duration must be from 0 to 255. This is all right in the help file. Duration cannot be 1000.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Teacher: What is the difference between ignorance and apathy ?
Student: I don't know and I don't care
Teacher: Correct !
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.hittconsulting.com
·
I spent so long messing with it that I forgot about that, I did also try it with 100
Will try it again
DJH
Start:
DO
FOR duty = 0 TO 255 ' sweep through angles
PWM DAC, duty, 250 ' charge RC network
NEXT
LOOP
Nobody has said if i can even do this with just an led and a resistor?
This program works (the LED starts OFF and then gradually increases to full ON), I am watching it right before me·--
I am using RA.0 for the output, and I am not using a·capacitor or RC network at all (and I don't know why you are.)·
You will have to change the FREQ directive to match your time-base.
Update -- added drawing and SXB program
Post Edited (PJ Allen) : 7/13/2007 5:42:02 PM GMT
You got to help us help you...
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Teacher: What is the difference between ignorance and apathy ?
Student: I don't know and I don't care
Teacher: Correct !
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.hittconsulting.com
·
been a hard day, Im not using a cap or RC network, those comments were left over from the code taken from the manual.
I am now trying this code but I just get a "Tris_a not defined" error.
thats the line I deleted.
Any ideas why this would happen? Sorry Ive been getting used to the propeller, but need to use the SX for it's larger number of outputs and cheaper price.
Thanks
DJH
It seems you have found a bug in the compiler. This can be corrected by adding a line: __TRISA CON __TRIS
I will make sure this is corrected in the next release of the compiler.
Thanks,
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Teacher: What is the difference between ignorance and apathy ?
Student: I don't know and I don't care
Teacher: Correct !
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.hittconsulting.com
Post Edited (Bean (Hitt Consulting)) : 7/13/2007 7:22:41 PM GMT
Thanks for all of your help also, i do not mean to be a pain, once I pick things up I will bother you all a bit less [noparse]:)[/noparse]
You don't have to set the pin to an output, PWM will do that for you.
and you can just use
FOR duty = 255 TO 0 STEP -1
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Teacher: What is the difference between ignorance and apathy ?
Student: I don't know and I don't care
Teacher: Correct !
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.hittconsulting.com
·
in trying to cut down code space, however, I've hit a snag... I need to be able to specify the PIN in the PWM command as a variable... I'm sending pulses out each RA & RB port bit ( 16 seperate PWM commands..yuk) & want to use a generic 'send' subroutine, passing pin & duration as params... any ideas??
thanks,
jesse in venice..
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
---
James Newton, Host of SXList.com
james at sxlist,com 1-619-652-0593 fax:1-208-279-8767
SX FAQ / Code / Tutorials / Documentation:
http://www.sxlist.com Pick faster!
Thank you, would never have tried out the SX chips without it [noparse]:)[/noparse]
DJH