r. How to set the PWM prescaler value and drive a stepper motor...
QUESTION:
The PWM frequency is calculated as 1 / ((PMR2 + 1) * Tosc * [TMR2 Prescale]). At Fosc = 48 Mhz, PMW2 = 255 and prescale 1:1, that is a "minimum" of 46.875 KHz. Can I set a different prescaler?
ANSWER:
Prescaler can be easily set to 1:16 (the other two ratios are: 1:1 and 1:4) from VB.NET with the following functions:
DataMemRead(addr as UInt16) as Integer
DataMemWrite(addr as UInt 16, data as Byte) as Integer
Let me show you an example: "pic.DataMemWrite(&HF81,&HAA)" ... this will write directly to PORT B of a PIC18F... Every second LED will light up on your K8055 experiment board... There are many examples with source code that use this functionality on my website....
To set TIMER2 prescaler to 1:16 just use the following commands in VB.NET:
Dim PIC As SVLib_PIC18F24J50.SVPICAPI = New SVLib_PIC18F24J50.SVPICAPI ' initialization of PIC object
Dim x as Integer
...
x=PIC.DataMemRead(&HFCA)
if x>=0 then
x=x or 3
PIC.DataMemWrite(&HFCA,x)
Else
.... error reading register memory ....
End If
You can do anything that your PIC18F HW can do... Read more here: PIC18F26J50 32-bit low frequency PWM generator
If this is not enough, simply use a much more advanced PIC32MX250F128B microcontroller with 32-bit PWM resolution ... All the HW and VB.NET support is also available from PC USB Projects website...
ALSO READ: The original Microchip document: DS39931D (PIC18F46J50 Data Sheet that also applies to PIC18F2xJ50 microcontrollers)... See pages 211, 212, 251, 253+ ... It is clear that PWM frequences in range of a few kHz may be easily obtained. Available enhanced PWM configurations are described on page 253 of the data sheet.