Try to compact your code. Maybe repeated code can be a subroutine etc.
Also if you use flags, then declare them as BIT and not as BYTE or even worse as WORD.
If you need a BYTE variable, do not declare as WORD.
Ioannis
Try to compact your code. Maybe repeated code can be a subroutine etc.
Also if you use flags, then declare them as BIT and not as BYTE or even worse as WORD.
If you need a BYTE variable, do not declare as WORD.
Ioannis
Whitout "graphics elements" the code it's 659 words. Maybe it's a good start for use PID ?! (+314 words)
Code:' version 2 @ DEVICE PIC12F675, intrc_osc_noclkout, wdt_off, mclr_off DEFINE OSC 4 DEFINE ADC_BITS 10 DEFINE ADC_CLOCK 3 DEFINE ADC_SAMPLEUS 50 CMCON = 7 TRISIO = %001001 INTCON = 0 GPIO = 0 ANSEL = %00010001 ADCON0 = %10000001 wpu = %00000010 D_C var GPIO.2 SDIN var GPIO.4 SCK var GPIO.5 MOSFET var GPIO.1 buton var GPIO.3 LcdReg var byte x var byte y var byte z var byte a var byte PosX var byte PosY var byte Chr var byte LcdData var byte Offset var byte Char var byte adval var word w1 var word vt var word cnt var byte grup var word mode var byte calibra var word DATA @0,$3E,$51,$49,$45,$3E,_ ';// 0 $00,$42,$7F,$40,$00,_ ';// 1 $42,$61,$51,$49,$46,_ ';// 2 $21,$41,$45,$4B,$31,_ ';// 3 $18,$14,$12,$7F,$10,_ ';// 4 $27,$45,$45,$45,$39,_ ';// 5 $3C,$4A,$49,$49,$30,_ ';// 6 $01,$71,$09,$05,$03,_ ';// 7 $36,$49,$49,$49,$36,_ ';// 8 $06,$49,$49,$29,$1E,_ ';// 9 $08,$08,$3E,$08,$08,_ ';// + $08,$08,$08,$08,$08,_ ';// - $00,$60,$60,$00,$00,_ ';// . $00,$02,$05,$02,$00,_ ' grad $3E,$41,$41,$41,$22,_ ' C $7F,$02,$0C,$02,$7F,_ ' M $00,$00,$00,$00,$00,_ ' space $08,$04,$7F,$04,$08,_ ' arrow up $20,$40,$7F,$40,$20 ' arrow down pause 500 LcdReg = %00100001 'LCD Extended Commands. call PrintCtrlLcd LcdReg = $E6 'Set LCD Vop (Contrast).Initial $C5 call PrintCtrlLcd LcdReg = %00000110 'Set Temp coefficent. call PrintCtrlLcd LcdReg = %00010011 'LCD bias mode 1:48. call PrintCtrlLcd LcdReg = %00100000 'LCD Standard Commands call PrintCtrlLcd LcdReg = $0C 'LCD in normal mode. $0D inverse call PrintCtrlLcd Pause 100 Call CursorHome Pause 100 Gosub LCD_Clear mode = 0 Pause 500 ' time to give-up :) '===================== READING VOLTAGE ============================== Main: low mosfet vt=0 grup=0 for cnt = 1 to 20 ADCON0.1 = 1 WHILE ADCON0.1 = 1 : WEND Pause 10 adval.HighByte = ADRESH adval.LowByte = ADRESL PAUSE 10 vt=adval * 500 vt=div32 1023 grup=vt+grup PAUSE 10 next cnt w1=grup / 20 '~~~~~~~~~~~~~~~~~ setting cursor for display the voltage LcdReg = %10000000 + 25 ' cursor X call PrintCtrlLcd LcdReg = %01000011 ' cursor Y call PrintCtrlLcd '~~~~~~~~~~~~~~~~~ now display results if (w1 dig 2) <1 then char = 16 call Printchar else Char = (w1 dig 2) call PrintChar endif Char = (w1 dig 1) call PrintChar if (w1 dig 0) < 5 then Char = 0 call PrintChar else char = 5 call PrintChar endif Char = 16 call PrintChar Char = 13 call PrintChar Char = 14 call PrintChar if buton = 0 then mode = mode + 1 gosub memo endif gosub check Pause 100 Goto Main '================== L C D =========================================== CursorHome: LcdReg = %10000000 ' cursor Home call PrintCtrlLcd LcdReg = %01000000 ' cursor Home call PrintCtrlLcd return PrintChar: offset = Char * 5 for a = 1 to 5 read offset, LcdReg call PrintDataLcd offset = offset + 1 next a LcdReg = 0 call PrintDataLcd return PrintCtrlLcd: D_C = 0 PrintDataLcd: for x = 1 to 8 SDIN = LcdReg.7 SCK = 1 LcdReg = LcdReg << 1 SCK = 0 next x D_C = 1 return LCD_Clear: PosX=0:PosY=0:Gosub LCD_GotoXY D_C = 1 FOR Chr=1 TO 252 LcdData=0:Gosub LCD_ByteOut LcdData=0:Gosub LCD_ByteOut next Chr return LCD_GotoXY: D_C = 0 LcdData=%01000000 | PosY :Gosub LCD_ByteOut LcdData=%10000000 | PosX :Gosub LCD_ByteOut return LCD_ByteOut: SHIFTOUT SDIN,SCK,1,[LcdData] return '=============================================================================== memo: if mode = 1 then gosub poz char = 17 call PrintChar endif if mode = 2 then gosub poz char = 15 call PrintChar calibra = vt endif if mode = 3 then gosub poz char = 18 call printchar endif if mode > 3 then mode = 0 gosub poz char = 16 call printchar endif return '=============================================================================== check: SELECT CASE MODE CASE 1 PWM MOSFET, 255, 300 CASE 2 if w1 < (calibra-1) then pwm mosfet, 155, 200 'era 500 else low mosfet endif CASE 3 LOW MOSFET END SELECT return '=============================================================================== Poz: LcdReg = %10000000 + 67 ' cursor X call PrintCtrlLcd LcdReg = %01000011 ' cursor Y call PrintCtrlLcd return '=============================================================================== End 'of program
You can still shave some bytes...
- you don't need 2 spi routines LCD_ByteOut & PrintDataLcd,
- replace the For-To-Next loop with Repeat-Until ones,
- if at all possible, try to skip the div32.
- use internal timer for delays (not sure it will that much though
- pwm with a high/low loop maybe?
- select case for a couple a if-then
couples of ideas like that. sounds like a nice challenge![]()
Last edited by mister_e; - 13th July 2011 at 17:37.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Another thing about the graphic part, I've messed with it a lot recently and I saved a load of code space by skipping the whole SELCT-CASE + Lookup thing by using something like
But you need to modify a little bit the way your DATA lines are done.Code:SearchChar: read (index), char if char == TheCharYoureLookingFor then Gosub PrintIt index=endtable endif index=index+6 if (index)<endtable then SearchChar
so when you want to display your grad character, just need to send G to that routine above. Simple... if it fits the EEPROM ...Code:DATA @0,"0",$3E,$51,$49,$45,$3E,_ ';// 0 "1",$00,$42,$7F,$40,$00,_ ';// 1 "2",$42,$61,$51,$49,$46,_ ';// 2 "3",$21,$41,$45,$4B,$31,_ ';// 3 "4",$18,$14,$12,$7F,$10,_ ';// 4 "5",$27,$45,$45,$45,$39,_ ';// 5 "6",$3C,$4A,$49,$49,$30,_ ';// 6 "7",$01,$71,$09,$05,$03,_ ';// 7 "8",$36,$49,$49,$49,$36,_ ';// 8 "9",$06,$49,$49,$29,$1E,_ ';// 9 "+",$08,$08,$3E,$08,$08,_ ';// + "-",$08,$08,$08,$08,$08,_ ';// - ".",$00,$60,$60,$00,$00,_ ';// . "G",$00,$02,$05,$02,$00,_ ' grad "C",$3E,$41,$41,$41,$22,_ ' C "M",$7F,$02,$0C,$02,$7F,_ ' M " ",$00,$00,$00,$00,$00,_ ' space "^",$08,$04,$7F,$04,$08,_ ' arrow up "_",$20,$40,$7F,$40,$20 ' arrow down
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Hi,
314 words is the size when compiled by itself. Depending on what functions your code uses it might already have one or more of the PBP library routines included meaning the total size will be less than whatever + 314 words.
But like I said, the problem in this case is likely the amount of available RAM. If my count is correct your code uses 23 bytes and the original incPID uses 29 bytes, then, if I'm not mistaken, PBP adds ~24 bytes for its internal use (might change depending on what library routines are used, I don't know for sure). All in all this adds up to more than the 64 bytes of RAM available on the 12F675.
What I meant with not being worth it wasn't that you should throw a "bigger" PIC at the issue. I meant that I don't think the effort of implementing incPID is worth it considering the performance gain you might get compared to the aproaches already discussed. Sure, it it fits it's wort a try, if it doesn't fit I'd try to make do with what's available.
Finally incPID was written in order to be versatile and easy to use. It's probably possible to reduce the size and amount of RAM needed further if adapting it to a specific application - but that's up to anyone using it to do.
/Henrik.
I'm sure there is something I am missing here but,
Do you think you can do better then this? Or need to? Now if its an excersize in learning and just the fun of doing it, well thats a great reason. But I would think the tip temp will cool that much if you just blow on the tip. but to raise it will take full power for a few seconds to get it back, then it will overshoot. Just my HO.Still have BIG thermal inertia of iron soldering (about 7-8 degree)...![]()
-Bert
The glass is not half full or half empty, Its twice as big as needed for the job!
http://foamcasualty.com/ - Warbird R/C scratch building with foam!
Just so we are all playing on the same field . . . are we talking degrees C or degrees F ? I am guessing Centigrade so that's more like 13 or 14 Fahrenheit.
Check out Robert's article:
http://itech.fgcu.edu/faculty/zalews...PIDcontrol.pdf
If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
.
Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
.
There simply is no "Happy Spam" If you do it you will disappear from this forum.
Sure enough, it's not Kelvin... just sayin![]()
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Bookmarks