B4R Question Faster Timer1_Tick

ChocoScope

Member
Licensed User
Longtime User
Is it possible to change the timer prescaler to give a faster Tick? (Arduino UNO/Nano(328)) Or is there a better way to generate regular fast interrupts?

My attempt to change the Timer Control register with RunNative. Didn't work

B4X:
Private Sub AppStart
    Serial1.Initialize(9600)
    Timer1.Initialize("Timer1_Tick", 500)
    Timer1.Enabled = True 'don't forget to enable it
    RunNative("SetT1PS",Null)                            'attempt to change the timer prescaler
    #If C
    void SetT1PS(B4R::Object* o) {
    ULong *TCCR1B = _SFR_MEM8(0x81)                    //address of timer/counter 1B control register
    TCCR1B = 1;
    }
    #End if
End Sub

The program compiled ok and was downloaded to the UNO but it made no difference whether the RunNative code was present or not.
 

ChocoScope

Member
Licensed User
Longtime User
I have now successfully written three Loopers, which step three stepper motors at three different speeds. It was impressive but slightly unpredictable due to the random nature of its structure. Please can we return to my original question, which was how to temporarily disable the prescaler associated with Timer and then restore it back to its correct value on completion. Nothing else needs to be altered and if the original prescaler was div64 then I can adjust the value I put in Timer1 to suit. Can you tell me what I did wrong with the RunNative code which I presented at the top of this thread and possibly provide a couple of snippets of code to alter and restore the prescaler. Thank's in advance.
 
Upvote 0
Top