Allegro A6280 with PICBASIC
HI there, I'm very new in picbasic and need to have some expert's advise in here. I wish to drive an Allegro A6280 with PIC16F628 by using shiftout. It seems that the data can be sent but the problem is I need to continuously pulse the clock with the code below to keep the A6280's PWM in order to run.
clksend:
high clk
low clk
goto clksend
It seems that when I execute this command, my pic is busy with the code and I can't send the next data to the A6280. Anyone can give me a good suggestion in here as I'm lost in no where right now. Thanks in advise.
shiftout doesn't run as expected
Dear Darrel, sorry for the trouble again, below is the code that I'm trying to work with but it doesn't light up the led as expected. Please kindly advise. Thanks in advance.
@ DEVICE HS_OSC
DEFINE OSC 4
include "bs1defs.bas"
CMCON = 7 ' PortA = digital I/O
VRCON = 0 ' A/D Voltage reference disabled
TRISB = %00000000 ' B.3=PWM,B.0,B.1,B.2 blink LEDs
PR2 = 25 ' Set PWM for approximately 38KHz
CCPR1L = 13 ' Set PWM Duty-Cycle to 50%
CCP1CON = %00001100 ' Mode select = PWM
T2CON = %00000100 ' Timer2 ON + 1:1 prescale
d2pin var portb.0
c2pin var portb.3
latch var portb.4
'oe var portb.1
funct var byte
rvar var word
gvar var word
bvar var word
funct = 0
gvar = %0011111111
rvar = %0000000000
bvar = %0000000000
begin:
high porta.0
pause 1000
low porta.0
CCPR1L = 0
shiftout d2pin, c2pin, 1, [funct\1,gvar\10,rvar\10,bvar\10]
gosub latching
pause 1000
gosub bringpwm
goto begin
bringpwm:
PR2 = 25 ' Set PWM for approximately 38KHz
CCPR1L = 13 ' Set PWM Duty-Cycle to 50%
CCP1CON = %00001100 ' Mode select = PWM
T2CON = %00000100 ' Timer2 ON + 1:1 prescale
return
latching:
high latch
pause 500
low latch
return
how to use TMRIF2 to synch with serial data send
Using SHIFTOUT to send the data may cause blinking when you update the PWM values. You would need to turn off the CCP module to allow SHIFTOUT to control the clock pin, shift the data out, then turn on the CCP module again to keep the clock going.
It's possible that you may not even be able to see it because it will be more of an elongation of 1 PWM cycle, so you should try that way first.
If it is noticable, you'll need to manually shiftout the data "In Sync" with the CCP clock cycles, which can be done with the TMR2IF flag. But try it with SHIFTOUT first to see if there's a problem or not. If there is, I can show you how to "sync" the data.
HTH,[/QUOTE]
Dear All, especially to DT,
My brother had tried out the shiftout part of the codes, it worked perfectly. But to my calculation, that will be way to slow for our requirement, pausing to wait for the shiftout to complete will take impractically long in our project.
You mentioned of using TMR2IF flag. Both me and my bro are new. I tried playing with the TMR2 to synch the data send: ie using the PWM as clock drive. But seems like my understanding of the TMR2 is wrong. Please correct:
1. TMR2 counts from 00 to value in PR2 then resets.
2. If TMR2 count reaches value in CCPR1L, then duty cycle is completed, hence going to the low cycle of the PWM and therefore our "clock"
So my aim is to send the data on the duty cycle time via the data pin and prepare for the next data bit in the low time. I set the PR2 = 9 and CCPR1L =5 as in your earlier code with the above assumption. Thinking the Low time will be after TMR2 = 5, so I wrote:
For Counter = 1 to 31
while TMR2 <= 5 then
high DataPin
wend
low DataPin
next Counter
Will this work?
Didn't use TMRIF2 as I am still struggling to understand the interrupts.
Can you show how to synch CCP with the TMRIF2 as you have mentioned?
Thanks a lot.
Heng.