Sharing variables , 1302 timing chipp clock
Hi people , need some help again ,
im tring to get the propeller chip to toggle a pin to set some lights to go on ,
but I want to do this at a time interval
. the big problem is that the time variables are in a diferent cog and I seem to be not getting it right
tryed to do it with lock , cause I know ther wil be data collisons if i don"t but can't get it right
please let me know if you seen the problem
cog 0 main method
THe pin toggle code
ANd the time stamp code's
im tring to get the propeller chip to toggle a pin to set some lights to go on ,
but I want to do this at a time interval
. the big problem is that the time variables are in a diferent cog and I seem to be not getting it right
tryed to do it with lock , cause I know ther wil be data collisons if i don"t but can't get it right
please let me know if you seen the problem
cog 0 main method
PUB main
dira[21..22]~~
outa[21..22]~~
LCD.Init( E, RS, RW, DBHigh, DBLow ) {LCD init}
LCD.usDelay( 5_000 ) {LCD init}
LCD.Clear {LCD init}
cognew(init,@stack)
repeat
repeat until not lockset(statusSemId)
time
if second < 30
set
else
reset
lockclr(statusSemId)
waitcnt(clkfreq + cnt)
THe pin toggle code
PUB set
outa[22]~~
waitcnt(clkfreq/20 + cnt)
outa[22]~
waitcnt(clkfreq/20 + cnt)
return
PUB reset
outa[21]~~
waitcnt(clkfreq/20 + cnt)
outa[21]~
waitcnt(clkfreq/20 + cnt)
return
ANd the time stamp code's
PUB init
statusSemId := locknew
rtc.init( 20, 19, 18 ) {timekeeper init}
repeat
repeat until not lockset(statusSemId)
rtc.readTime( @hour, @minute, @second ) 'read time from DS1302
rtc.readDate( @day, @month, @year, @dow )
lockclr(statusSemId)
waitcnt( clkfreq + cnt )
PUB time
LCD.RawSetPos( $01 ) {display time on first row lcd}
LCD.PrintStr( decx(hour,2) )
LCD.Printchr( ":" )
LCD.PrintStr( decx(minute,2) )
LCD.Printchr( ":")
LCD.PrintStr( decx(second,2) )
LCD.RawSetPos( $0B ) {display date on first row lcd}
LCD.PrintStr( decx(day,2) )
LCD.Printchr( "/" )
LCD.PrintStr( decx(month,2) )
LCD.Printchr( "/")
LCD.PrintStr( decx(year,2))
return

