From: Jan K. <kro...@ho...> - 2018-11-02 20:09:39
|
Hi, I have taken the TIMER_1 example, and make some small change. Instead of the timer1.tick I toggle pin-7 of the Arduino. With the values as in the listing I measure a frequency of 15,2 Hz with my scoop. When I change some of the preload value by hand no change is seeing. Frequency is staying at 15,2 Hz. When I print the value of TCNT1 after setting, and compare this one after timer1.start there is a difference First value = 63536 and the Second value = 31033. I think some where in amForth TCNT1 is overwritten! Please can you take a look. I included my program. Cheers, Jan \ TIMER1_interrupt marker --timer1_interrupt-- PORTD 7 portpin: PD7 PD7 pin_output &26 constant TIMER1_OVFAddr : togglePD7 PD7 pin_high? if PD7 low else PD7 high then ; : timer1.isr \ toggle output PD7 togglePD7 ; \ preload for overflow interrupt every 1 ms \ preload = 65536 - (f_cpu / (prescaler * 1000)) : timer1.preload f_cpu #1000 um/mod nip 8 / negate \ <===== if i change the value #1000 notting is change ; : timer1.init ( -- ) timer1.preload TCNT1 ! TCNT1 @ u. cr \ <=============== print value of TCNT1 =========== ['] timer1.isr TIMER1_OVFAddr int! ; : timer1.start -int timer1.init %00000010 TCCR1B c! \ prescaler 8 %00000001 TIMSK1 c! \ enable overflow interrupt +int ; : timer1.stop %00000000 TCCR1B c! \ stop timer %00000000 TIMSK1 c! \ stop interrupt ; |
From: Tristan W. <ho...@tj...> - 2018-11-02 21:26:44
|
Jan, > I think some where in amForth TCNT1 is overwritten! Indeed. Every time timer1 overflows. > When I change some of the preload value by hand no change is seeing. > Frequency is staying at 15,2 Hz. Yes. You are seeing a frequency of 16000000 divided by 8 (for the prescaler) divided by 65536 (for each rollover of the timer1) divided by 2 (for the LED toggle) which gives a theoretical 15.3Hz , close to your observed value. Are you looking to generate something for multiplexing a display? There might be an easier way, if that is the case. Best wishes, Tristan On 02Nov18 20:09, Jan Kromhout wrote: > Hi, > > I have taken the TIMER_1 example, and make some small change. > Instead of the timer1.tick I toggle pin-7 of the Arduino. > With the values as in the listing I measure a frequency of 15,2 Hz with my scoop. > > When I change some of the preload value by hand no change is seeing. > Frequency is staying at 15,2 Hz. > > When I print the value of TCNT1 after setting, and compare this one after > timer1.start there is a difference > > First value = 63536 and the Second value = 31033. > > I think some where in amForth TCNT1 is overwritten! > > Please can you take a look. > > I included my program. > > Cheers, > > Jan > > \ TIMER1_interrupt > > marker --timer1_interrupt-- > > PORTD 7 portpin: PD7 > PD7 pin_output > > &26 constant TIMER1_OVFAddr > > : togglePD7 > PD7 pin_high? if PD7 low else PD7 high then > ; > > : timer1.isr > \ toggle output PD7 > togglePD7 > ; > > \ preload for overflow interrupt every 1 ms > \ preload = 65536 - (f_cpu / (prescaler * 1000)) > > : timer1.preload > f_cpu #1000 um/mod nip 8 / negate \ <===== if i change the value #1000 notting is change > ; > > : timer1.init ( -- ) > timer1.preload TCNT1 ! > TCNT1 @ u. cr \ <=============== print value of TCNT1 =========== > ['] timer1.isr TIMER1_OVFAddr int! > ; > > : timer1.start > -int > timer1.init > %00000010 TCCR1B c! \ prescaler 8 > %00000001 TIMSK1 c! \ enable overflow interrupt > +int > ; > > : timer1.stop > %00000000 TCCR1B c! \ stop timer > %00000000 TIMSK1 c! \ stop interrupt > ; > > > > _______________________________________________ > Amforth-devel mailing list for http://amforth.sf.net/ > Amf...@li... > https://lists.sourceforge.net/lists/listinfo/amforth-devel > |
From: Matthias T. <mt...@we...> - 2018-11-03 08:39:32
|
> I think some where in amForth TCNT1 is overwritten! I can assure you, that there is no code in plain amforth that overwrites your settings. It's either your code or the hardware itself. Matthias |
From: Richard B. <ric...@gm...> - 2018-11-03 11:31:33
|
Hi Jan I suggest that the ISR has to toggle the pin and re-load the timer1 counter. >From memory timer1 counts upwards and once it overflows it just keeps counting up from zero unless you re-load it. Regards Richard On 11/3/18, Jan Kromhout <kro...@ho...> wrote: > Hi, > > I have taken the TIMER_1 example, and make some small change. > Instead of the timer1.tick I toggle pin-7 of the Arduino. > With the values as in the listing I measure a frequency of 15,2 Hz with my > scoop. > > When I change some of the preload value by hand no change is seeing. > Frequency is staying at 15,2 Hz. > > When I print the value of TCNT1 after setting, and compare this one after > timer1.start there is a difference > > First value = 63536 and the Second value = 31033. > > I think some where in amForth TCNT1 is overwritten! > > Please can you take a look. > > I included my program. > > Cheers, > > Jan > > \ TIMER1_interrupt > > marker --timer1_interrupt-- > > PORTD 7 portpin: PD7 > PD7 pin_output > > &26 constant TIMER1_OVFAddr > > : togglePD7 > PD7 pin_high? if PD7 low else PD7 high then > ; > > : timer1.isr > \ toggle output PD7 > togglePD7 > ; > > \ preload for overflow interrupt every 1 ms > \ preload = 65536 - (f_cpu / (prescaler * 1000)) > > : timer1.preload > f_cpu #1000 um/mod nip 8 / negate \ <===== if i change the value #1000 > notting is change > ; > > : timer1.init ( -- ) > timer1.preload TCNT1 ! > TCNT1 @ u. cr \ <=============== print value of TCNT1 =========== > ['] timer1.isr TIMER1_OVFAddr int! > ; > > : timer1.start > -int > timer1.init > %00000010 TCCR1B c! \ prescaler 8 > %00000001 TIMSK1 c! \ enable overflow interrupt > +int > ; > > : timer1.stop > %00000000 TCCR1B c! \ stop timer > %00000000 TIMSK1 c! \ stop interrupt > ; > > > > _______________________________________________ > Amforth-devel mailing list for http://amforth.sf.net/ > Amf...@li... > https://lists.sourceforge.net/lists/listinfo/amforth-devel > |
From: Jan K. <kro...@ho...> - 2018-11-03 11:38:52
|
Hi, Thanks all for the suggestions. After reload the timer after every interrupt it is working great. My leaving question is the word “f_cpu” in the code of Timer1.frt. When I execute it I get two values on the stack. What is the meaning of this two values? Cheers, Jan Op 3 nov. 2018, om 12:31 heeft Richard Burden <ric...@gm...<mailto:ric...@gm...>> het volgende geschreven: Hi Jan I suggest that the ISR has to toggle the pin and re-load the timer1 counter. From memory timer1 counts upwards and once it overflows it just keeps counting up from zero unless you re-load it. Regards Richard On 11/3/18, Jan Kromhout <kro...@ho...<mailto:kro...@ho...>> wrote: Hi, I have taken the TIMER_1 example, and make some small change. Instead of the timer1.tick I toggle pin-7 of the Arduino. With the values as in the listing I measure a frequency of 15,2 Hz with my scoop. When I change some of the preload value by hand no change is seeing. Frequency is staying at 15,2 Hz. When I print the value of TCNT1 after setting, and compare this one after timer1.start there is a difference First value = 63536 and the Second value = 31033. I think some where in amForth TCNT1 is overwritten! Please can you take a look. I included my program. Cheers, Jan \ TIMER1_interrupt marker --timer1_interrupt-- PORTD 7 portpin: PD7 PD7 pin_output &26 constant TIMER1_OVFAddr : togglePD7 PD7 pin_high? if PD7 low else PD7 high then ; : timer1.isr \ toggle output PD7 togglePD7 ; \ preload for overflow interrupt every 1 ms \ preload = 65536 - (f_cpu / (prescaler * 1000)) : timer1.preload f_cpu #1000 um/mod nip 8 / negate \ <===== if i change the value #1000 notting is change ; : timer1.init ( -- ) timer1.preload TCNT1 ! TCNT1 @ u. cr \ <=============== print value of TCNT1 =========== ['] timer1.isr TIMER1_OVFAddr int! ; : timer1.start -int timer1.init %00000010 TCCR1B c! \ prescaler 8 %00000001 TIMSK1 c! \ enable overflow interrupt +int ; : timer1.stop %00000000 TCCR1B c! \ stop timer %00000000 TIMSK1 c! \ stop interrupt ; _______________________________________________ Amforth-devel mailing list for http://amforth.sf.net/ Amf...@li...<mailto:Amf...@li...> https://lists.sourceforge.net/lists/listinfo/amforth-devel _______________________________________________ Amforth-devel mailing list for http://amforth.sf.net/ Amf...@li...<mailto:Amf...@li...> https://lists.sourceforge.net/lists/listinfo/amforth-devel |
From: Matthias T. <mt...@we...> - 2018-11-04 14:16:21
|
> My leaving question is the word “f_cpu” in the code of Timer1.frt. > When I execute it I get two values on the stack. It's the current clock the controller is running at. It's a double cell number, since the 16bit controllers run too fast to keep this number in a single cell. Matthias |