Shop OBEX P1 Docs P2 Docs Learn Events
SHIFTIN and Freq issues — Parallax Forums

SHIFTIN and Freq issues

GC4130GC4130 Posts: 13
edited 2005-01-03 13:50 in General Discussion
I am trying to use an ADC0831 A/D converter with the SX. My problem is that when I run the sample code I get varying execution speeds which·are counter intuitive. For FREQ 50_000_000 I get a really long·shiftin cycle. For FREQ 4_000_000 I get a really·short·shiftin cycle. Isn't it suposed to be the other way around????

Any help would be greatly appreciated. thanks

George


'
' Device Settings
'
DEVICE········· SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
'FREQ··········· 50_000_000
FREQ··········· 4_000_000
'
' IO Pins
'
Dpin··········· VAR···· Rc.0··················· ' shift data
Cpin··········· VAR···· Rc.1··················· ' shift clock
CS············· VAR···· Rb.7··················· ' chip select
temp··········· VAR···· Byte
· PROGRAM Start

Get_ADC0831:
· CS = 0······································· ' activate ADC0831
· SHIFTIN Dpin, Cpin, MSBPOST, temp\1·········· ' start conversion
· SHIFTIN Dpin, Cpin, MSBPOST, temp············ ' shift in the data
· CS = 1······································· ' deactivate ADC0831
· RETURN

'
' Program Code
'
Start:
· HIGH CS······································ ' make CS output, no ADC
· LOW Cpin····································· ' make clock 0-1-0
Main:
·low rb.5
· ·GOSUB Get_ADC0831··················· ' move ADC value to LEDs
·high rb.5·
·break
· ·watch temp,8,UDEC
· ·pauseus 10···································· ' wait 0.1 second
GOTO Main

Comments

  • Guenther DaubachGuenther Daubach Posts: 1,321
    edited 2004-12-30 19:03
    George,

    this is only a guess:

    Did you make sure that the SX is clocked with the frequency matching the FREQ directive in the code?

    The FREQ directive only tells the SX/B compiler what clock frequency shall be the base for any delay loops but it does not actually set the frequency itself, unless you are using the SX-Key for debugging. In this case, the SX-Key generates the clock frequency as specified by the FREQ directive in the SX/B code and the resulting Assembly code.

    When you use the SX-internal clock, or an external clock device instead, like a crystal or a resonator, this physical component (or the SX internal clock) determines the frequency, and not the FREQ directive in the program.

    It looks to me that you clock the SX with its internal (not very precise and stable) 4 MHz generaor (because of the OSC4MHZ directive in your sample code). When you activate the FREQ 50_000_000 directive in this case, the SX/B compiler "assumes" that you are running the SX at that speed, and adds more delay cycles for SHIFTIN, which slows down the shift cycle by a factor of .08 when you actually run the SX at 4 MHz.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Greetings from Germany,

    G
  • GC4130GC4130 Posts: 13
    edited 2005-01-03 13:50
    Guenther,

    After I posted I suspected this may be the problem and it was now everything works as anticipated.

    thanks,

    George
Sign In or Register to comment.