Comments
Your stack may not be large enough. Try doubling it in size. Also try doing a lockclr before calling cognew.
maybe it totally wrong.
maymee I see it bad but isint it supose to be a simple code ??
hope to hear from you
repeat until not lockset(statusSemId) time if second < 30 set else reset lockclr(statusSemId) waitcnt(clkfreq + cnt)You also misspelled cnt. There are similar indenting problems in the "init" method. Please check your program carefully to see that it's written the way you expect it to behave.Next time, be sure to post your entire program including declarations and constant definitions. You also need to describe what the program does and doesn't do. Just saying it's not right or it doesn't work is not helpful.
lets start with what i'm trying to acomplis .
I have a lcd 20*4 , 4 pushbuttons , a 1302 timekeeping chip , and some ssr relay,s conected to the propeller.
The project was to create a menu structure on the lcd display, time and date where always on the first low of the lcd , and the other rows I used to scroll tru the different menu's .
in the menu's i have to be able to adjust the time of the 1302 timechip, and set the on and off time . for an it to trigger the light .
at first i had the problem of getting my time into the chip , no figured that out via the form ( previous post) turnd out that i had to adress the variables with byte[@ variable ] .
as that was finished , i created some var to hold the time to set the light to on and off. but I doesn't work
the problem i think is in the sharing the variables *** I want a diferennt cog to monitor the time and compare it to the alarm time to trigger .
so the trigger is not working correct to let the lights go on or off.
so the code works like this , the main method starts , where it controles the lcd enso , the different menus are enterd the same way so I'm gonna put only one or it will get to big
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 TxPin = 23 {data pin 4 shift register} BitTime = 80_000_000 / 19200 buton1 =9 {input buttons } buton2 =10 {input buttons } buton3 =11 {input buttons } buton4 =12 {input buttons } RS = 25 {lcd control} RW = 26 {lcd control} E = 27 {lcd control} DBLow = 0 {lcd control} DBHigh = 3 {lcd control} OBJ LCD : "LCD_20x4" {LCD controler} rtc : "DS1302_full" {timekeeper} VAR byte h_menu,menu1,menu2,menu3,menu4,menu5,menu6,menu23,menu21,menu22 {menu variables} long stack[30],idx,tc byte hour, minute, second, day, month, year, dow,out ,cmd,vg_dagen {time ic variables} byte nstr[64] byte _month, _day, _year, _dow, _hour, _min, _sec {tijd instel buffer variabelen} byte von_year,von_month,von_day,von_hour,von_minute,von_sec {alarm 1 } byte voff_year,voff_month,voff_day,voff_hour,voff_minute,voff_sec {alarm 1 } byte bon_year,bon_month,bon_day,bon_hour,bon_minute,bon_sec {alarm 2 } byte boff_year,boff_month,boff_day,boff_hour,boff_minute,boff_sec {alarm 2 } PUB main {shift register control lines } dira[buton1]~ {make button input} dira[buton2]~ {make button input} dira[buton3]~ {make button input} dira[buton4]~ {make button input} rtc.init( 20, 19, 18 ) {timekeeper init} LCD.Init( E, RS, RW, DBHigh, DBLow ) {LCD init} LCD.usDelay( 5_000 ) {LCD init} LCD.Clear {LCD init} cognew(Lightcontrol,@stack) h_menu:= 1 {Set LCD to home menu} repeat if ina[buton2]==1 { down scroll button} h_menu:= h_menu + 1 if h_menu == 7 {menu size = 6} h_menu := 0 waitcnt (clkfreq / 10+ cnt) if ina[buton1]==1 {up scroll button } h_menu:=h_menu - 1 if h_menu ==0 {menu size = 6} h_menu:= 7 waitcnt (clkfreq / 10+ cnt) if ina[buton4]==1 {return menu} waitcnt (clkfreq / 10+ cnt) h_menu:= 1 if ina[buton3]==1 and h_menu == 2 {enter submenu2 } waitcnt (clkfreq / 2+ cnt) menu2:= 1 sub2 if ina[buton3]==1 and h_menu == 3 {enter submenu3 } waitcnt (clkfreq / 2+ cnt) menu3:= 1 sub3 if ina[buton3]==1 and h_menu == 4 {enter submenu4 } waitcnt (clkfreq / 2+ cnt) menu4:= 1 sub4 if ina[buton3]==1 and h_menu == 5 {enter submenu5 } waitcnt (clkfreq / 2+ cnt) menu5:= 1 sub5 if ina[buton3]==1 and h_menu == 6 {enter submenu6 } waitcnt (clkfreq / 2+ cnt) menu6:= 1 sub6 case h_menu 1: Tempu LCD.RawSetPos( $14 ) LCD.PrintStr( string(" Home " )) LCD.usDelay( 400_000 ) 2: Tempu LCD.RawSetPos( $14 ) LCD.PrintStr( string(" submenu 2 " )) LCD.usDelay( 400_000 ) 3: Tempu LCD.RawSetPos( $14 ) LCD.PrintStr( string(" submenu 3 " )) LCD.usDelay( 400_000 ) 4: Tempu LCD.RawSetPos( $14 ) LCD.PrintStr( string(" submenu 4 " )) LCD.usDelay( 400_000 ) 5: Tempu LCD.RawSetPos( $14 ) LCD.PrintStr( string(" Submenu 5 " )) LCD.usDelay( 400_000 ) 6: Tempu LCD.RawSetPos( $14 ) LCD.PrintStr( string(" submenu 6 " )) LCD.usDelay( 400_000 )the I go to the sub menu 2 where this codes continues
PUB sub2 {set menu to first menu} LCD.Clear repeat if ina[buton2]==1 { down scroll button} menu2:= menu2 + 1 if menu2 == 4 {menu size = 3} menu2 := 0 waitcnt (clkfreq / 10+ cnt) if ina[buton1]==1 {up scroll button } menu2:=menu2 - 1 if menu2 ==0 menu2:= 4 {menu size = 3} waitcnt (clkfreq / 10+ cnt) if ina[buton4]==1 { return button} waitcnt (clkfreq / 20+ cnt) LCD.Clear return if ina[buton3]==1 and menu2 == 1 {enter submenu21 } waitcnt (clkfreq / 2+ cnt) menu21:= 1 sub21 if ina[buton3]==1 and menu2 == 2 {enter submenu22 } waitcnt (clkfreq / 2+ cnt) menu22:= 1 sub22 if ina[buton3]==1 and menu2 == 3 {enter Tijd instellen } waitcnt (clkfreq / 2+ cnt) menu4:= 1 instelseqtime case menu2 1 : Tempu LCD.RawSetPos( $14 ) LCD.PrintStr( string(" alarm 1 " )) LCD.usDelay( 400_000) 2 : Tempu LCD.RawSetPos( $14 ) LCD.PrintStr( string(" alarm 2 " )) LCD.usDelay( 400_000) 3 : Tempu LCD.RawSetPos( $14 ) LCD.PrintStr( string(" Tijd instellen " )) LCD.usDelay( 400_000) PUB sub21 {set menu to first menu} repeat if ina[buton2]==1 { down scroll button} menu21:= menu21 + 1 if menu21 == 3 {menu size = 2} menu21 := 0 waitcnt (clkfreq / 10+ cnt) if ina[buton1]==1 {up scroll button } menu21:=menu21 - 1 if menu21 ==0 menu21:= 21 {menu size = 2} waitcnt (clkfreq / 10+ cnt) if ina[buton4]==1 { return button} LCD.Clear waitcnt (clkfreq / 10+ cnt) return sub2 case menu21 1 : Tempu LCD.RawSetPos( $14 ) LCD.PrintStr( string(" on time " )) LCD.usDelay( 400_000) LCD.RawSetPos( $55 ) {display time on first row lcd} LCD.PrintStr( decx(von_hour,2) ) LCD.Printchr( ":" ) LCD.PrintStr( decx(von_minute,2) ) LCD.Printchr( ":") LCD.PrintStr( decx(von_sec,2) ) LCD.RawSetPos( $5E ) {display date on first row lcd} LCD.PrintStr( decx(von_day,2) ) LCD.Printchr( "/" ) LCD.PrintStr( decx(von_month,2) ) LCD.Printchr( "/") LCD.PrintStr( decx(von_year,2)) if ina[buton3]==1 waitcnt (clkfreq / 10+ cnt) instelstart 2 : Tempu LCD.RawSetPos( $14 ) LCD.PrintStr( string(" off time " )) LCD.usDelay( 400_000) LCD.RawSetPos( $55 ) {display time on first row lcd} LCD.PrintStr( decx(voff_hour,2) ) LCD.Printchr( ":" ) LCD.PrintStr( decx(voff_minute,2) ) LCD.Printchr( ":") LCD.PrintStr( decx(voff_sec,2) ) LCD.PrintStr( string(" " )) if ina[buton3]==1 waitcnt (clkfreq / 10+ cnt) insteloff PUB sub22 repeat if ina[buton2]==1 { down scroll button} menu22:= menu22 + 1 if menu22 == 3 {menu size = 2} menu22 := 0 waitcnt (clkfreq / 10+ cnt) if ina[buton1]==1 {up scroll button } menu22:=menu22 - 1 if menu22 ==0 menu22:= 21 {menu size = 2} waitcnt (clkfreq / 10+ cnt) if ina[buton4]==1 { return button} LCD.Clear waitcnt (clkfreq / 10+ cnt) return sub2 case menu22 1 : Tempu LCD.RawSetPos( $14 ) LCD.PrintStr( string(" on time " )) LCD.usDelay( 400_000) LCD.RawSetPos( $55 ) {display time on first row lcd} LCD.PrintStr( decx(bon_hour,2) ) LCD.Printchr( ":" ) LCD.PrintStr( decx(bon_minute,2) ) LCD.Printchr( ":") LCD.PrintStr( decx(bon_sec,2) ) LCD.RawSetPos( $5E ) {display date on first row lcd} LCD.PrintStr( decx(bon_day,2) ) LCD.Printchr( "/" ) LCD.PrintStr( decx(bon_month,2) ) LCD.Printchr( "/") LCD.PrintStr( decx(bon_year,2)) if ina[buton3]==1 waitcnt (clkfreq / 10+ cnt) instelstart1 2 : Tempu LCD.RawSetPos( $14 ) LCD.PrintStr( string(" off time " )) LCD.usDelay( 400_000) LCD.RawSetPos( $55 ) {display time on first row lcd} LCD.PrintStr( decx(boff_hour,2) ) LCD.Printchr( ":" ) LCD.PrintStr( decx(boff_minute,2) ) LCD.Printchr( ":") LCD.PrintStr( decx(boff_sec,2) ) LCD.PrintStr( string(" " )) if ina[buton3]==1 waitcnt (clkfreq / 10+ cnt) insteloff1ANd the pice of code where i allready got help with on the form , here is where I set in the time via the display and the pushbottons , and after that it gets trasnferd to the 1302 chip to set the time
PUB instelseqtime LCD.Clear LCD.RawSetPos( $46 ) LCD.PrintStr( string("Maand" )) _month:=month instel(@_Month,12) {Maand instellen } LCD.Clear LCD.RawSetPos( $46 ) LCD.PrintStr( string("Dag " )) _day:=day instel(@_day,31) {Dag instellen } LCD.Clear LCD.RawSetPos( $46 ) LCD.PrintStr( string("Jaar " )) {Jaar instellen } _year:=year instel(@_year,99) LCD.Clear LCD.RawSetPos( $46 ) LCD.PrintStr( string("DoW " )) {Dag vd week instellen } _dow:=dow instel(@_dow,7) LCD.Clear LCD.RawSetPos( $46 ) LCD.PrintStr( string("Uur " )) {Uur instellen } _hour:=hour instel(@_hour,24) LCD.Clear LCD.RawSetPos( $46 ) LCD.PrintStr( string("Min " )) {min instellen } _min:=minute instel(@_min,60) LCD.Clear LCD.RawSetPos( $46 ) LCD.PrintStr( string("Sec " )) {sec instellen } _sec:=second instel(@_sec,60) rtc.config rtc.setDatetime( _month, _day, _year, _dow, _hour, _min, _sec ) LCD.Clear return PUB instelstart LCD.Clear LCD.RawSetPos( $40 ) LCD.PrintStr( string(" Start Time " )) LCD.RawSetPos( $55 ) {display time on first row lcd} LCD.PrintStr( decx(von_hour,2) ) LCD.Printchr( ":" ) LCD.PrintStr( decx(von_minute,2) ) LCD.Printchr( ":") LCD.PrintStr( decx(von_sec,2) ) LCD.RawSetPos( $5E ) {display date on first row lcd} LCD.PrintStr( decx(von_day,2) ) LCD.Printchr( "/" ) LCD.PrintStr( decx(von_month,2) ) LCD.Printchr( "/") LCD.PrintStr( decx(von_year,2)) instel2(@von_year,99,$64) instel2(@von_Month,12,$61) {Maand instellen } instel2(@von_day,31,$5E) {Dag instellen } instel2(@von_hour,24,$55) instel2(@von_minute,60,$58) instel2(@von_sec,60,$5B) LCD.Clear LCD.RawSetPos( $40 ) LCD.PrintStr( string(" Duur Voorgroei " )) instel2(@vg_dagen,30,$5B) voff_year:=von_year voff_month:=von_month voff_day:=von_day voff_hour:=von_hour + 12 voff_minute:=von_minute voff_sec:=von_sec bon_year:=von_year bon_month:=von_month bon_day:=von_day + vg_dagen bon_hour:=von_hour bon_minute:=von_minute bon_sec:=von_sec boff_year:=bon_year boff_month:=bon_month boff_day:=bon_day boff_hour:=bon_hour + 12 boff_minute:=bon_minute boff_sec:=bon_sec LCD.Clear return PUB insteloff LCD.Clear LCD.RawSetPos( $40 ) LCD.PrintStr( string(" End Time " )) LCD.RawSetPos( $5B ) {display time on first row lcd} LCD.PrintStr( decx(voff_hour,2) ) LCD.Printchr( ":" ) LCD.PrintStr( decx(voff_minute,2) ) LCD.Printchr( ":") LCD.PrintStr( decx(voff_sec,2) ) instel2(@voff_year,99,$64) instel2(@voff_Month,12,$61) {Maand instellen } instel2(@voff_day,31,$5E) {Dag instellen } instel2(@voff_hour,24,$55) instel2(@voff_minute,60,$58) instel2(@voff_sec,60,$5B) return PUB instelstart1 LCD.Clear LCD.RawSetPos( $40 ) LCD.PrintStr( string(" Start Time " )) LCD.RawSetPos( $55 ) {display time on first row lcd} LCD.PrintStr( decx(bon_hour,2) ) LCD.Printchr( ":" ) LCD.PrintStr( decx(bon_minute,2) ) LCD.Printchr( ":") LCD.PrintStr( decx(bon_sec,2) ) LCD.RawSetPos( $5E ) {display date on first row lcd} LCD.PrintStr( decx(bon_day,2) ) LCD.Printchr( "/" ) LCD.PrintStr( decx(bon_month,2) ) LCD.Printchr( "/") LCD.PrintStr( decx(bon_year,2)) instel2(@bon_year,99,$64) instel2(@bon_Month,12,$61) {Maand instellen } instel2(@bon_day,31,$5E) {Dag instellen } instel2(@bon_hour,24,$55) instel2(@bon_minute,60,$58) instel2(@bon_sec,60,$5B) boff_year:=bon_year boff_month:=bon_month boff_day:=bon_day boff_hour:=bon_hour + 12 boff_minute:=bon_minute boff_sec:=bon_sec return PUB insteloff1 LCD.Clear LCD.RawSetPos( $40 ) LCD.PrintStr( string(" End Time " )) LCD.RawSetPos( $5B ) {display time on first row lcd} LCD.PrintStr( decx(boff_hour,2) ) LCD.Printchr( ":" ) LCD.PrintStr( decx(boff_minute,2) ) LCD.Printchr( ":") LCD.PrintStr( decx(boff_sec,2) ) instel2(@boff_year,99,$64) instel2(@boff_Month,12,$61) {Maand instellen } instel2(@boff_day,31,$5E) {Dag instellen } instel2(@boff_hour,24,$55) instel2(@boff_minute,60,$58) instel2(@boff_sec,60,$5B) returnAnd the changing of the variablesPUB instel (Variabele,schaal) repeat if ina[buton1]==1 { down scroll button} byte[Variabele]:= byte[Variabele] + 1 if byte[Variabele] == (schaal+1) {menu size } byte[Variabele] := 0 waitcnt (clkfreq / 14+ cnt) if ina[buton2]==1 {up scroll button } byte[Variabele]:=byte[Variabele] - 1 if byte[Variabele] == 0 byte[Variabele]:= schaal {menu size } waitcnt (clkfreq / 14+ cnt) LCD.RawSetPos( $5B ) {display variable on lcd} LCD.PrintStr( decx(byte[Variabele],2) ) LCD.usDelay( 200_000) if ina[buton3]==1 waitcnt (clkfreq / 14+ cnt) return if ina[buton4]==1 return main PUB instel2 (Variabele,schaal,position) repeat if ina[buton1]==1 { down scroll button} byte[Variabele]:= byte[Variabele] + 1 if byte[Variabele] == (schaal+1) {menu size } byte[Variabele] := 0 waitcnt (clkfreq / 14+ cnt) if ina[buton2]==1 {up scroll button } byte[Variabele]:=byte[Variabele] - 1 if byte[Variabele] == 0 byte[Variabele]:= schaal {menu size } waitcnt (clkfreq / 14+ cnt) LCD.RawSetPos( position ) {display variable on lcd} LCD.PrintStr( decx(byte[Variabele],2) ) LCD.usDelay( 200_000) if ina[buton3]==1 waitcnt (clkfreq / 14+ cnt) return if ina[buton4]==1 returnbeside thos theres the code that's reads the time and displays it
PUB Tempu rtc.readTime( @hour, @minute, @second ) 'read time from DS1302 rtc.readDate( @day, @month, @year, @dow ) LCD.RawSetPos( $01 ) {display time on first row lcd} LCD.PrintStr( decx(hour,2) ) LCD.Printchr( ":" ) LCD.PrintStr( decx(minute,2) ) LCD.Printchr( ":") LCD.PrintStr( decx(second,2) ) LCD.RawSetPos( $0B ) {display date on first row lcd} LCD.PrintStr( decx(day,2) ) LCD.Printchr( "/" ) LCD.PrintStr( decx(month,2) ) LCD.Printchr( "/") LCD.PrintStr( decx(year,2)) returnand then there is the pice of code where the problem is , this pice of code get's lauched in another cog, and should activate of disactivate the lights.(alarm on /off)
but it ain't doing just that. \
pub set dira[22]~~ repeat 2 outa[22]~~ waitcnt(clkfreq/20 + cnt) outa[22]~ waitcnt(clkfreq/20 + cnt) pub reset dira[21]~~ repeat outa[21]~~ waitcnt(clkfreq + cnt) outa[21]~ waitcnt(clkfreq + cnt) PUB Lightcontrol dira[21..23]~~ {shift register control lines } outa[21..23]~~ repeat if byte[@second] >= byte[@von_sec] set if byte[@second] <= byte[@von_sec] resetI hope this time my problem is understandable enoug to get some usefull advise on how to get it working, advise in any form is a plus *** i am learning myself to work with this prop but it's proving allot of fun and just can't stop imagining the possibilities , i
hope to get this sorted out
igor