Counters, how to?
Franklin
Posts: 4,747
I am in the process of creating a weather station program using the Davis 6410 anemometer/wind vane. So far with the help of those here I have been able to get the wind direction and the string representation of that. I can also get the wind speed but would like to create an object for this and I think I need to have a seperate cog to handling the counting. My code for this is,
pub displaypulses olds := 0 speed := 0 phsa := 0 waitcnt(cnt+clkfreq*5) '' Pause for 5s term.str(string(13, "starting 01",13)) repeat s := phsa speed := (s - olds) olds := s 'term.dec (phsa) term.str(string(", s= ")) term.dec (s) term.str(string(", speed= ")) term.dec (speed) term.tx (13) waitcnt(cnt + clkfreq * (225/100))but I would like to call a function running in the object that would return the speed so I think I need to start this in its own cog and place the results in main ram but I don't know where to start. Where should I look for help? Thanks.
Comments
I don't think you need a seperate cog. All you need is take the counter value and divide by how much CNT has advanced.
Something like:
P.S. It looks like you want your final waitcnt to be 2.25 seconds, but it won't be because "(225 / 100)" = 2
It would be better to divide clkFreq by 100 THEN multiply by 225.
Bean